Use problems of the ilist type (Collection)

Source: Internet
Author: User
For example, in category. CS,
// Get all pet types
Public ilist <categoryinfo> getcategories ()
// Obtain a single pet type by ID
Public categoryinfo getcategory (string categoryid)
The first method returns the set of entity categoryinfo. Why does it use ilist <categoryinfo> instead of list <categoryinfo>?
Reply:Ristona (one arrow)() Credit: 98 2007-3-9 21:40:26 Score: 0
?
This is to develop reusable code, called the Dependency inversion principle.
Top
Reply:Syeerzy (happy always * Happy first * happy after the world * worries and worries *)() Reputation: 95 2007-3-9 22:54:45 Score: 0
?
API-oriented programming.

If. in net 3.0, 4.0, 5.0, list may have some changes, but ilist is unlikely to change (because it is only an interface, and the implementation is not here, changing an interface is of little significance, even if this interface is unreasonable, it will not be changed when a new interface is added. This is just a simple example.

Returning an ilist gives more flexibility. This is more important.

Top
Reply:Sp1234 (encountering adware. cpush rogue)() Credit: 98 2007-3-9 22:57:06 Score: 0
?
Basically, the functions of the ilist <t> and list <t> types are identical.

. Net does not support multiple inheritance. You can use ilist <t> to adapt to more types, including those not inherited from list <t>.

However, it is very painful to use interface programming. Therefore, when a common person returns a set of this type, it inherits from the list <t> instead of allowing the custom set to only implement ilist <t>. Fortunately, the list <t> is also an ilist <t>, so using ilist <t> can completely hide this messy choice.

In combination, ilist <t> is difficult to use, but flexible.

Top
Reply:Ivony)() Credit: 100 2007-3-11 6:49:59 Score: 0
?
I think it is the minimum usage principle. If the receiver does not need a specific container, but only needs something that can be used as a container, a specific container is not returned at this time.

In terms of semantics, ilist emphasizes that I return a container and list emphasizes that I return a specific container.

Interface-oriented programming cannot be difficult, or else it will be very painful.

Finally, the arraylist and rule list all implement the ilist interface.
You can declare a variable of the ilist type to point it to the arraylist or sorted list.
Ilist list = new arraylist ();
Ilist list = new partition list ();

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.