Technology
Design Patterns & Principles SOLID, MVC

Design patterns & principles SOLID, MVC & Common Designs
Creating quality software does not merely entail coming up with software that functions. It is more about creating a code that is simple to maintain, scale and understand six months down the line. To obtain this, engineers are guided by two foundation blocks of architecture namely Design Principles (the rules) and Design Patterns (the blueprints).
Imagine that it is a house construction. Building codes (e.g., "electrical wires must be insulated") are called Principles, Patterns (e.g., this is a Victorian-style layout).
1. The SOLID Principles - The Golden Rules.
The SOLID principles are five rules of object-oriented design that ensure that the code does not turn into a spaghetti mess.
S - Single Responsibility - There should be only one thing that a class does. When your User object is also interconnecting with databases and emailing, it is doing too much.
O - Open/Closed - Software entities are to be open to be extended and closed to be modified. It should be possible to add new functionality by adding new code, without altering previously tested code.
L - Liskov Substitution - You are expected to be able to substitute one of the parent classes with its child class without application failure.
I - Interface Segregation - Do not make a class provide methods that it does not need. It is preferable to have a lot of narrow and narrow interfaces, rather than having just one large interfaces that does everything.
D - Dependency Inversion - High-level modules are not supposed to be dependent on low-level modules, but abstractions are. This causes your code to be pluggable.
2. Architectural Patterns - MVC
Your high-level structure is determined by architecture patterns. The best-known one is MVC (Model-View-Controller).
This trend divides the application into three different layers in order to maintain the structure of the code,
- Model - The Data. It takes care of logic and database and rules. It is unaware of what the user is viewing, but only of the data.
- View - The Interface. It is what the user perceives (the HTML/CSS). It is just concerned about the presentation of the data.
- Controller - The Brain. It acts as the middleman. It gets user input on the View, requests the Model to change, and then requests the View to display next.
3. Common Design Patterns
Whilst MVC is used to address the larger picture, Design Patterns address repetitive, narrow issues in the code.
Singleton - Makes a single instance of a class, and avails it worldwide. This comes in handy such as database connections.
Factory - A factory object is an object that produces other objects, such that the main code is not required to be aware of the particular type of the created object. This works well in handling complicated objects.
Observer - An observer is simply a type of subscription mechanism in which several objects (observers) are notified in real time of any changes in the state of the object they are observing. This forms the basis of the present reactive structures.
The Verdict - Why Bother?
It seems like an added burden to apply such patterns and principles in the beginning. Nevertheless, they are what one can live and die over when it comes to a project that blows itself out. Adherence to these conventions enables any engineer to enter into a codebase and instantly comprehend the logic that must have been used to construct things.
Test Your Knowledge!
Click the button below to generate an AI-powered quiz based on this article.
Did you enjoy this article?
Show your appreciation by giving it a like!
Conversation (0)
Cite This Article
Generating...


