TIL: Controller - Service - Repository(MVC pattern)

Adam Sung Min Park·2022년 10월 5일
0

It was quite challenging for me to wrap my head around this concept of Model-View-Controller pattern.
I am still getting used to it and within this blog, hopefully I can retain more knowledge about this concept.

"Open for extension , closed for modification"

What is MVC pattern

It is a software architectural pattern done to separate internal representations of information from the ways infromation is presented to and accepted from the user.

Model

Contains only the pure application data, it contains no logic describing how to present the data to a user.

View

Presents the model's data to the user. The view knows how to access the model's data, but it does not know what this data means or what the user can do to manipulate it.

Controller

Exists between the view and the model. It listens to events triggered by the view (or another external source) and executes the appropriate reaction to these events.
View and the model are connected through a notification mechanism, the result of action is automatically reflected in the view.

Interactions

  • The model is responsible for managing the data of the application. It receives user input from the controller.

  • The view renders presentation of the model in a particular format

  • The controller responds to the user input and performs interactions on the data model objects. The controller receives the input, optionally validates it and then passes the input to the model.

  • Spring implements MVC with the front controller pattern using its DispatcherServlet.

    Benefits

    It is very efficient when it comes to unit testing. Due to the separation of concerns, we can mock adjacent layers and focus on specific layer.

0개의 댓글