开发者

Do I have the correct understanding of composition

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜