Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7185377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:24:07+00:00 2026-05-28T18:24:07+00:00

I am finishing a course on design patterns, and while reviewing the notes came

  • 0

I am finishing a course on design patterns, and while reviewing the notes came across something I missed during the semester: Composite vs. Composition. What I managed to understand is that composite is when an object actually encapsulates whole objects, while composition is when it only holds pointers to them.

  1. Is this right? Can someone explain this to me a little better?
  2. When would I prefer one over the other?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T18:24:08+00:00Added an answer on May 28, 2026 at 6:24 pm

    Composition

    This is a design concept (not really a pattern). This term is used when you want to describe one object containing another one. It occurs very often in Composition over inheritance discussion.

    Moreover, composition implies strong ownership. One objects owns (i.e. manages the lifecycle) of another object. When parent is destroyed, all children are destroyed as well. If there is no such strong relationship (children can outlive parent) we are talking about aggregation.

    Quoting great example in Wikipedia:

    For example, a university owns various departments (e.g., chemistry), and each department has a number of professors. If the university closes, the departments will no longer exist, but the professors in those departments will continue to exist. Therefore, a University can be seen as a composition of departments, whereas departments have an aggregation of professors. In addition, a Professor could work in more than one department, but a department could not be part of more than one university.

    So as you can see you should choose between composition or aggregation depending on the type of ownership relationship.

    Composite pattern

    This is a GoF design pattern describing a parent-child strong relationship where the child can be a simple node or a container of other nodes (possibly containing other children).

    It is very common in GUI and tree like structure. E.g. in Java Swing a JPanel can hold various controls like text fields, labels, lists, etc. but it can also hold other JPanels which, in turn, can contain simple components and even more nested panels.

    Typically Composite design pattern uses composition, however in some cases the parent does not have to own all children. To continue GUI example, you can take one panel and move it to another place (change the parent).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm just finishing up a computer architecture course this semester where, among other things,
I am just finishing up an Artificial Intelligence course where, as part of the
I'm finishing up a project I've been working on for a while, and am
I'm finishing up my first app on the Palm Pre for a client. During
I will be finishing the core Java course and now I have to move
Well, after finishing an advanced C programming course i decided to take a look
I'm finishing up my first site: http://www.audio-agent.com/ . I just noticed that, while it
I'm just finishing off coding a a document storage solution and I've run across
I'm finishing up a midterm project for an HTMl course and I'm working on
While finishing a project at My Map , I discovered that the API, V2,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.