He means you can't encapsulate business logic within the entities
you're iterating over. I.e., a query row is completely "dumb" - the
worst case scenario for an anemic domain model.
As a very simple example, if you have a recordset with id, name, and
dateOfBirth columns, you have to do age calculations in every
view/controller that needs an age value. But if you have an array of
objects, you can just expose a 'getAge' method that encapsulates the
logic, thereby reducing the duplication all over your app.
<cfloop query="getPeople">
...
<td>#dateDiff('yyyy', getPeople.dateOfBirth, now())#</td>
...
</cfloop>
vs.
<cfloop array="#people#" index="person">
...
<td>#person.getAge()#</td>
...
</cfloop>
I believe the encapsulation you were referring to (in the code
producing the recordset) is the implementation of PersonDao's
findPeople(...) method, right? No way to tell if that's SQL backed,
SOAP backed, etc., which is good, but it's the less interesting
encapsulation, because it's not business logic, it's just data access
"stuff". The encapsulation of business logic is in your domain model,
not your data access code.
cheers,
barneyb
On Fri, Jan 7, 2011 at 12:25 PM, Steve Bryant
<[email protected]> wrote:
> Peter,
>
> Would you mind expanding on that a bit? How does the use of a query prevent
> encapsulation? I realize that the data is read-only, but that doesn't mean
> that the code that produced it wasn't well-encapsulated.
>
> Or am I missing something fundamental?
>
> Thanks,
>
> Steve
>
> On 1/7/2011 1:31 PM, Peter Bell wrote:
>>
>> Well, I certainly wouldn't use a query object. I'm not a fan as there is
>> no possibility of encapsulation of any possibly business logic.
>
> --
> You received this message because you are subscribed to the Google Groups
> "CFCDev" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/cfcdev?hl=en.
>
>
--
Barney Boisvert
[email protected]
http://www.barneyb.com/
--
You received this message because you are subscribed to the Google Groups
"CFCDev" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/cfcdev?hl=en.