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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:30:27+00:00 2026-06-01T18:30:27+00:00

In the following UML diagram that represents a Decorator pattern for designing games character

  • 0

In the following UML diagram that represents a Decorator pattern for designing games character scenario, how will the objects look like in heap when following code is executed?

Decorator UML

GameCharacter milo;
milo = new Armour (new DefensiveSpell(new Knight()));
milo.Defend();

Also, is the above code the same as the following code:

GameCharacter milo;
milo = new Knight();
milo = new DefensiveSpell(milo);
milo = new Armour(milo);
milo.Defend();

I believe the Knight object will be created first on the heap with ‘milo’ object pointing to it. Then DefensiveSpell and Armour will be created. The ‘wrapped’ object in DefensiveSpell will then point to ‘Knight’ and the ‘wrapped’ object in Armour will point to DefensiveSpell. Also, when milo.Defend() code is executed, I believe the Defend() method is called in Armour which will call Defend() of DefensiveSpell which in turn will call Defend() of knight that finally performs some defend action.
Here is the diagram that I have so far:

Memory diagram

  • 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-01T18:30:29+00:00Added an answer on June 1, 2026 at 6:30 pm

    You’ve got it almost completely right, just a couple of minor points:
    milo and wrapped are references to objects, not objects themselves. Thus, there will be an Armour object which contains a reference to a DefensiveSpell object, which contains a reference to a Knight object. The milo reference points to the Armour object, not the Knight object.

    Also, when you invoke defend, it will not automatically forward the call to the super class. So, unless your decorators explicitly call base.Defend().

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

Sidebar

Related Questions

What does the dashed and filled arrow mean in the following UML diagram for
I have following UML class diagram and java coding for each, please tell me
Given the following sequence diagram, how to express the equivalent in a UML communication
We are attempting to use VS2008 Class Designer for a UML-like class diagram. However,
What is UML sequence diagram of the following code featuring a class with two
An analysis from a colleague with UML diagrams contains the following: 0..° I'm familiar
Given the following situation (UML below), If Y has the method: public void PrintWs();
I want to describe the following situation in an UML Classdiagram: A day, on
Following code takes like 2500 milliseconds on an i7-*3.4 GHz windows-7 64-bit computer to
I am just starting to use UML and have came to the following question:

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.