S
SenthilVel
Hi
Can any one let me know the websites/Pdf for learning Aggragation in C#??
Thanks
Senthil
Can any one let me know the websites/Pdf for learning Aggragation in C#??
Thanks
Senthil
Kevin Spencer said:The word "aggregation" simply means "group." So, you'll have to be more
specific about what sort of aggregation you're asking about.
dot.state.fl.us> said:I do remember from my OOP classes in the univ that there was a clear
distinction between aggregation and composition, Aggregation is when a type
has a member variable of another type, but only store a reference. In such a
way that the inner instance can exist independently of the external, or
wrapper type. The destruction of the external one does not imply the
destruction of the internal.
In Composition the internal instance is created when the external one is
created and is destroyed at the same time.
C++ does implement both concepts very clearly.
In C# when you are using classes you have the aggregation by default.
The problem is when you want to use composition, in C# there is no way of
using composition with classes.
If you use a struct (value type) you do have composition as in C++.
Any comments are welcome, a few months ago somebody asked me that very same
question, how to implement aggregation and composition in C# and my
explanation was not very clear.
If the "embedded" object is no longer accessible after the enclosing
instance is no longer accessible, then even if it hasn't actually been
garbage collected, it's been destroyed as far as anything else is
concerned. There's no longer any way to get at the data in it.
dot.state.fl.us> said:I think that you cannot assure a composition unless that the
enclosing(wrapper) type only expose value types from the composed type, as
soon as you expose it as reference you lose the composition as the calling
code can keep a reference to the member even after the wrapper is disposed.
Jon Skeet said:<"Ignacio Machin \( .NET/ C# MVP \)" <ignacio.machin AT
Yes - so if you're composing including a List, you don't expose the
list itself, but you might have methods which effectively indexed the
list.
I'm not sure that it wouldn't count as composition if you exposed
immutable reference types (eg string) too though.
Only if you expose the list as an indexer, if you just expose it as a
public property the calling code can keep a reference after the wrapper
instance is disposed.
Good question, I don't think that the OOP cover this case. At least I do not
remember being given this example in class.
Right.
My interpretation is that if you have something like
class C{
public string theStrig = "This is a string";
}
we can say that the member is assigned when the instance is created ( as in
composition ) but you can keep a reference to it after the wrapper is
disposed:
string s;
C c = new C;
s = c.theString;
c = null;
//I can keep using s as long as I keep a reference to it.
Jon Skeet said:<"Ignacio Machin \( .NET/ C# MVP \)" <ignacio.machin AT
I don't see how that would count as not exposing the list itself![]()
Indeed - but it doesn't affect the object. To me, the difference
between aggregation and composition is in terms of how clients can
affect the object. I'm not an expert though![]()
Jon Skeet said:If the "embedded" object is no longer accessible after the enclosing
instance is no longer accessible, then even if it hasn't actually been
garbage collected, it's been destroyed as far as anything else is
concerned. There's no longer any way to get at the data in it.
Alan Pretre said:I think it is a matter of ownership, simply. If the "enclosing" object, so
to speak, owns the reference*, it is responsible for the lifetime of it. If
not, it is simply using it and the lifetime of the referenced object is
independent of the container. Would you agree?
Ref.: GoF p.22
*Note: Ownership can be transferred to another container, but there can only
be at most 1 owner.
Jon Skeet said:It depends exactly what is meant by ownership. Responsibility for
lifetime? Responsibility for data?
I guess the question I'd like to ask is what *useful* distinction can
be made between the two in C#.
Is there some way of interpreting the
patterns so that in some cases we could describe the usage as
aggregation and in some we could call it composition?
Or do we need to
invent a new term for when we expose immutable data?
Jon Skeet said:Is there some way of interpreting the
patterns so that in some cases we could describe the usage as
aggregation and in some we could call it composition?
Joanna Carter said:"Alan Pretre" <no@spam> a écrit dans le message de (e-mail address removed)...
No, I am sorry, but you are totally wrong, Composition implies ownership,
aggregation implies non- ownership.
Joanna Carter said:Object Composition here is talking about the composition of an object;
IOW,
a class is made up from references to different types, not the Composite
relationship, this is a subtle difference in the English language that can
be mistaken by a non-native speaker.
So to be simple one could avoid the terms Aggregation and Composition
and stick to the terms Containment by Reference and Contaiment by Ownership.
However, the distinction between these terms is less clear in a garbage
collected environment.