Why Fat Controller Aunt

Good evening, this is Kyoton (@ippomihosanpo). The other day, for the first time, I had senior Rails seniors do a code review.

I had the Rails code reviewed by an advanced user for the first time

Although the amount of code with simple specifications should have been small, I feel that there were many indications around the controller. I tend to do it all the time. I'm really stupid. ~~ I want to blame the existing Rails product I was involved with was FatController ~~

Why do I turn into an aunt Fat Controller?

** "Is Fat Controller the implementation of fat? Ww" **

I want to fix it before it is dismissed. I searched for the cause.

When I think about it, the model I know was different from the Rails model.

The MVC model was recognized as a "data container". Since it is a vessel, basically it is just a simple input and output of data, and various logics are not written. The idea was stuck all the time.

Java EE's three-tier architecture

When I was learning JavaEE, I studied the system as three layers.

Presentation layer<=>Business logic layer<=>Data access layer<-> DB

It was the "model" that exchanged data between these layers. When applied to MVC, it looks like this.

M: Model
V: Presentation layer
C: Business logic layer / data access layer

When it comes to Rails, Model is a model + data access layer

Rails models inherit from ActiveRecord, allowing the models themselves to access the data. If you think about it in three layers and apply it to MVC, it will look like this ... right?

M: Model data access layer
V: Presentation layer
C: Business logic layer

** If there is this difference in recognition, there is a mistake that the processing around data access must be written in Model, but it is written in Controller due to the three-tier architecture of JavaEE. ** **

at the end

I'm sorry, it's been a long excuse ... I'm sorry if I said something quite natural ... FatController Is there a person who tends to do it and is a former Java field person like this ...? Isn't it ... is that so ...

Rails I'll do my best! !! I will do my best to call a good code! !!

Recommended Posts

Why Fat Controller Aunt
Why Cocoa MVC tends to be Fat