How can a collection class instantiate many objects with one database call?
Posted
by
Buttle Butkus
on Programmers
See other posts from Programmers
or by Buttle Butkus
Published on 2013-11-02T23:31:08Z
Indexed on
2013/11/03
4:11 UTC
Read the original article
Hit count: 260
object-oriented
|collections
I have a baseClass
where I do not want public setters. I have a load($id)
method that will retrieve the data for that object from the db.
I have been using static class methods like getBy($property,$values)
to return multiple class objects using a single database call. But some people say that static methods are not OOP.
So now I'm trying to create a baseClassCollection
that can do the same thing. But it can't, because it cannot access protected setters. I don't want everyone to be able to set the object's data. But it seems that it is an all-or-nothing proposition. I cannot give just the collection class access to the setters.
I've seen a solution using debug_backtrace()
but that seems inelegant. I'm moving toward just making the setters public.
Are there any other solutions? Or should I even be looking for other solutions?
© Programmers or respective owner