Welcome Guest, Not a member yet? Register   Sign In
designing classes/models
#1

[eluser]Rob Steele[/eluser]
alright, just trying to take a vote. I have an application that i'm designing to keep track of concert events. it has tables for the content, audio, video, sponsors per event, and a general event table which keeps the title, event date and time, event location. I've made the event model with getters and setters for the general event table. My question is, should I include the rest of the getters/setters for the audio, video and content in the same class, or create a different class for each one and access them through the event class: ie.
i could have
ALL GETTER/SETTERS in the event_model class and have it be a huge file
or
Event_model class accesses the video, content, audio classes and make it slightly more organized.
i'm leaning towards the latter, but would that be the correct way for the code?
#2

[eluser]jedd[/eluser]
Hmm .. a tricky question with lots of different answers.

Wanna post your schema?

I tend to go for models that reflect groups of tables, usually this means one primary table with a couple of ancillary tables that support it, data-wise. I don't think I have any models that talk to just one table in my current project. A lot also depends on what kind of complexity you're expecting at the controller level - what types and groupings of data you want to be able to pull into your controller to do whatever it is you're going to do with them.
#3

[eluser]kgill[/eluser]
I'll give you my standard model spiel here, models are supposed to be the digital representations of the object that you are interacting with. So, you have to ask yourself the question: what am I supposed to be working with here, in your case it's an event. So your model should have methods for all the properties that an event would have. Where it gets tricky is overlapping areas, events have audiences and while an audience is clearly its own entity separate from the event, attendance is a property of an event and would be a query based on how many audience members there are. Me, I'd stick that in the event model but I'm sure there are others who would say it would go in the audience model. It's all about deciding what makes the most sense to you when you're dealing with stuff, "if I wanted to see X I'd expect to find it in Y" kind of thing.
#4

[eluser]jwindhorst[/eluser]
I've found that bridging the gap with Libraries in CI helps out quite a bit. Sure an Event is an object, but in my world models are data access bridges. I like having portable Objects that I can pass around (Libraries) using the new constructor, but I use the models to populate the libraries with data.

Maybe it's crazy but it's working and I find that not only do I get the advantages of having the data access code seperate, I also get to enjoy the simplicity of portable objects that have getters and setters.




Theme © iAndrew 2016 - Forum software by © MyBB