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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:47:40+00:00 2026-06-10T08:47:40+00:00

Can someone please walk me through the differences between (as in benefits of) creating

  • 0

Can someone please walk me through the differences between (as in benefits of) creating decorator classes using constructor injection of another class as opposed to class inheritance? In the examples I can think of, I might accomplish the same end goal in one of two ways but I suspect I am missing something fundamental.

  • 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-10T08:47:42+00:00Added an answer on June 10, 2026 at 8:47 am

    The decorator pattern concerns composing an object. To be able to inherit the type of that object, it must obviously be inheritable. Not all types are designed for inheritance, i.e., meant to be base classes, even if they from a purely technical viewpoint can be inherited (which I consider a design flaw).

    The raison d’être for the decorator pattern is to be able to modify the behavior of objects without modifying the objects themselves. By inheriting, you’re essentially modifying the object itself and what you get then is regular behavioral change through polymorphism, meaning that you did not accomplish the same thing.

    So, both decoration and inheritance has their uses. Use decoration when anyone of these is true

    • you can not inherit (for example if the class is sealed in C#)
    • you should not inherit (the class is obviously not meant to be a base class)
    • you want to change the behavior of one particular object many times (by wrapping it with decorators of different behavior)

    Note that inheritance is the most powerful tool there is in the OO toolbox. With great power comes great responsibility and that’s not always easy to cope with. I’d say: Always compose or aggregate. When that just cannot be done, inherit. If you can’t inherit, try harder to compose or aggregate.”

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

Sidebar

Related Questions

Can someone please walk me through mathematical part of the solution of the following
Can someone please help me on this find specific record Edit through MS access
Can someone please provide an example of using set_bound() method from Test::MockObject module? Can
Can someone please explain the difference between the following queries. The joins in the
Can someone please explain the following constructor syntax to me. I haven't come across
Can someone please explain to me what is the difference between protected / public
Can someone please tell me what I'm doing wrong? I'm using the following arguments
Can someone please tell me what this means: 07-04 09:54:38.048: I/DetailActivity(15496): Title that is
Can someone please explain why ?___SID=U is appearing in some Magento URLs on my
Can someone please explain how Read/Show works.. I cannot find any tutorials on it.

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.