Posted by Jim on 04/20/07 12:39
Hi guys,
I have an object which represents an "item" in a CMS "component" where
an "item" in the most basic form just a field, and a "component" is
effectively a table.
"item" objects can be created and then added to "component" objects to
build up the component definition.
My dilemma comes in deciding how to read/write data to the "item"
object.
I figure I can either:
1. Use getters and setters (hate the idea of them though)
2. Use __get and __set which I prefer the idea of from a user
interface point of view though I understand they take no notice of
member visibility.
3. Pass all the required parameters to one function and do all the
validation there - inflexible, unintuitive and more work in the long
run in my opinion.
I'm leaning towards the __get and __set route so I could do:
$item = new Item('user');
// could throw exceptions in the functions that do validation
$item->required = true;
$item->label = 'User';
$item->description = 'A description of the item';
// all validation on the item is done so just add it
$component->add_item($item);
Does this make sense? I'm interested in hearing what other methods
people would choose and why.
Thanks for any input.
Jimmy.
Navigation:
[Reply to this message]
|