I'd like peoples opinion about the concept on Data Modeling Vs SQL (OOP Vs Select Statement) on the following matter: When studying MVC and OOP concepts, it's easy to see a natural form of things like in the follow:
<php? | <% | <#
Class Country{
_name:String;
_language:String;
}
Class Estate{
_name:String;
_country:Country;
}
?> | % | #>
The point that I'm trying to get is a simple parent-child relation. Now, as I've seen working on ExtJS + PHP and JSF 2.0 (Java using Converter), it's quite common to see a DAO (Data Access Object) being defined sort of like this:
Abstract class CountryDAO{
public function getCountry();//This function returns an ArrayList.
public function getCountryById(countryId:Integer);//This function returns a Country Object;
...
}
Class EstateDAO{
public function getEstate(){
$sql = "SELECT * FROM tbl_estate";
//[your favorite way to comunicate with the database here]
//Declare an ArrayList or something to store the result:
$arrayList;
while($result = $ResultSet.next()){
$obj = new Estate();
$obj->name = $result['name'];
$obj->Country = new CountryDAO().getCountryById($result['country_id']);
$arrayList->addItem($obj);
}
}
}
Sorry for mixing language syntaxes, I'm trying not to get too attached to language, just the concept
Now to finalize my thoughts: That is the right concept, according to theory. Personally, I don't think it's right to disagree with it since it's the logic of the thing. But as in practice, the real world don't ever shine as you want, what I see from that:
If I have 10 Estates, I'll have 11 SQL Statements being executed on a Hard Disk level (which according to Operational System's theory, it's the slowest of all sorts of stored memory).
If I have 100 Estates, I'll have 101 SQL Statements being executed.
If I have n Estates, I'll have n+1 SQL Statements being executed.
My final point: I think that can be a real pain if you're modeling a data entity that might have thousands of records. Because of that line of thought, I refused to use this kind of design logic while working with Flex + PHP. But now that I'm trying to build an application that will have both Flex and ExtJS as viewers and PHP as Server-Side, I just wanna be sure that I'm not choosing the hardest path for insignificant reason. Is it safer not to respect this MVC/OOP logic? Am I exaggerating? What do you think about SQL Vs Data Model on OOP?
Thanks.