composition - Store a reference to component class in compositional relationship -
i'm looking @ composition. mean 'store reference component'?
to me means there 2 classes, , 1 class instantiated within other class. correct? how else represent compositional relationship?
how particular example different aggregation? (or require object storing reference instantiated classes created out of it's scope..)
i.e. (ruby syntax)
class def initialize #stuff end end class b def initialize @many_a_instances = [] end def attach_an_a @many_a_instances << a.new end end
would better define class within class b?
in light of thunderous enthusiasm question answerers... answer (based on conversation colleagues , friends):
how define classes independent of relationship between instances of different classes (which dependent on how classes instantiated).
if instance defines reference instance, referenced instance's lifespan dependant on object holds reference. defines compositional relationship.
however, if instantiated object , passed reference object class, example of aggregation. because lifespan of 2 instantiated objects independent each other, 1 object still references other.
so same classes, different relationships between instances. , in terms of classes defined, use-case specific.
any better answer marked accepted on 1 :)
Comments
Post a Comment