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

  • Home
  • SEARCH
  • 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 68175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T19:22:31+00:00 2026-05-10T19:22:31+00:00

First off, I know next to nothing about language theory, and I barely know

  • 0

First off, I know next to nothing about language theory, and I barely know any other languages except Java, but I had an idea that I think would be cool, but I need you guys to tell me:
a: why it sucks
b: how language x has had that for years
c: how my mind sucks
d: all of the above

The idea would give composition the same ease of code reuse that extends does.

So if you had a class like this:

 public interface A {       public void methodInA();   } 

And then you had a class like this:

 public class B {       private composed A;     public B() {         // construct A within constructor     } } 

You would then be able to do this:

 B myB = new B(); myB.methodInA(); 

Without having to add in the delegation in B’s class. But you could also do the same as with inheritance, ie:

 @Overrides public void methodInA(){     // B's own delegation method } 

Disadvantages include:

  • methods are hidden in the source code, making it less obvious where the call is coming from, but this is also the case with extends
  • if composed fields share the same method signature there needs to be a conflict resolved (how do conflicting interfaces solve this?)
  • if you wanted to have several composed fields of the same type, there would be an obvious conflict for which field to delegate to
  • probably 100 other things I’ve not thought of

Like I say, I’m obviously no language theorist, and I haven’t spent ages thinking about it, the idea just popped in my head and I wanted to know how wrong I am. I just think it would be kind of cool.

  • 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. 2026-05-10T19:22:32+00:00Added an answer on May 10, 2026 at 7:22 pm

    I think if you restricted it such that a class could only use this feature to compose a single class it would be somewhat useful and would avoid a lot of the headaches that are being discussed.

    Personally I hate inheritance of concrete classes. I’m a big proponent of Item 14 from Bloch’s Effective Java, Favor composition over inheritence. I think that something like this would make it a little easier to implement the idiom he recommends in that item.

    Honestly, if you really knew what you were doing I’ll bet you could write a compiler annotation that would handle this. So assuming you had a class Bar that implemented the interface IBar, your class would look like this:

    public class Foo {    @Delegate(IBar.class)   private Bar bar;    // initialize bar via constructor or setter } 

    Then during compilation Foo could be made to implement IBar and any of the methods on that interface that weren’t already implemented by Foo would end up being generated to look like this:

    public Baz method1(Qux val) {   return bar.method1(val); } 

    As mentioned above you would want to make the restriction that only one field per class could use this annotation. If multiple fields had this annotation you’d probably want to throw a compilation error. Alternatively you could figure out a way to encode some sort of precedence model into the parameters passed to it.

    Now that I’ve written this out that seems kinda cool. Maybe I’ll play around with it next week. I’ll update this if I manage to figure anything out.

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

Sidebar

Related Questions

first off I'm going to say I don't know a whole lot about theory
First off I know this has been covered on SO. But the most popular
First off, I know my title can be formulated better, but my math classes
First off I want to start off saying that I don't know anything about
First, I know there are methods off of the generic List<> class already in
First off, I know this may be a very stupid question, so don't shoot
First off: I know that AES is a block cipher and not a hashing
First off, does anyone know of a good place to get help with CodeIgniter?
First off, I am using Windows XP. I have multiple hard drives and it
First off, I understand the reasons why an interface or abstract class (in the

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.