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.
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.
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?
@behnam Revati has given you very good advice, and that is your response?
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community