The demo you give for what you call the "Composite Pattern" is, interestingly enough, a demo that explains perfectly why we would use the "Factory Pattern" = to be able to return different Class types depending on the initial creation values (something we cannot do with the traditional CONSTRUCTOR Method)......................
I wouldn't say that you would prefer one over the other. In fact I don't see the comparison. Inheritance is a fundamental of OO and Composition is a pattern. In fact in order to make Composition pattern work you must use Inheritance. [Thomas Jung]
@@sapdevs I think both are confusing the Composite pattern with composition, which is done via interfaces. Mateusz shared the best resource in ABAP for the composition vs inheritance discussion, which basically boils down to inheritance being difficult to design properly and makes logic hard to reuse outside of sub-classes.
You showed an example of the Strategy pattern. The Composite pattern is a structural pattern. The purpose of Composite pattern is to compose a tree of related objects with parent and children relations. The base class of composite objects usually holds one parent object with the base class type and many child objects with the base class type.
I am not too familiar with oops concepts but I have learned that abstract should atleast have one abstract method and these are no implementations of abstract methods in a abstract class, but in last example base abstract class was having only factory method which is not abstract method and also there is implementations of it in the same class
Not necessarily, abstract classes can contain abstract methods, which must be redefined in the inheriting classes. You can create abstract classes without any abstract methods. You might be confusing it with interfaces.
It's really very easy to understand! Thank you for your explanation!
The demo you give for what you call the "Composite Pattern" is, interestingly enough, a demo that explains perfectly why we would use the "Factory Pattern" = to be able to return different Class types depending on the initial creation values (something we cannot do with the traditional CONSTRUCTOR Method)......................
Very well explained as always.
Great video, thanks!
Can you please explain why to prefer composition over inheritance?
I wouldn't say that you would prefer one over the other. In fact I don't see the comparison. Inheritance is a fundamental of OO and Composition is a pattern. In fact in order to make Composition pattern work you must use Inheritance. [Thomas Jung]
@@sapdevs I think both are confusing the Composite pattern with composition, which is done via interfaces. Mateusz shared the best resource in ABAP for the composition vs inheritance discussion, which basically boils down to inheritance being difficult to design properly and makes logic hard to reuse outside of sub-classes.
@@baca0391
So basically Interfaces >>> Inheritance
You showed an example of the Strategy pattern. The Composite pattern is a structural pattern. The purpose of Composite pattern is to compose a tree of related objects with parent and children relations. The base class of composite objects usually holds one parent object with the base class type and many child objects with the base class type.
Tks for the explanation! Great video
I am not too familiar with oops concepts but I have learned that abstract should atleast have one abstract method and these are no implementations of abstract methods in a abstract class, but in last example base abstract class was having only factory method which is not abstract method and also there is implementations of it in the same class
Yes he is clearly a newbie in OO.
Not necessarily, abstract classes can contain abstract methods, which must be redefined in the inheriting classes. You can create abstract classes without any abstract methods. You might be confusing it with interfaces.