As far as I know, composition is a "owns-a" or "is-part-of" relation, while aggregation is "has-a" instead.
@dhanushs18022 жыл бұрын
Very neatly explained as always. Thank you.
@MikeShah2 жыл бұрын
Cheers, thank you Dhanush!
@evgeniystakhovskiy59782 жыл бұрын
Mike, question not specifically related to the topic of the lesson, rather on how you draw the parent-child relationship. In the first example with inheritance, you've got encircled Character and Point2D, with the arrow pointing towards the parent Point2D. I'm confused why the arrow is pointing this way, for me it looks more logical to point to Character being a child? To my mind, the characteristics of parent are being transferred to the child, not vice versa. What am I missing here? Great job with the series!
@MikeShah2 жыл бұрын
In most of the literature that I have seen, the arrow points up from child to parent in regards to inheritance (because you want to know who you inherit from). This is opposite to how we usually draw when first learning about trees for example which is probably the confusion :) Hopefully I did not reverse this in any of the lessons, but again, arrow should point up from child towards parent :)
@維仁陳-c2k9 ай бұрын
Hey Mike, thanks for the awesome tutorial! At 6:33, I found that it says that an aggregation can be an array or a class that has no user-declared or inherited constructors (since C++20) ... on cppreference. Is the example at 6:33 still considered to be an aggregation or is this concept still applicable to aggregations? Thanks in advance! The keyword I use in cppreference: Aggregate initialization (It seems like my comment would be deleted by KZbin if I paste the link)
@MikeShah9 ай бұрын
I think 'aggregate initialization' is more in reference to creating a new object through a mechanism like a list_initializer, versus the general idea of composition (which is about 'holding multiple components/fields/value' -- thus 'aggregating' or collecting one or more different or the same types together). I'll need to think about it a little more, but that's my initial understanding.
@im_another_you7 ай бұрын
Composition over inheritance please make a session for this. 😊
@MikeShah7 ай бұрын
Indeed, composition is in favor these days :)
@blaisofotso34392 жыл бұрын
Great video and topic too. But could not differentiate between the lifetime of composition against aggregation. Would be appreciated if you could do a pictorial explanation to iron out the lifetime concept. We did aggregation in class using pointer . Why is it called aggregation?
@MikeShah2 жыл бұрын
Aggregation is named because we're are 'collecting' or 'making up' a new data type consisting of other types. I agree, a picture may be useful to think about lifetimes. @4:30 I explain a little bit about the subtle difference between composition and aggregation. Composition think about as just having everything being destroyed (on a timeline) with the actual instance of that object. Aggregation could allow other objects to live further on a timeline (e.g. some data being pointed to)
@reptilicusrex47482 жыл бұрын
As usual, another great explanation.
@MikeShah2 жыл бұрын
Cheers!
@damondouglas2 жыл бұрын
This video reminded me of kzbin.info/www/bejne/o6DXfYKfpLF9nMk use of composition to delegate methods to references of other class implementations. Your series is my personal prerequisite to reading Klaus's recent book. Thank you so much for this.
@MikeShah2 жыл бұрын
Cheers! Klaus gives wonderful talks, and his new book is wonderful -- definitely recommend!