What is SOLID?
SOLID stands for ** of the first five object-oriented design (OOD) ** principles, known to Robert C. Martin as [Uncle Bob (https://en.wikipedia.org/wiki/Robert_Cecil_Martin].
WHAT DOES SOLID Mean?
Q — Single responsibility principle
O — On-off policy
L — Liskov substitute principle
I — Interface allocation policy
D — Addiction reduction Policy
Purpose of SOLID Design Principles:
- To make the code more sustainable.
- Make it easier to read and understand code.
- To make it easier to quickly expand the system with new functions without disrupting existing functions.
- Writing clean code.
Q — Let's Look at the Single Responsibility Policy.
According to the official definition of the principle of sole responsibility
A class must have only one reason to change.
What's that supposed to mean? Let's take an example from Laravel. On Controller
Storeuse of method
Store The validate process will look like this.
namespace App\Http\Controllers use App\Http\Controllers\Controller;class PostController extends Controller $validator = Validator::make($request->all(), [
public function store(Request $request)
'title' => 'required|string|max:200',
'description' => 'required|string',
use App\Post; // validate incoming request // finally store our post
Let's apply the Single responsibility policy here, Laravel removes the Form Request object from the package. Create a form request using an artisan command.
php artisan make:request StoreBlogPost
Creates a new request class
Now we've created a form request
PostControllerlet's change it to use it
namespace App\Http\Controllers use App\Http\Controllers\Controller;class PostController extends Controller
public function store(StoreBlogPost $request)
use App\Post; // finally store our post
Automatically verifies the form request and returns verified requests. You can now use this method to verify your data as you wish.
In this article, we learned how to make the first letter of solid, S, the principle of sole responsibility. I hope this article was useful.