Support the ongoing development of Laravel.io →
Configuration IOC Views
Last updated 1 year ago.
0

I do not remember where i heard about it, but if you have more then 3 classes in constructor it's "red light". Class has to many dependencies, to many logic in it. This class has 8 dependencies...

One class should be doing only one thing.

Look in to SOLID principles.

  • Do not mix php with html (if it isn't a view).
  • What is templates purpose -> look into Blade (Laravel templating)

One more thing. Assign all properties in constructor (or call method thats only job is to assign property, e.g. $this->setProperty($property) ), i noticed that you are passing them to methods and only then assigning. It has no difference now, but later when for some reasons you will need change method calling order or what ever, it could break things.

Remember when oop was something new to me... I wrote some peaces of s**t. If I were asking questions that you are, i would avoid some big mistakes, and evolved a lot faster.

Last updated 1 year ago.
0

revati said:

I do not remember where i heard about it, but if you have more then 3 classes in constructor it's "red light". Class has to many dependencies, to many logic in it. This class has 8 dependencies...

One class should be doing only one thing.

Look in to SOLID principles.

  • Do not mix php with html (if it isn't a view).
  • What is templates purpose -> look into Blade (Laravel templating)

One more thing. Assign all properties in constructor (or call method thats only job is to assign property, e.g. $this->setProperty($property) ), i noticed that you are passing them to methods and only then assigning. It has no difference now, but later when for some reasons you will need change method calling order or what ever, it could break things.

Remember when oop was something new to me... I wrote some peaces of s**t. If I were asking questions that you are, i would avoid some big mistakes, and evolved a lot faster.

Why didn't you ask quesitons when you were learning?

Last updated 1 year ago.
0

@behnam Revati has given you very good advice, and that is your response?

Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.