lundi 28 septembre 2015

MVC layer level listener interface design (Should listener be generic or not)

I came across this design, So I am not quite sure which way to lean towards. Any help would be much appreciated

I have three levels
a) Dialog
b) Controller
c) View

The Dialog creates the Controller and the view object. The Dialog passes down the view to the controller on the constructors argument.

Some of this design is existing, so the code base is already messed up, but regardless, this is my question

Say if I have a Listener interface.

Interface DoSomthing{
int doSomthing();
}

The existing flow is like below Dialog implements the listener and adds it to the controller. The controller implements the listener,(again no implementation change from the dialog) and adds it to the view. The view notifies the controller and then the controller notifies the Dialog and the dialog performs the action as needed.

So the Dialog creates the controller and implements the above interface and adds it to the controller.

Should the controller implement the same interface again or should it be a different interface.

As of now the implementation detail are the same, but I think since we look this as a layer.

Should I have it like this
a) View Listener
b) Controller Listener

And make the Dialog implement the Controller listener and the Controller implement the view listener.

Like this

Interface DoSomthingContollerListener{
int doSomthingController();
}

Interface DoSomthingViewListener{
int doSomthingView();
}

Or just have a generic listener in both the view and controller and implement them differently.

The problem I had having them as a generic listener is,I think since we use an MVC(though the above does not follow MVC at all) type design the interface should be for each level.

Am I wrong?

Aucun commentaire:

Enregistrer un commentaire