mercredi 7 septembre 2016

Should I use an interface or an abstract hierarchy to update a view?

I have an updateGUI method that can receive two different objects, either object1 or object2 that can be used to update two different views view1 or view2.

view1 and view2 are sub-classed from the abstract class ViewSuper, and a factory class creates the appropriate view. Each view has it's own implementation of the methods initialize and update.

public void updateGUI(Object object){

    GUIFactory viewFactory = new GUIFactory(object);
            ViewSuper view = viewFactory.getView();
            view.initialize();
            view.update();

    }

Now my question is, should I make initialize and update two abstract methods in the ViewSuper class OR create a seperate interface with these methods and make ViewSuper implement this interface?

I'm confused because both the methods seem to be specific to a view hierarchy but at the same time it defines general functionality which is what interfaces (as per my understanding) is used for.

If the answer is to go with abstract methods, please provide an example where I could use the above functionality as an interface.

Aucun commentaire:

Enregistrer un commentaire