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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:12:24+00:00 2026-06-02T17:12:24+00:00

I have an interface IAction that has one generic method: public interface IAction {

  • 0

I have an interface IAction that has one generic method:

public interface IAction  {
    void doAction(ISignal sig, IState state);
}

Another class IActionAbstract then implements the IAction interface and calls overloaded methods with instanceof clauses:

public abstract class IActionAbstract implements IAction
{

@Override
public void doAction(ISignal sig, IState state)
{
    if(sig instanceof ISignal1 && state instanceof IState1)
    {
        doOther((ISignal1)sig, (IState1)state);
    }       
    else if(sig instanceof ISignal2 && state instanceof IState1)
    {
        doOther((ISignal2)sig, (IState1)state);
    }
    else if(sig instanceof ISignal1 && state instanceof IState2)
    {
        doOther((ISignal1)sig, (IState2)state);
    }
}

abstract void doOther(ISignal1 sig, IState1 state);
abstract void doOther(ISignal2 sig, IState1 state);
abstract void doOther(ISignal1 sig, IState2 state);
}

I would like to remove the instanceof checks and replace with generics or redesign, but without adding more methods to IAction. I see how to do this with reflection, but would like to avoid if possible.

Edit: Removed generics since they are not required. I will try and explain more to give a better idea of this approach. The IActionAbstract file might be generated with the developer making an impl to implement the methods. ISignal and IState together make the method unique and can be thought of as a state machine state and signal.

Usage of the classes would look like in pseudo-code:

List<IAction> actions;
actions.get(i).doAction(ISignal1, IState1);
actions.get(i).doAction(ISignal2, IState2);
and so on...
  • 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-02T17:12:25+00:00Added an answer on June 2, 2026 at 5:12 pm

    Looks to me like you want separate implementations of IAction, i.e.

    // generic interface declaration
    public interface IAction<T extends ISignal, S extends IState> {
        void doAction(T sig, S state);
    }
    
    // typed implementations of the generic interface
    public class Action1 implements IAction<Signal1, State1> {
        doAction(Signal1 sig, State1 state) {
            // impl
        }
    }
    
    // another typed implementations of the generic interface
    public class Action2 implements IAction<Signal2, State2> {
        doAction(Signal2 sig, State2 state) {
            // impl
        }
    }
    

    …and so on. Otherwise you’re not even using generics.

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

Sidebar

Related Questions

I have interface Foo public interface Foo { public void test(); } Class FooChild
I have a UISegmentedControl that has 6 segments which I created in Interface Builder.
If I have interface IFoo, and have several classes that implement it, what is
Lets say you have interface definition. That interface can be Operation . Then you
Let's say we have interface window_creator that responsible for creation of windows. For simplicity
Have a interface class abc { public: virtual int foo() = 0; ... }
I have an Interface called IStep that can do some computation (See Execution in
lets say I have an NSWindow Class, that has several events for mouse and
I am developing app that has multiple skins and I have a dilemma on
I have a UITabBarController which has on one of its tabs, a UINavigationController. 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.