Re: Articles or Turorials on Aggregation??

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Alan Pretre <no@spam> wrote:
> "Jon Skeet [C# MVP]" <skeet@xxxxxxxxx> wrote in message
> news:MPG.1e2f6e57bc3a8cac98ccb3@xxxxxxxxxxxxxxxxxxxxxxx
> > 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.
>
> 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.

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?

Suppose instead of exposing an actual string, we exposed the length as
one property, and allowed indexing of the string. A client could easily
reconstruct the string - they would be functionally equivalent,
wouldn't they? Would one be composition and the other aggregation?

--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
.



Relevant Pages

  • Re: Articles or Turorials on Aggregation??
    ... > It depends exactly what is meant by ownership. ... Responsibility for data? ... simply responsibility for lifetime. ... Though if immutability is a requirement then obviously the way the enclosed ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Structured programs (long)
    ... > If you want to say that String and Date are not objects, ... Unfortunately the knowledge responsibility issue is critical here (along ... the only entity that has to access the first character of each string. ... dependency management during OOP, though. ...
    (comp.object)
  • RE: Sections in repeater
    ... Public Class Responsibility ... Public Property PersonAs String ... Public Sub New(ByVal activityStart As DateTime, ByVal person As String, ... Dim litSection As Literal ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)
  • Re: Aggregation vs composition
    ... >>lifetime of the B instances it holds. ... It shairs that responsibility. ... I would expect that any Python programmer looking at the above snippit ... I thought UML was supposed to be language ...
    (comp.object)
  • Re: Operand
    ... It was indeed very nice of you to give me an explanation on datatypes. ... assigned a numeric string to a string, you could treat it just like a ... You have to take more responsibility for ... Sub btnInv ...
    (microsoft.public.dotnet.framework.aspnet)