To use associative arrays violates the principles of OOP? |
[eluser]Giga[/eluser]
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: Code: class ControllerX extends 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): Code: class Fornitore Thanks in advance
[eluser]Caio Russo[/eluser]
hi Giga, think that way: if you have a variable called $p_iva_f and change it into $p_iva_fornitore you have to change it in any levels, right? so, if you have a array with some index name and change that index name, it's not the same? Cheers. Caio
[eluser]Giga[/eluser]
[quote author="Caio Russo" date="1272442392"]hi Giga, think that way: if you have a variable called $p_iva_f and change it into $p_iva_fornitore you have to change it in any levels, right? so, if you have a array with some index name and change that index name, it's not the same? Cheers. Caio[/quote] Thanks for the reply, but if I use a class: Code: class Fornitorem { Code: $this->load->library('fornitorem');
[eluser]Caio Russo[/eluser]
Hi Giga. Absolutely right, but it's a different approach from what you asked before. If u have a function that receive parameters, doesn't matter if you change the name. But if you use the array or variable directly then you have to change. Caio
[eluser]Giga[/eluser]
[quote author="Caio Russo" date="1272482956"]Hi Giga. Absolutely right, but it's a different approach from what you asked before. If u have a function that receive parameters, doesn't matter if you change the name. But if you use the array or variable directly then you have to change. Caio[/quote] My question is: What is the best approach? In my opinion the latter approach to observe the principles of software engineering as reuse, maintainability, low dependence. You think so or am I wrong? PS: I have talked about this concept because I have to develop a project of software engineering. So this is not only to implement a workable solution but justify what you are doing in the documentation of the project, adopting the "best" solution. Thanks for your patience
[eluser]Caio Russo[/eluser]
Hi Giga, Check this page OOP with PHP that may answer your questions. Cheers Caio
[eluser]danmontgomery[/eluser]
This is a logical fallacy... A model is a class, there's no reason you can't accomplish what you have in your second example with a model, simply by making the class a model. You have indeed added a layer of abstraction, but you've also changed the logic of the code, which is the real benefit of the abstracted approach, not that it's done outside of the model.
[eluser]Caio Russo[/eluser]
hi Giga, Again it's 2 different things. MVC is an architectural pattern. Doesn't means that it "must" be or use OOp at all. It could simply be developed with a procedural programing language and still use MVC patterns. cheers Caio |
Welcome Guest, Not a member yet? Register Sign In |