Welcome Guest, Not a member yet? Register   Sign In
To use associative arrays violates the principles of OOP?

Hello everyone,
I am an university student who needs to develop a web application for a project in software engineering.

Having to respect the principles of OOP, I asked myself some questions:
Using MVC should be no independence between the levels ... but in many video tutorials (youtube) known as the use of associative arrays.
Let me explain:
class ControllerX extends controller
function inserisciX()
$options['nome']= $_POST['nome'];

$id = $this->fornitore_model->aggi

class ModelX extends model
function aggiungi($options=array())
      $fornitore = array(  'p_iva_f'=>$options['p_iva_f'],'nome'=>$options['nome'],
             return $this->db->insert_id();
Now if I change in the controller:
$options[‘p_iva_f’] in $options[‘p_iva_fornitore’]
I have to change even in the Model!
The independence between the layers is lost in this way ???!!!

So,I decided to create a class ( in library):
class Fornitore
... attributes
Now step away from control to model an object of that class! In your opinion is as good solution for a more OO? Or you have other solutions?

Thanks in advance

At some point, you will always need to know what your properties are called. You can make a data model (as you are doing, Fornitore class) but in this class you will still need to have properties like Fornitore->name, Fornitore->kind etc. So, if you want to call this from you controller you might say Fornitore->setName() in stead of saying $options['name'] = 'x'; but still, if you change Fornitore->name to Fornitore->Product_name, this will impact your Controller. Maybe a little bit less because when you change the property Fornitore->name, the method Fornitore->setName could still be called the same.

So, your controllers and models will have to know about each other somehow. It may be through an array or an object or whatever. In the end there will be some things you can't change without changing the other. And that's okay.

It's much better to use an array of options (as you did) then the "old" way of calling a function like add_furniture($name, $kind, $....) because that is really hard to change!

Theme © iAndrew 2016 - Forum software by © MyBB