I know that in OOP you want each object (from a class) to be a "thing", for example. user, validator, etc.
I know the basics of MVC, how they interact with each other.
However, I am wondering if MVC models should be developed in accordance with the traditional design of OOP, i.e. should each model be a base / table / row (solution 2)?
Or is it more like collecting methods that affect the same table or a bunch of related tables (solution 1).
example for the address book module in CodeIgniter, where I want to be able to "CRUD" a Contact and add / remove it to / from the contact group accessible by CRUD.
Model 1 Solution: Combining all related methods (not a real object, but rather a “package”)
class Contacts extends Model { function create_contact() {) function read_contact() {} function update_contact() {} function delete_contact() {} function add_contact_to_group() {} function delete_contact_from_group() {} function create_group() {} function read_group() {} function update_group() {} function delete_group() {} }
Model 2 Solution: OOP Method (One Class for Each File)
class Contact extends Model { private $name = ''; private $id = ''; function create_contact() {) function read_contact() {} function update_contact() {} function delete_contact() {} } class ContactGroup extends Model { private $name = ''; private $id = ''; function add_contact_to_group() {} function delete_contact_from_group() {} function create_group() {} function read_group() {} function update_group() {} function delete_group() {} }
I do not know how to think when I want to create models. and the examples above are my real tasks in creating an address book. Should I just combine all the functions in one class. then the class contains different logic (contact and group), so it cannot save properties that are specific to any of them.
Solution 2 works in accordance with OOP. but I do not know why I should make such a separation. what advantages will be, for example, a contact object. This is certainly not a User object, so why would Contact live with its own state (properties and methods). Because I tend to think this way: if something needs a state, then I create an OOP class so that methods can influence state or other things based on state.
so should the models be “in terms of state”? if they do not require state, why should I create it according to the OOP pattern. then I could just put it all together as a package solution.
you had experienced guys with OOP / MVC, please clarify how you should think here in this specific task (and generally when creating a model).
EDIT: Think about controllers in MVC. they are created in accordance with the solution "package". It makes me think ...