Composite design pattern = polymorphism?
-
I’m studying computer programming, and I’m a little puzzled by the Composite design pattern. In "Design Patterns in C#" by Steven John Metsker, Addison-Wesley, it says: COMPOSITE lets clients treat individual objects and compositions of objects uniformly. And in "Programming C#", O'Reilly, it says about polymorphism: Thus, polymorphism refers to being able to use many forms of a type without regards to the details. Is this not one and the same thing?
Programming is like Mathematics… you take ONE step at the time! ;-)
-
I’m studying computer programming, and I’m a little puzzled by the Composite design pattern. In "Design Patterns in C#" by Steven John Metsker, Addison-Wesley, it says: COMPOSITE lets clients treat individual objects and compositions of objects uniformly. And in "Programming C#", O'Reilly, it says about polymorphism: Thus, polymorphism refers to being able to use many forms of a type without regards to the details. Is this not one and the same thing?
Programming is like Mathematics… you take ONE step at the time! ;-)
Polymorphism is one pillar of the OOP paradigm. Composite is a design pattern, i.e. a very good solution to a well known problem. I think you have to learn more about both OOP and design pattern techniques. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
-
I’m studying computer programming, and I’m a little puzzled by the Composite design pattern. In "Design Patterns in C#" by Steven John Metsker, Addison-Wesley, it says: COMPOSITE lets clients treat individual objects and compositions of objects uniformly. And in "Programming C#", O'Reilly, it says about polymorphism: Thus, polymorphism refers to being able to use many forms of a type without regards to the details. Is this not one and the same thing?
Programming is like Mathematics… you take ONE step at the time! ;-)
Polymorphism: being able to treat a car as an vehicle - using a base class reference to call virtual methods. Composite: making a car of individual parts (motor etc.) and being able to treat both the motor and the whole car the same, e.g. calling Repair() on them. The Composite pattern uses polymorphism (as most design patterns do), but it isn't the same thing.