Welcome Guest, Not a member yet? Register   Sign In
OOP Design
#1

[eluser]waterloomatt[/eluser]
Hi,

How would this design (see attachment) be implemented in CI? It was an old school project that was implemented in JSP. As I understand it, Models are essentially Data Access Layer (DALs). Therefore, my XXYYSurveyModel wouldn't be the business object that is passed around to the view; right? So, in which folder do my business objects (XXYYSuvery, XXYYQuestion etc) get stored; the Library folder?

Most of the forum posts that I've been reading don't seem to implement OOP techniques such as passing objects around - from the Model to Controller to the View. Instead, they pass arrays of info. In my opinion, passing an object to the view is cleaner since all I need to update is the view if I want to include other information. I.e. XXYYSurvey->GetTitle();

Or am I trying to fit a square into a hole here?

Thanks!
#2

[eluser]jedd[/eluser]
[quote author="waterloomatt" date="1268497228"]

Or am I trying to fit a square into a hole here?
[/quote]

Almost definitely Smile

This [url="/forums/viewthread/108763/"]post of mine[/url] from aeons ago might be interesting (but perhaps not).

The subject does come up semi-regularly, but not as often as I'd have expected it to.

Quote:As I understand it, Models are essentially Data Access Layer (DALs). Therefore, my XXYYSurveyModel wouldn't be the business object that is passed around to the view; right? So, in which folder do my business objects (XXYYSuvery, XXYYQuestion etc) get stored; the Library folder?

Yeah - the problem is that objects aren't the same thing in PHP as they are in .. well, almost anything else. And CI's re-interpretation and/or the way they've done MVC - means that it probably is square peg stuff.

Quote:In my opinion, passing an object to the view is cleaner since all I need to update is the view if I want to include other information. I.e. XXYYSurvey->GetTitle();

I'm not a huge advocate of OOP - plus I don't really have much training or experience with the paradigm - but your example here works just as well for passing an array over (you just grab $XXYYSurvey['gettitle'] Wink. Sure, a bit contrived, and you're obviously intending to have views generating calls into your model (arguably not the cleanest approach, but most of the gurus around here seem to think it's not a mortal sin).
#3

[eluser]waterloomatt[/eluser]
Hi jedd,

Thanks for the reply. Ok - so my Model XXYYSurveyModel would have the properties/attibutes (title, active etc) and the methods (CRUD) would manipulate those fields and return them if needed. So how do you handle multiplicity, polymorphism etc or are those features useless in CI?

Cheers.
#4

[eluser]jedd[/eluser]
I was really hoping an OO-guru would have popped in with some advice by now Smile

[quote author="waterloomatt" date="1268503685"]
Ok - so my Model XXYYSurveyModel would have the properties/attibutes (title, active etc) and the methods (CRUD) would manipulate those fields and return them if needed.
[/quote]

Yes, this is pretty much How We Do it. My post (that I linked above) was asking why we don't have many instances of each model - the conclusion (not necessarily from that thread) is that we don't treat models as objects in the full sense of OO.

Whether or not you can treat them as models in the OO sense .. is not something I can usefully answer - sorry.

Quote:So how do you handle multiplicity, polymorphism etc or are those features useless in CI?

Short pithy response - I don't. And I think others tend to (as a rule) not do, either.

As I say, hopefully some OO experts will have something more useful for you here. Looking through the forums might yield up some good insights, but I haven't seen any in the past 18 months that really stuck in my head (or rather my posts-to-take-note-of file). Perhaps checking out some of the example code and tutorials (see the wiki for links) though I think most of them tend to describe the orthodox approach, rather than explore the finer points of OOP.
#5

[eluser]icomefromthenet[/eluser]
I have in the past created seperate business objects to use along side the model, I then just include_once the file in the model's header, so when the model is loaded so is the business object. I just pass this object to all the methods in the model, you can then add some helper methods to merge from a post array, validation , post-process etc as static methods or a baseclass.

I just use the following folder structure

models
---- baseobjects
---- interfaces
---- collections
---- file.php
---- file2.php

Using business object gives you all the advantages of PHP's OOP support.




Theme © iAndrew 2016 - Forum software by © MyBB