Characteristic 4 - No business logic in the controller

Characteristic 4 - Controllers should have no routing logic only business logic

This characteristic of the controller is based on the previous two characteristics of the controller. As the controllers should be singleton and also they should be controlling the entry and exit of the system, the controllers at no point of time should have the business logic, the only logic that should be there within the controllers is the routing logic.

In the example we can see that there is a single instance of the controller. There are also a large number of structural components that needs to be manipulated by the controller. Now as shown in the figure, the controller has business logic [Business logic means the logic of invoking different structural components in accordance with the business logic of a particular behavior] within it for various behaviors and there is a single instance of the controller within the system. We also know that the controller is the first component that a request encounters. If a large number of request comes to the system, these requests will be simultaneously be intercepted by the controller and because the controller has business logic, there will be critical sections [non thread safe] of code within the controller wherein if multiple request threads reach the same critical region at the same time, we will start getting mission/business level inconsistencies within systems and the system might start giving improper results. The critical sections of code within the controller containing business logic is shown by red ovals in the figure.

Figure- Figure

Why is the constraint of no business logic in the controller needed?

This constraint is because of the fact that controllers are singleton. If the constraint of controllers being singleton was not there and if for every other client request a new instance of controller could have been created then the constraint of no business logic was needed.

Ideally there can be no situation wherein we cannot remove the business logic from the controller but in case if you are not able to remove the business logic, then the system cannot handle the requests parallely/ concurrently in that case request will be handled by the system sqeuentically which will increase the response time exponentially thereby degrading the performance of the system.

SingleThreadModel interface provided in the servlet API is primarily meant for the same.

This characteristic is not just true for software controllers, it is true for other type of system controllers as well.

My PM doesnt know how to code .. to only thing he knows is to boss around ..

Just a quick analogy, I have come across lot of software engineers who say … that ..”my project manager doesn’t know how to code , the only thing he knows is to boss around” Based on my experience I can say many of the engineers/developers consider their managers as liabilities on the project for a very simple reason, according to them they don’t do anything, the only thing they do is to boss around and give directions.

Let us understand it is not that the Project Manager doesn’t know how to code and he his just bossing around to satisfy his ego… let us understand as a manager his job is not to code but to act as the controller and get the work done from the various project resources available to him ie he should not have the business logic , he should only have the routing logic.

History shows professionals who are brilliant techies mostly don’t turn out to be great managers. One of the reasons for the same is because they are “Genius” they want to do a lot of things themselves without realizing that they themselves are becoming a bottleneck within the system , second even if they don’t do it themselves and delegate the work to the team their estimations go for a toss. Because they are genius, they may only take few minutes to do a task but they also assume that every other person is a genius as well and that’s where their estimate goes for a toss.

Hence this characteristic plays a very critical role in the success of any system.

Hemant Jha
Founder - VPlanSolutions
Researcher, Trainer