Advanced C++: Code Reuse - Inheritance vs Composition

preview_player
Показать описание
There are two ways to reuse code in C++: inheritance and composition. Which one should I use?

Рекомендации по теме
Комментарии
Автор

"Friends and children, biggest enemy of your privacy. It's a philosophy of life." lol

kochcj
Автор

Thanks for your feedback. I'll keep your list.

BoQianTheProgrammer
Автор

Thank you for this. I struggle a lot with programming and this was very easy for me to understand. You're a good teacher.

kayleenees
Автор

That's good theory. On practice using ActivityManager is justified only on multiple binding. In case of 1:1 which is 90% of cases it makes more complexity, which is: a) worse readability and understanding code; b) more efforts to support code and more opportunities to bugs; c) extra indirection takes memory and CPU time. The guidelines are usable for very huge and complex software, which is exclusive case.

ldxyz-se
Автор

Friends and children break the encapsulation of your life. ohhh

zaiyi
Автор

I only wish you were my teacher in my high school days, Thanks a ton! .. You just got a new fan :)

Shall be glad if you consider few requests in your next topics lists :

1. S.O.L.I.D Design principles explained with examples
2. Code Review ticks and tips for e.g prefer vec.empty() over vec.size() > 0 for empty check.
3. Multiple reader and Single writer solution with old win32 approach vs stl (shared_mutex, unique_lock) and benefiits
4.Memory leaks smart ptr & profiling

Many Thanks again :)

threelittlefoxproductions
Автор

Very useful video. I was wondering about this for quite some time.

CodingJesus
Автор

Thank you for such a good explanation on the basic!

anushamanila
Автор

Best material on this topic so far, thanks Bo!

rjmunt
Автор

This is best best 👍💯 explaination
Thanks bo qian

pawarlg
Автор

Not quite the idea in modern languages, which nicely separate interfaces from impls. E.g., in Java, Dog is an interface, and the stuff you put in ActivityManager is done in AbstractDog, which is almost always an internal class. All derived classes will derive from AbstractDog so long as it provides the base impl that they need. In terms of composition, it's about responsibilities: a Dog should specify only behaviors it's responsible for. Other behaviors should be composed. In your example, common Dog behavior should still be in Dog. Just like your example on tree pre-order traversal.

thachnnguyen
Автор

Sir Video is great
But I am confused whether its aggregation over inheritance or composition over inheritance?

if we include virtual function??

if we use composition then dynamic binding not possible

So i am confused with this video :(

pawarlg
Автор

Composition rocks, most languages should have traits/mixins (hopefully like the ones in perl6 :) )...

shinobicl
Автор

I am glad you like it. If there is any particular area you have trouble with, feel free to let me know and I'll see if I can help.

BoQianTheProgrammer
Автор

This is a good video, but I would really tone down on the statement that composition is better than inheritance. Both techniques have their uses and places.

claudioviotti
Автор

"Friends and children, biggest enemy of your privacy, it's a philosophy of life." Hahaha

baronvonmike
Автор

I love your videos, teach me a lot. But I have a question and I'll appreciate if you give answer. You say that Inheritance breaks encapsulation because Derived Classes can access Protected members, But aren't protected members declared protected for this ?. Maybe you mean when I Inherit from someone else's Library class, then I can break encapsulation accessing his protected members... Oh

rafaelmoura
Автор

Hey im trying to create or recreate 3d animation software. Do i use someone elses software code & create it on a new platform?

goo
Автор

I think there is too much talk about naming and too much reading of what I can read by myself. It would have been great to explain the concept, the benefits and to give some examples.

martinsand
Автор

pretty good. I learn't something here.. thanks

Kareem-cxfi