Classes part 23 - Composition (and aggregation) versus Inheritance in C++ | Modern Cpp Series Ep. 60

  Рет қаралды 8,416

Mike Shah

Mike Shah

Күн бұрын

Пікірлер: 17
@GaryChike
@GaryChike 2 жыл бұрын
Man, you are on a roll Mike!
@MikeShah
@MikeShah 2 жыл бұрын
Thank you for the support! :)
@codygao8323
@codygao8323 4 ай бұрын
As far as I know, composition is a "owns-a" or "is-part-of" relation, while aggregation is "has-a" instead.
@dhanushs1802
@dhanushs1802 2 жыл бұрын
Very neatly explained as always. Thank you.
@MikeShah
@MikeShah 2 жыл бұрын
Cheers, thank you Dhanush!
@evgeniystakhovskiy5978
@evgeniystakhovskiy5978 2 жыл бұрын
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!
@MikeShah
@MikeShah 2 жыл бұрын
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 :)
@維仁陳-c2k
@維仁陳-c2k 9 ай бұрын
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)
@MikeShah
@MikeShah 9 ай бұрын
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_you
@im_another_you 7 ай бұрын
Composition over inheritance please make a session for this. 😊
@MikeShah
@MikeShah 7 ай бұрын
Indeed, composition is in favor these days :)
@blaisofotso3439
@blaisofotso3439 2 жыл бұрын
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?
@MikeShah
@MikeShah 2 жыл бұрын
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)
@reptilicusrex4748
@reptilicusrex4748 2 жыл бұрын
As usual, another great explanation.
@MikeShah
@MikeShah 2 жыл бұрын
Cheers!
@damondouglas
@damondouglas 2 жыл бұрын
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.
@MikeShah
@MikeShah 2 жыл бұрын
Cheers! Klaus gives wonderful talks, and his new book is wonderful -- definitely recommend!
Only Use Inheritance If You Want Both of These
9:10
Christopher Okhravi
Рет қаралды 22 М.
Wednesday VS Enid: Who is The Best Mommy? #shorts
0:14
Troom Oki Toki
Рет қаралды 50 МЛН
"Идеальное" преступление
0:39
Кик Брейнс
Рет қаралды 1,4 МЛН
The Flaws of Inheritance
10:01
CodeAesthetic
Рет қаралды 1 МЛН
you will never ask about pointers again after watching this video
8:03
C++ OOP - What is inheritance in programming?
16:32
CodeBeauty
Рет қаралды 155 М.
Inheritance in C++
8:00
The Cherno
Рет қаралды 407 М.
Why Favor Object Composition Over Class Inheritance? A Deep Dive
19:00
Composition over Inheritance Explained by Games! #programming
8:10
Metaphorically Speaking
Рет қаралды 19 М.