SOLID no Laravel

Asked

Viewed 458 times

0

Laravel breaks the concepts of SOLID?

SRP - Single Liability Principle Unique - A class must have one, and only one, reason to change.

OCP - Open/closed principle Open/closed principle - You must be able to extend a class behavior without the need to modify it.

LSP - Liskov substitution principle Liskov - Derived classes should be substitutable with their classes bases.

ISP - Interface segregation principle interfaces - Many specific interfaces are better than one general single interface.

DIP - Dependency inversion principle dependency - Rely on abstractions and not implementations.

and if we use the command php artisan make:controller TestController -r he will create a Controller with all the verbs HTTP, which turns out to be like index, edit, delete and store in a single controller.

In case we had such a class:

class TestController extends Controller 
{

public function index() {

 /*  Consulta  */

}
public function store() {

 /*  Insere  */

}

public function edit($id) 
{

/*  Edita  */

}
public function delete($id)
{

/*  Deleta  */

}

This does not end up violating one of SOLID’s principles?

Source: Medium

  • And why do you think that? And what is the problem with that? We also have a source here: https://answall.com/q/178718/101

  • I think (I’m still learning, so the question) that are totally different functions, so they should be separated, no?

  • 6

    As functions they are separate, as organizational unit seems to have a coherence, after all they are all actions of a controller. Can you question that? Can you. Should you use an MVC? Is that what SOLID is all about? https://answall.com/q/336319/101 Do people know what they are saying? Is it simple to define what is cohesive or not? That deep down is what SOLID preaches. Does forgetting OOP no longer help in SRP? And deep down it seems that it’s only about him who is talking and not SOLID. What I’m sure is that memorizing and following rules doesn’t make software any better.

  • @Rodrigopires This business of sólid in Laravel is shooting on foot program the bang and be happy

  • @Rodrigopires da para trabalhar com Aravel working with Solid good, I didn’t understand what the bullshit is...

1 answer

0

Dude, SOLID is very important for large systems with complex business rules. To use SOLID in Laravel you’ll have to do it by hand. You will have to create all the separation directories: Service, Repository, Entity (if applicable), etc. Then you will make the injections according to the flow of the architecture you find best. Then you apply the other rules, creating intefaces and Factories, applying dependency inversion and so on. Laravel does not break the SOLID principle is exactly the controller you will call the services from. But there are several lines of thought on this, will be at your discretion as will the controller, but no business rules in it. I hope I’ve helped.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.