I'm implementing classes for simulating and generating different kind of automata. I'd prefer to use the same State and Transition classes for all the automata: NFA, DFA, PDA, etc.For a PDA a transition from one state to another work require some sort of an extension, because the transition requires to pop something from and push something on the stack.So I came up with the idea to let the transitions accept a extension class as template parameter:public class Transition<T> {    private State target;    private T extension;    public Transition(State target, T extension) {        this.target = target;        this.extension = extension;    }    public State getTarget() {        return target;    }    public T getExtension() {        return extension;    }}Note that there are EpsilonTransition and RegularTransition derived classes from this base class.A PDA would require for instance this extension:public class StackExtension {    private Character toPop, toPush;    public StackExtension(Character toPop, Character topush) {        this.toPop = toPop;        this.toPush = topush;    }    public Character getToPop() {        return toPop;    }    public Character getToPush() {        return toPush;    }}So that the PDA class can use Transition<StackExtension> instances.Although this is a solution for my problem, it feels like bad design. Especially for the NFA and DFA, which do not require any extension.Is there another design pattern for my particular problem?
Class template specialization for implementing Automata
java;design;object oriented design;generics
I'm not familiar with the particular automata classes you mention, but whenever you have a one-off class that you'd like to handle in similarly to the other classes, then the Facade pattern is pretty useful.I'm over-simplifying, but the facade pattern is little more than a wrapper around the class in order to either or both of:reduce the complexity of the available class methodsmake the class conform to a particular interfaceIn your case, it sounds like you're wrapping the PDA class so that it will conform to a particular set of interfaces.  That's a perfect use for the facade.