开发者

Object relationship and class relationship?

Can anyone explain me the difference bet开发者_运维知识库ween them? A Lake, A Fish, A Plant and A Frog. What is the Object relationship between them?


Adding to awoodland's answer, a Lake object will contain fish, plant and frog objects. Please see aggregation for a better explanation.


In your example a lake is a habitat, whilst fish, plant and frog are all examples of life forms that would live in a specific lake.


HAS-A and IS-A are terms used to describe object relationships. A lake HAS-A: fish, plant, and a frog. This means that your lake class contains references to a: fish, frog, and plant object. A IS-A relationship is like...a trout IS-A fish, so you extend a fish class to make a trout class.

EDIT: a frog and a fish COULD extend an animal class (since they're both animals). This is another example of an IS-A relationship

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜