开发者

Do I have the correct understanding of composition

开发者 https://www.devze.com 2023-03-05 23:50 出处:网络
From what I read composition is when one object depends on another to exist. For example a tail cannot exist with out a dog.Also, would it 开发者_运维知识库still be considered composition if I had a t

From what I read composition is when one object depends on another to exist. For example a tail cannot exist with out a dog. Also, would it 开发者_运维知识库still be considered composition if I had a tail class that was used by both a class dog and a class cat?


Yes, composition is when a large thing (think whale) eats a smaller thing (think of a poor fish of some kind).

Your cat class contains a tail just like your dog contains a tail class. Both are examples of composition.

0

精彩评论

暂无评论...
验证码 换一张
取 消