G
G
goodMenik12015-05-18 18:23:01
PHP
goodMenik1, 2015-05-18 18:23:01

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

8 answer(s)
Y
Yuri, 2015-05-18
@goodMenik1

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

I
Ivan Lemeshev, 2015-05-28
@vanlmshv

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

T
trevoga_su, 2015-05-18
@trevoga_su

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)
My advice to you is one - start reading Fowler and Grady Booch. The second is purely OO theory, the first is real architectural solutions.
In Fowler, read carefully the part that describes domain objects and those decisions that affect OO programming and DBMS . This book brought me to a new level, although I will have to re-read it more than once - not everything is so simple.
The fact is that OOP in PHP is essentially useless if you do not represent records from the database as objects. And this is a very non-trivial task. Read everything in the book that rocks ORM topics - Data Mapper, Active Record and read about data recording gateways. Without translating the domain models from the DBMS into objects, there will in fact be no OO in your programs.

M
Mercury13, 2015-05-18
@Mercury13

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.

I
igorpopryduhin, 2018-12-04
@igorpopryduhin

5c0640e53ed75188503117.jpeg
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...

O
olexandr7, 2015-05-18
@olexandr7

Write your own smallest project and practice knowledge there. P.S. You can also convert the code into UG using OOP, a personal example.

H
He11ion, 2015-05-18
@He11ion

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

2
2vtlk, 2015-05-19
@2vtlk

If you write in symfony or laravel, then there will be no such problems.3NVMnB

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question