Milad Khajavi
Milad Khajavi

Reputation: 2859

What is the Whole-part and Part-whole object relationship?

I'm reading Head First Design Patterns book, on page 382 it says:

Composite Patterns is used when you have collection of objects with Whole-Part relationships. and you want to be able to treat those objects uniformly.

Upvotes: 12

Views: 8678

Answers (3)

Anil Burak Bilsel
Anil Burak Bilsel

Reputation: 11

Part-whole is also related to Composite Pattern. Composite pattern provides a mechanism for treating groups of objects the same as an individual object (this is often known as part-whole hierarchy).

Upvotes: 0

jilt3d
jilt3d

Reputation: 4034

Basically, the term represents the construction of larger objects based on smaller ones. In the context of Composite Pattern both large and small objects are instances of same class.

Upvotes: 3

SomeWittyUsername
SomeWittyUsername

Reputation: 18368

Well, it's pretty straightforward - any object in a collection is a part of the whole composition and composition as a whole is a collection of parts.

Upvotes: 18

Related Questions