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

  • Home
  • SEARCH
  • 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 6365989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:21:52+00:00 2026-05-25T00:21:52+00:00

One recommendation I get out of the composite pattern is to provide default operations

  • 0

One recommendation I get out of the composite pattern is to provide default operations that handle inappropriate child management operations for a Leaf node (ie, throwing an exception on AddChild, returning an empty enumeration for Children, etc.).

My understanding of the classic pattern is to have a single abstract class with a Leaf subclass and a Composite subclass but if you provide default ops in the parent, doesn’t it effectively obviate the need for the Leaf?

Does anyone do it this way?

Cheers,
Berryl

enter image description here

  • 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-25T00:21:53+00:00Added an answer on May 25, 2026 at 12:21 am

    it’s possible we’re talking about different things. i am assuming the composite pattern is as described on http://en.wikipedia.org/wiki/Composite_pattern

    for that pattern, you would not expose operations that don’t apply to the leaf node, like AddChild (your example) because the Component interface (using the names from the wikipedia article) is intended to expose only common actions that can be performed on either a leaf or a node. so there is no need for defaults.

    there is an add() on the Composite class in the wikipedia article, but that is to add things to the composite “view”, not to any particular data structure. in other words, you might access some parts of a tree of data through a composite interface, but the add() method on the interface is adding or removing items from that collection, and not from the tree itself.

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

Sidebar

Related Questions

In one C++ coding style guide , I found one particular recommendation (page 41,
By dynamic data rating I mean a time-based recommendation system. One example use case
One of my biggest typographical frustrations about HTML is the way that it mangles
Out of the following methods to get the working directory of an executing assembly,
I'm sure that someone already posted this question; however, I would like to get
I am developing RESTful API for my application. All getters (that use HTTP GET)
Does the HATEOAS (hypermedia as the engine of app state) recommendation imply that query
Looking at number of resources I've found out this weird recommendation. Or to quote
I'm a big fan of Yahoo's recommendations for speeding up websites. One of the
One of our external developers has created a minigame in Flash CS5 which we

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.