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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:07:28+00:00 2026-05-26T05:07:28+00:00

I have a bunch of classes with a unique set of methods. class1 {

  • 0

I have a bunch of classes with a unique set of methods.

class1 {
    method1(dbconn, args...);
    method2(dbconn, args...);
}

class2 {
    method3(dbconn, args...);
    method4(dbconn, args...);
}

class3 {
    method5(dbconn, args...);
}

We need to expose all the methods via a flat library:

class library {
    init () {
        //create instance of all helper classes
    }
    method1(args...) {
        return class1Instance.method1(getDbconn(), args...);
    }
    method2(args...) {
        return class1Instance.method2(getDbconn(), args...);
    }
    method3(args...) {
        return class2Instance.method3(getDbconn(), args...);
    }
    method4(args...) {
        return class2Instance.method4(getDbconn(), args...);
    }
    method5(args...) {
        return class3Instance.method5(getDbconn(), args...);
    }
}

But it is very time consuming, and there is a lot of repetitive code to move each method into the library. Is there a better way to do this?

Note that each method name is unique. The arguments and return value are of different types.

  • 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-26T05:07:29+00:00Added an answer on May 26, 2026 at 5:07 am

    define an interface:

    interface library {
        method1();
        ...
        methodN();
    }
    

    then use dynamic proxy to reflectively invoke methods of your service implementations. you will also have to find a solution on how to choose on which service particular method should be invoked. but this is not very hard.

    you can implement a class:

    class ServiceDemultiplexer implements InvocationHandler {
    
         ServiceDemultiplexer(Object services[]) {
           ... 
         }
    
         public Object invoke(Object proxy, Method m, Object[] args)
        throws Throwable
         {
            ...
         }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After I have created a serious bunch of classes (with initialize methods), I am
I have a NetBeans project set up with a bunch of source classes and
I have a bunch of classes that have a set of dependencies. Dependency Injection
If i have bunch of classes in objectspace and have a list of methods
I have a bunch of classes I want to rename. Some of them have
Let's say I have a bunch of classes that look something like... class Foo{
I have a bunch of generic interfaces and classes public interface IElement { //
imagine I have a bunch of C++ related classes (all extending the same base
I have a web application that contains a bunch of classes in the App_Code
I'm working with a number of 'helper' classes, which affectively have a bunch of

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.