i try to understand the difference between Composition and Inheritance in swift but i can't find a simple and easy answer that can help me to understand the difference between them and how i can choose which one to use
Asked
Active
Viewed 999 times
0
-
https://www.thoughtworks.com/insights/blog/composition-vs-inheritance-how-choose – Milan Nosáľ Jan 21 '18 at 21:48
-
3Composition is `"has a"` or `"contains a"` relationship.. whereas inheritance is `"is a"` or `"is a type of"` relationship.. Example: A Gorilla has 2 Legs (composition - Gorilla class would have 2 instance of Leg class).. However.. A Gorilla is an Animal (inheritance).. Thus Gorilla would inherit all the properties and traits of an animal. This is not specific to swift. It's for all Object-Oriented languages. – Brandon Jan 21 '18 at 21:54
-
Please see the duplicate question. It may not seem as a duplicate at first. But its answes surely provide enough to ponder – mfaani Jan 21 '18 at 21:56
-
Honey thank you i found my answer there – Hazem Mohamed Jan 21 '18 at 22:02
-
@HazemMohamed Brandon's comment is also very valuable The **Has-a** and **Is-a** are very easy to understand rules. For more see [here](https://en.wikipedia.org/wiki/Has-a) – mfaani Jan 22 '18 at 16:20