Base principles of OOP
MVC Design Pattern
- Model maintains the relationship between Object and Database and handles validation, association, transactions.
It means that the model will maintain an extreme relation with the Database. Each model (can) represent a database table (in case of SQL databases). This model object gains capabilities (inherited from ActiveRecord — Rails class) to retrieve, save, edit, and delete data from database table. We use model objects as a layer between our application and the database.
Besides that relation with the database, the model can create validations and associations between models.
- View is a presentation of data in a particular format, triggered by a controller’s decision to present the data.
It is the presentation of the request’s response. This presentation can be a bunch of format types: PDF, HTML, JSON, etc. The final result of a view will be probably the user interface (UI) — Part of the “Client”.
- Controller is the facility within the application that directs traffic, on the one hand querying the models for specific data, and on the other hand organising that data (searching, sorting) into a form that fits the needs of a given view.