Skip to content

Wrong Composite Pattern Definition #28

Open
@ozen

Description

@ozen

First of all, thanks to the contributors for their work, there are really good simple explanations. But, the definition of Composite Pattern is completely wrong. What is explained is simply a usage of inheritance. The motivation for using composite pattern is not to treat group of objects in the same way; but treat (1) group of objects with (2) a single object in the same way.

Keeping up with the Employee example; assume there is an Employee class; and a Team class that consists of a group of Employees and other Teams. You define a super type for Employee and Team, let's call it Workforce, and make Team consist of Workforce. This is well explained in Wikipedia article [1]. Matching the terminology with it, Employee is Leaf, Team is Composite, and Workforce is Component. Here Team is the client that make use of the Component.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions