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 9038683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:32:49+00:00 2026-06-16T09:32:49+00:00

I have already looked at this question enter link description here however i cant

  • 0

I have already looked at this question enter link description here

however i cant seem to find the answer to WHY there is a composition between the two objects

The link to the uml is here:

enter link description here

Can anyone explain to me why there is a composition? or why there should be anything other than the generalization?

  • 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-06-16T09:32:50+00:00Added an answer on June 16, 2026 at 9:32 am

    Because the point of the decorator pattern is to decorate a contained component:

    public interface Logger {
        void print(String message);
    }
    
    public class ConsoleLogger implements Logger {
        @Override
        public void print(String message) {
            System.out.println(message);
        }
    }
    
    public class FileLogger implements Logger {
        @Override
        public void print(String message) {
            // TODO write the message to a file
        }
    }
    
    public WithCurrentDateLoggerDecorator implements Logger {
        private Logger delegate;
    
        public WithCurrentDateLoggerDecorator(Logger delegate) {
            this.delegate = delegate;
        }
    
        @Override
        public void print(String message) {
            message = new Date() + " - " + message;
            delegate.print(message);
        }
    }
    

    Using the above, the decorator can be used anywhere you would use any other logger, and the decorator can decorate any kind of logger (console, file, email, socket, whatever). It doesn’t care what the concrete logger does (print to the console or print to a file). All it does is decorate the concrete logger, by adding the current date to the message before letting the delegate logger print it.

    If you had to do this without composition (or rather delegation), you would have to create a WithCurrentDateFileLogger and a WithCurrentDateConsoleLogger (add one subclass for each concrete logger). And every other decoration or concrete logger type would make the number of classes to create explode, due to the high number of combinations.

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

Sidebar

Related Questions

I have already looked at this question but there was no solution. Here is
I have already looked at this question and even though the question titles seem
I have already looked at this similar question but i am still wondering if
Have already looked at this stack question , at which point I looked at
I've looked at every question so far and none seem to actually answer this
Quick question (and sorry if it's already been asked, I have looked but couldn't
I have already surveyed SO for an answer, and could not find an appropriate
Before I posted this question, I already looked this , but I couldn't get
I've already posted this question here , but since it's maybe not that Qt-specific,
I have looked at many posts but unable to find an answer to my

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.