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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:16:20+00:00 2026-05-27T15:16:20+00:00

I am containing the primary object (with most of the features) within a helper

  • 0

I am containing the “primary object” (with most of the features) within a “helper object” that will provide convenience methods. I have only an Interface available, aside from a returned object with that interface from a factory method. I am thinking a good way to “extend” this object is composition, but the problem that my superclass must implement the primary object’s interface, which would be about 600 lines of stub code.

Clearly an uncomplicated but verbose solution would be to fill out all the stubs so they merely call the primary object’s methods. Is there a better way than this in Java? In other languages I’m familiar with, there would be ways to do automatic delegation for methods that are not implemented in the helper object.

Example:

class Helper implements Interface {
    Primary primary;

    Helper(Primary _primary) {
        primary = _primary;
    }

    void helper() {
        doStuff();
    }

    // 500 lines of this
    void stub() {
        primary.stub();
    }
}

Note:

Original plan was to just use regular expressions to replace all the stub TODOs in Eclipse with the actual calls. Will be looking for an Eclipse tool that does this automatically though. Also, looks like extending the interface or using Proxy is better in the end, so will be pursuing that.

  • 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-27T15:16:20+00:00Added an answer on May 27, 2026 at 3:16 pm

    There are a few possiblites.


    First: Use an abstract implementation that delegates the calls.

    abstract class InterfaceDelegator implements Interface {
      protected final Interface primary;
      public InterfaceDelegator() {
        this.primary = primary;
      }
      // implements all the calls as: primary.call(...)
    }
    
    class Helper extends InterfaceDelegator {
      // override just the methods you need
    }
    

    Second: Use the proxy (probably cleaner).

    See: http://docs.oracle.com/javase/1.5.0/docs/guide/reflection/proxy.html

    final Interface primary = ...;
    return (Interface) Proxy.newProxyInstance(Inteface.class.getClassLoader(),
       new Class[] { Interface.class },
       new InvocationHandler() {
         public Object invoke(Object proxy, Method m, Object[] args) throws Throwable {
           // if m is a method that you want to change the behaviour of, return something
           // by default, delegate to the primary
           return m.invoke(primary, args);
         }
       });
    

    The invocation handler will handle calls through executing a method that you have coded, an all the others would be delegated to the primary implementation.
    Then, you can wrap a code like this in a method or another factory.


    Third: Using the IDE to generate the methods (as others pointed out).

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

Sidebar

Related Questions

I have a table containing primary key and foreign key that references same table.
In my database I have table AnimalDetails containing animalNumber(primary key),name,breed dateofbirth and an image
I have a directory containing multiple subdirectories. I want to list only those subdirectories
I have a class containing Linq To SQL objects that are used to populate
For examples sake, lets say I have a table containing these columns ID (primary
I have a bunch of methods that make use of jquery to basically generate
An array containing the primary key values of a mysql table will be passed
I have a table in MySQL that for compatibility issues we assigned specific Primary
Lets say that I have a table containing users . Each row in that
I have a collection containing a LOT of Data Transfer Objects that I need

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.