Please be rude honest and tear my work, if you need.
So, I am rewriting a small web application that I recently made. The reason for this is because the code got pretty dirty and I want to learn and apply the best OO design. What this application should do is just CRUD. I have a database with three tables, companies and partners , which are not related to each other and city , which has a 1: n relationship with companies and partners. Very simple. Now I have a few questions that I will indicate at the end of my post. Here I will just try to explain:
My first approach was that I created the company, partner and city classes, pulled out all the data sets from the database and created objects from them:
class company { private $id = null; private $name = null; private $city = null;
And these are all these classes. I extracted each data set from the database and built the company, partner and city objects (the attribute city in these classes is an object with several attributes) and saved them in two arr_companies and arr_partners , which then held these objects ... and it worked fine .
Now I would like to update, insert, delete into the database, and all 3 classes (city, company, partner) need this function. My approach was that I created a new class with a constructor that basically would take two lines of command and object, for example. ('update', 'company') , and he will then update the company directly in the database, leaving my objects untouched. This really upset me, because I had such beautifully designed objects, and I did not know how to use them.
Questions:
Is it bad to have such huge constructors (my biggest is 28 parameters)?
If you have a separate class for the database, or is it better to have, perhaps, an abstract class or an interface for it and let the subclasses themselves handle the update, deletion, insert?
Is it usually simple to write, delete from the database each time, or when I just apply these changes to my objects and only later execute commands in the database, for example, when the session ends?
I suppose an application like this must have been fantastic. What is the approach here? create objects, work with objects, save them in a database?
I have so many questions, but I think many of them I just don’t know how to ask.
Please note that if possible, I would not want to use ORM at this point.
Thanks so much for your time.