2

I'm developing a desktop application with a GUI. To do so, I'm using the MVC design pattern for the GUI part. For now the application consists of a single window (view) with one controller interacting with the backend (model).

The interaction is becoming more complex day by day with the controller getting more and more methods to handle inputs and adding more dependencies with model objects. Since it's a best practice to keep the classes and methods small I feel like delegating some tasks, is it right? Is there any clean way to do so?

Regarding the dependencies with the model, I'm using a facade object, but again I feel like it's getting too overloaded.

2 Answers 2

1

Turn your question upside down. When is it a good idea not to delegate large pieces of functionality to an other class? ....

Bit of a no-brainer isn't it? I can only think of a few scenarios where I wouldn't want to delegate, and I'd view it being difficult / impractical to do so as a major design flaw.

How to do it, is a far more subjective question.

Based on your question, I'd also be reviewing whether one form was good idea as well. User defined controls maybe.

0

I suggest you google up the View Helper pattern, it's one I prefer (I am using Spring WebMVC).

Controller methods only receive the parameters, construct a parameter Data Transfer Object and pass this into a ViewHelper class. The ViewHelper class returns a result DTO ready for the consuming view.

The ViewHelper can call the necessary Service classes using the inbound param DTO and construct/ augment the return DTO.

Encapsulating the inbound and outbound parameters/ results into DTO objects help reduce the effort to maintain your code. For example, when a new requirement introduces an additional parameter to the controller method signature, then only the controller, the DTO and the affected service are affected. You do not have to "pass through" this new parameter all the way from the controller to the DAO.

In summary, keep your controller classes light. Encapsulate in/out data with DTO's. Introduce ViewHelpers to offload the complexity of gathering data from your service(s).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.