Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

oop - Association vs. Aggregation vs. Composition in Java

I'm trying to understand what these terms mean. And I came with few examples like:

Aggregation : Facebook has a user

Composition : Each user in facebook has a session.

Association : People uses a browser

But I'm getting confused with has a and uses a examples of mine. Why can't it be User uses a facebook account or Facebook uses a session to authenticate user?

Is that wrong in terms of OOP? Where I'm missing the concept?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The uses a relationship means two things

->both can exist independently

->Data flows from the whole classifier(people) to the part classifier(browser)

The has a relationship means two things

->the lifetime of the part classifier(session) is dependent on the lifetime of the whole classifier(facebook)

->data usually flows in only one direction (that is, from the whole classifier(facebook) to the part classifier(session)).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...