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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:21:39+00:00 2026-06-10T07:21:39+00:00

Let’s have a simple Decorator example: struct IStuff { virtual void Info()=0; virtual ~IStuff()

  • 0

Let’s have a simple Decorator example:

struct IStuff {
  virtual void Info()=0;
  virtual ~IStuff() { }
};

class Ugly : public IStuff {
public:
  void Info() { cout  << "Ugly"; }
};

class Shiny : public IStuff {
  IStuff* stuff;
public:
  Shiny(IStuff* stuff) {
    this->stuff = stuff;
  }
  ~Shiny() {
    delete stuff;
  }
  void Info() {
    stuff->Info(); // <------------------------------- call super?
    cout << "->Shiny";
  }
};

int main() {
  IStuff* s = new Ugly();
  s = new Shiny(s); // decorate
  s = new Shiny(s); // decorate more
  s->Info(); // Ugly->Shiny->Shiny
  delete s;
  return 0;
}

Is this also the Call super anti-pattern?

Call super is a design pattern in which a particular class stipulates that in a derived subclass, the user is required to override a method and call back the overridden function itself at a particular point.

Here is a little different implementation Is there any difference in design?

  • 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-10T07:21:41+00:00Added an answer on June 10, 2026 at 7:21 am

    This is not Call super. You call the Info method of another IStuff instance, not the overriden version.

    Call super version:

    struct IStuff {
      // If you override this, you MUST call the base class version <-- call super
      virtual void Info()
      {
        // a default implementation.
    
        std::cout << "Super call ";  
      }
      virtual ~IStuff() { }
    };
    
    class Shiny : public IStuff {
    public:
      void Info() {
        IStuff::Info();  // don't forget to call base implementation.
        std::cout << "->Shiny";
      }
    };
    

    Some implementations of Decorator are making a super call to a Decorator base class, that is responsible to hold, call and manage the decorated reference:

    struct IStuff 
    {
      virtual void Info() = 0;
      virtual ~IStuff() { }
    };
    
    class Stuff : public IStuff
    {
    public:
        void Info() { std::cout << "Basic stuff"; }
    };
    
    class StuffDecorator : public IStuff
    {
        IStuff* decorated_;
    public:
        StuffDecorator(IStuff* decoratedStuff) :
            decorated_(decoratedStuff) {}
        ~StuffDecorator() { delete decorated_; }
    
        void Info()
        {
            decorated_->Info();
        }
    };
    
    class Shiny : public StuffDecorator 
    {
    public:
      Shiny(IStuff* stuff) : StuffDecorator(stuff) { }
    
      void Info() 
      {
        StuffDecorator::Info();
        std::cout << "->Shiny";
      }
    };
    

    To avoid the super call you might want to combine Decorator with Template Method:

    class StuffDecorator : public IStuff
    {
        IStuff* decorated_;
    public:
        StuffDecorator(IStuff* decoratedStuff) :
            decorated_(decoratedStuff) {}
        ~StuffDecorator() { delete decorated_; }
    
        void Info()
        {
            decorated_->Info();
            DoInfo();
        }
    private:
        // Template method
        virtual void DoInfo() = 0;
    };
    
    
    class Shiny : public StuffDecorator 
    {
    public:
      Shiny(IStuff* stuff) : StuffDecorator(stuff) { }
    private:
      void DoInfo() 
      {
        std::cout << "->Shiny";
      }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let me explain best with an example. Say you have node class that can
Let's say I have the following classes : public class MyProductCode { private String
Let's imagine I have a Java class of the type: public class MyClass {
let's say we have some simple code like this : private static void Main()
Let's have an example like below: package xliiv.sandbox; import android.app.Activity; import android.os.Bundle; import android.util.Log;
Let's say on a page I have alot of this repeated: <div class=entry> <h4>Magic:</h4>
Let's say I have the following text: (example) <table> <tr> <td> <span>col1</span> </td> <td>col2</td>
Let's say you have a class called Customer, which contains the following fields: UserName
Let's say we have a simple function defined in a pseudo language. List<Numbers> SortNumbers(List<Numbers>
Let's say I have 2 functions: void function1(int *ptr) { printf(%d, *ptr); } and

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.