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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:56:02+00:00 2026-05-23T10:56:02+00:00

I have a query regarding the Delegation Design Principle in OOP. I will use

  • 0

I have a query regarding the Delegation Design Principle in OOP. I will use the Window & Rectangle classes example from the GOF design patterns book to explain my query.

public class Window
{
    Rectangle myDelegate;

    public void Area()
    {
        return myDelegate.Area();
    }
}

public class Rectangle
{
    public int Area()
    {
        return 2*3;
    }
}

My question is: Can the Rectangle( the delegate) have a reference to the window( the parent class). i.e:

public class Window
{
    Rectangle myDelegate;
    public int myArea;

    public void Area()
    {
        myDelegate.Area();
    }
}

public class Rectangle
{
    Window myParent;

    public void Area()
    {
        myParent.myArea = 2 * 3;
    }
}

In non trivial cases the above would make it much more convenient for the delegate to update the state of the parent.
Is that logical or am I missing something here?

Thanks!

  • 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-23T10:56:02+00:00Added an answer on May 23, 2026 at 10:56 am
    public interface IShape
    {
      void Area();
      void SetArea(int area);
    }
    
    public class Window : IShape
    {
       private IShape rectangle;
       private int myArea;
    
       public Window(IShape shape)
       {
          rectangle = shape;
       }
    
       public void SetArea(int area)
       {
          myArea = area;
       }
       public void Area()
       {
          rectangle.Area();
       }
    }
    
    public class Rectangle : IShape
    {
       private IShape window;
    
       public Rectangle(IShape shape)
       {
           window = shape;
       }
    
       public void Area()
       {
          SetArea(2 * 3);
       }
    
       public void SetArea(int area)
       {
           window.SetArea(area);
       }
    }
    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a query regarding use of navigation Controller and tabBarController together. I will
Background info I have a query regarding a questions from Sierra & Bates, SCJP
I have a query regarding the directory returned from Path.GetTempPath() function. It returns C:\Documents
I have one query regarding the (UITextfield and Webservice) for example When i start
I have a query regarding launching a native application from a link of website
I have a query regarding accessibility of top level class from member inner class.
I have a query regarding the memory management. Let's begin with an example. Assume
I have a query regarding instantiating a new object in java from a class
regarding to this question , i have a problem if use that query for
I have a query on my database as such: SELECT * FROM expenses WHERE

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.