T
T
Taras Serevann2016-03-06 11:41:16
PHP
Taras Serevann, 2016-03-06 11:41:16

How to use design patterns in practice?

There is theoretical knowledge on all popular design patterns in PHP and JavaScript, what is their difference and how to work with them, but ... I don’t understand how to apply them in practice, what advantages they have compared to regular code and why they are at all needed at work, because everything is fine without them? In general, it seems to be good, but I feel that something is missing ...
Maybe I need to read some book that will make the necessary changes in the brain, or look at code examples on github?

Answer the question

In order to leave comments, you need to log in

5 answer(s)
S
Sergey, 2016-03-06
Protko @Fesor

why are they needed at all in work, because everything is fine without them?

You see, patterns are not something that is "applied on purpose", they just appear. They were just given names and that's it. This is a "dictionary" to quickly tell another developer that "we'll shove the mediator here, and close this garbage with a facade on top." And all at once everything is clear.
In a word, if you understand the principles of SOLID and GRASP, as well as in principle with OOP (hiding the state, exchanging messages between objects of different types), then the patterns will appear on their own.
TDD also shows itself well in questions of "how to learn how to do it better." In the form of a test, we describe what the object should do, or how they interact, then we do it. If it is inconvenient in tests or they become too tied to the implementation (again, it is inconvenient to maintain) - then something has gone wrong and you need to refactor. And if there are tests, this is very easy and simple to do.

O
OnYourLips, 2016-03-06
@OnYourLips

www.ozon.ru/context/detail/id/31079082

R
Ruslan Kvashnin, 2016-03-06
@RussellKvashnin

It would be nice to read something like this - www.ozon.ru/context/detail/id/33506422
View code examples - it would probably be better on the example of a popular framework.
Understand how it works, where what patterns are applied and what problems they solve.
I would recommend Symfony - https://github.com/symfony/symfony

B
Barmunk, 2016-03-06
@Barmunk

It will come by itself. At one fine moment, you will think, and it would not be bad to put a class factory here instead of a thousand if. Or, here you could put a singleton for the database class, instead of constantly creating objects

S
Stanislav Makarov, 2016-03-06
@Nipheris

In general, it seems to be good, but I feel that something is missing ...

So everything is fine or is something still missing?
You can look at code examples, the main thing is to find a fairly large project with high quality code. As for PHP and JS, I can’t advise such people, not in the subject. Better yet, work on a bigger project. You see, many software development practices only make sense on projects larger than some critical size, and on teams with a sufficiently large number of people.
You can read the Gang of Four, but don't be surprised if what you read there seems like overkill.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question