Possible Duplicate:
Classes. Whats the point?
I've read tons of tutorials, wrote many classes, used them, but I still can't figure out some OOP points.
I mean, I think I got the theory. It's a paradigm, a different way to think and solve a problem. I know all commom points: code reuse, encapsulation, better error handling, easier maintenance, inheritance, design by contract, better documentation, aggregation, composition, some design patterns...
That said, let's go to the real deal. Let's say I have the following:
- a database, and a class to access and query it.
- I have a table named person and another table named address
- Simple business rule: one person can have one or more address (home, work, delivery...), a simple one to many relationship
- I have a highlevel class for commom operations (CRUD). Each table has a class that is a extension from this one.
- Of course, each class (person and address) have their own methods: eg, getAddressByLocation or getPersonsByAge.
- Also there are a dozen views and a couple forms
All this is awesome and sure useful but... I can't stop thinking in the simplest case: listing some people. Yes because every row on the output table is made upon one class instance. I can't stop thinking on how much memory and cpu is used on not used resources.
Listing 50 people means creating 50 instances, full of resources like crud, filtering processing uploads, validating rules and so on when what I need is to run a query and just output results with a simple loop.
This confuses me a lot. And not just confuse, as I already saw some apps where runtime increases exponentialy with database when business rules are a little more complex.
I think, is the case to create new classes or plain scripts to just