"RSH" <wa*************@yahoo.com> a écrit dans le message de news:
uo**************@TK2MSFTNGP12.phx.gbl...
| I do have one question regarding this part of the code:
| public List<OrderLine>.Enumerator Lines
| {
| get { return lines.GetEnumerator(); }
| }
|
| What does this do? What is it called? and how do I use it?
This is a method that returns an iterator or enumerator that allows you to
traverse the collection without having access to the whole list
functionality like Add, Remove, etc; all of which should not be allowed as
the list is meant to be managed by the Order of which it is a part.
You could also use ReadOnlyCollection<T> to allow inspection, of the items
in a list without allowing modification of the list itself.
public ReadOnlyCollection<OrderLine> Lines
| {
| get { return new ReadOnlyCollection(lines); }
| }
There are two different type of aggregation: Aggregation itself and
Composition.
Aggregation typifies an object holding a list of related objects, but those
contained objects have a life of their own outside of the containing object.
e.g. a Company may have a list of Employees who are of the type Person in
the role of Employee; if the Company closes, the Employee list might be
destroyed but the Persons still exist and can be used again in another
context.
Composition typifies an object holding a list of objects whose lifetimes are
governed by the containing object. In the example of the Sales Order, Order
Lines have no context outside of the Order of which they are a part. Without
the Order, the Lines have no raison d'être, therefore thay are destroyed
when the Order is destroyed. Classes like ReadOnlyCollection allow us to see
the list, even to modify an individual item, but without being able to
modify the list itself.
Joanna
--
Joanna Carter [TeamB]
Consultant Software Engineer