Multiple Object Instantiation

Posted by Ricky Baby on Programmers See other posts from Programmers or by Ricky Baby
Published on 2013-07-03T11:03:19Z Indexed on 2013/07/03 11:16 UTC
Read the original article Hit count: 343

Filed under:
|
|

I am trying to get my head around object oriented programming as it pertains to web development (more specifically PHP).

I understand inheritance and abstraction etc, and know all the "buzz-words" like encapsulation and single purpose and why I should be doing all this.

But my knowledge is falling short with actually creating objects that relate to the data I have in my database, creating a single object that a representative of a single entity makes sense, but what are the best practises when creating 100, 1,000 or 10,000 objects of the same type.

for instance, when trying to display a list of the items, ideally I would like to be consistent with the objects I use, but where exactly should I run the query/get the data to populate the object(s) as running 10,000 queries seems wasteful.

As an example, say I have a database of cats, and I want a list of all black cats, do I need to set up a FactoryObject which grabs the data needed for each cat from my database, then passes that data into each individual CatObject and returns the results in a array/object - or should I pass each CatObject it's identifier and let it populate itself in a separate query.

© Programmers or respective owner

Related posts about php

Related posts about object-oriented