John Cooper
John Cooper

Reputation: 7631

Object relationship and class relationship?

Can anyone explain me the difference between them? A Lake, A Fish, A Plant and A Frog. What is the Object relationship between them?

Upvotes: 0

Views: 1353

Answers (3)

Steve's a D
Steve's a D

Reputation: 3821

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

Upvotes: 2

Bajji
Bajji

Reputation: 2383

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

Upvotes: 3

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.

Upvotes: 3

Related Questions