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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:55:28+00:00 2026-06-16T02:55:28+00:00

Say you have interfaces IBuilding and IDwelling, and class House which implements both. It

  • 0

Say you have interfaces IBuilding and IDwelling, and class House which implements both. It encapsulates a building and a dwelling:

class House implements IBuilding, IDwelling 
{
  private IBuilding building;
  private IDwelling dwelling;
}

If IBuilding and IDwelling each define 15 methods, is it really normal to write 30 methods in the House class that just forward to the methods of the door or window?

That seems very, very tedious. Is this really a thing? A lot of resources indicate that, yes, that’s what you’d do, but they all use super-simple examples that don’t make it look as daunting as I imagine it would be in real life.

Or is there some smarter way to compose that I’m not aware of?

  • 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-16T02:55:29+00:00Added an answer on June 16, 2026 at 2:55 am

    Does it have to be this tedious? No. Is there any smarter way? Yes.

    There are 3 reasons I can think of why You would use the composition:

    1. to establish a “has a” relationship between objects;
    2. to create some kind of a wrapper class (decorator/proxy);
    3. to bypass the single inheritance constraint, if it’s applicable to Your language.

    Of the three, only case #2 may require that You forward every call from Your wrapper class to the wrapped one. Even so, there are some languages that may allow You to create a so called “dynamic” proxy, so that You don’t have to create a method in Your outer class for every method in Your inner class just to forward the call. For example, in Java it’s called the Dynamic Proxy Class, in PHP it’s the magic __call() method.

    Another thing is that situations like the one You described in Your question are very rare in practice.

    UPDATE

    The main problem here is that while using PHP if we want the wrapper class to implement the wrapped class’s interface, the __call() method, indeed, can’t really help us. If the interface has few methods, it’s not difficult to implement them, but what if it has 15? This problem, I believe, is not a problem of the composition, it’s a problem of big interfaces. To avoid such problems You need to follow the Interface Segregation Principle. Sometimes, though, if You’re writing a general purpose API it’s hard to follow the principle. If this is the case, then there’s nothing else left You can do except for one-to-one mapping of method calls. Sorry.

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

Sidebar

Related Questions

Say I have 2 interfaces, which follow the same sequence of function calls. The
Let's say that I have two interfaces and a behavior class: public interface Creable
Say I have the following three classes/interfaces: public interface IImportViewModel { } public class
Lets say I have two interfaces interface A and interface B: public interface A
Let's say I have 2 interfaces here, Moveable and Walkable (sorry for the bad
I have a mess when I combine interfaces and polymorphism. Say I have the
I'm not much into COM interfaces, so i have a small question, say I
Say I have my class @interface Person : NSObject { NSString *name; } I
Say I have a parent interface/class like so interface Parent<T> {} And a number
Lets say I have two interfaces ISomeInterface and ISomeInterface<T> and ISomeInterface<T> inherites from ISomeInterface

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.