Answer the question
In order to leave comments, you need to log in
How to design classes?
Good day!
Rewriting my small project from scratch using classes.
Tell me, experienced colleagues.
There is such a code:
it displays such a thing (everything is scattered, it doesn’t matter where which column is)
Now the question is:
I want to rewrite the same code in OOP, or maybe even switch to it from the procedural.
Obviously, there will be a bunch of scripts, they all need to be transferred according to the OOP methodology. In OOP, I understand and use a little - I understand how abstract classes, static methods, traits, interfaces work, but how and where to apply, and most importantly why - no.
Tell me, according to what logic to display information from classes, - to make a method inside a class or a separate class that will only edit, according to what principle then to enter this information into the database - again a class or embed a method in a class? Where to use static methods, where are traits better? And do I need them here at all?
How would you design?
The functions are mainly output of information to the template, adding information to the database, sorting, updating.
I would love to use the twig, but then my code will be very complicated for me and it's good if I finish the project in a year or two.
Answer the question
In order to leave comments, you need to log in
If the first is outputting information to a template, definitely go to twig.
When you start using twig, you will be pleasantly surprised how easy the entry threshold is...
For database work, try Doctrine 2 Object Relational Mapper (ORM) .
If you saw something of your own - use Object Relational Mapping.
If you want everything at once and more: twig, ORM, OOP all in one - take some kind of framework - for example, Zend Framework or Symfony.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question