Hope a Guru here can help me with this interesting predicament.
I am building an application (its an assignment). And basically there are a specific set of functions that should be implementated. Now, i’ve already established an MVC structure.
Now what I’ve done was try to define a “Controller” interface/class. Basically, this component are a set of controls that the user can interact with. Be it a set of buttons, or a JMenu. Now I’ve also tried to implement an Event structure (java.util.EventObject etc etc). So this is what I have for Controller.
Controller
- addControllerListener(ControllerListener l);
- removeControllerListener(ControllerListener l);
Here’s where the problem starts. I cannot put any implementation inside Controller, as I cannot extend more than 1 class in my components. (For example, my first component is a JPanel, so it has to extend JPanel). But I also feel that while I can also make Controller an interface, and implement it in various classes, it doesn’t guarantee that all subclasses implement this events system in exactly the same way. Furthermore, I also need a dispatchEvent method to dispatch the events, and I cannot for the life of me figure out where to put it without duplicating code across classes.
I researched a little and came across a pattern called Mixins. But I have no idea if that will help, or how to implement.
What do you think? Am I thinking too much? Should I just implement the methods in the subclass? Or is there an elegant solution to this?
Many Thanks
(as this is an assignment, if you wish to refrain from posting code that is fine. I also hope I explained my problem clearly, but if there’s any questions please ask thanks)