Answer the question
In order to leave comments, you need to log in
PHP. OOP. Dry examples from books, but it doesn’t work on projects, what to do?
I started to study the object-oriented style in PHP, I already want to leave the procedural one, just because of the "mess" that happens there. > that happens there.
Most of the learning happens from the book, I know, most people just say "Download the PHP engine, start parsing, everything will be easier." It doesn’t work, these engines are too fancy, but there are places where I understand, well, if you bring everything into the big picture, then nothing happens.
I'm reading a book, I'm reading .. I myself am surprised at the clarity of this OOP. Everything immediately becomes clear, you can immediately see the strengths of this style, even working on such code is pleasant. Well, here’s the problem itself, I don’t know how to apply it all in projects, dry examples, no more, I can’t put everything together in one big pile so that the mechanism finally starts working.
PS I have not finished reading the book yet, now I have settled on the Composite template.
How do you use these templates?
I understand that each template, its own organization, its strengths and weaknesses, well, on the site, how to "stretch" everything?
Help, I want to see some kind of result from my work, and not dry examples from books.
Answer the question
In order to leave comments, you need to log in
Download a good framework (I recommend Symfony) and start doing something - even a simple - todo list for yourself on it.
there you will not be able to write procedurally - over time, in practice, you will understand what all this is for.
and it happens that people write with classes (static methods or singleton (well, singleton, even more or less)) and think that this is already OOP
rutracker.org/forum/viewtopic.php?t=4866308 - good explanation of OOP basics
https://www.youtube.com/playlist?list=PLoonZ8wII66... - solid principles explanation
https://www.youtube.com/ playlist?list=PLmqFxxywkat... - explanation of oop principles, grasp patterns, gof patterns
I already want to leave the procedural one, just because of the "mess" that is happening there.PHP itself is a messy language. If you tried Java, then it is nothing compared to OO in PHP, you would admire much more)
In ≈90% of web work, OOP is either not needed at all, or some foreign object is used as a black box. What's the matter? And that session PHP is short-lived. I gave the page to the user - and kirdyk. And everything that needs to be hidden until a new meeting is stuffed into cookies, sessions and databases.
My advice would be to: a) experiment with anything other than the web; b) if possible, write in a more or less object style in JavaScript.
PS And the second reason is that almost everything that a webist needs is already written by someone, it remains only to collect it all into a single site. And the third tip: where OOP is easy to use in the server web is in support for complex formats (wiki markup, for example) and complex protocols.
As for OOP, as I usually do.
I model like a designer.
For example:
The foundation of the house - the foundation of the house is an abstract class, it creates abstract methods and not, which I will use in my house.
I am laying communications, plumbing, sewerage, and so on, I will use all these things in descendants (descendants are the future house and rooms of the house).
House - as mentioned above, we laid the communications. We are building a house. The house will have three floors. The house is one class, it inherits the foundation methods, now the house has water and sewerage and other fundamental communications.
Floor 1 - inherits the House class on the ground floor already has water (we laid it in the foundation).
Floor 2 - inherits the House class
Floor 3 - inherits the House class
Room 1 floor 1 - inherits Floor 1 in my room there is water and sewage, but I laid it in the fundamental class.
And all in the same spirit!!!
Don't forget about https://ru.wikipedia.org/wiki/Encapsulation_(program...
Write your own smallest project and practice knowledge there. P.S. You can also convert the code into UG using OOP, a personal example.
Author, OOP =/= design patterns. Learn exactly OOP and try to put it into practice, only practice gives the necessary skills.
And just keep the patterns in mind, then understanding where and how to use them
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question