On 5/25/05, Ben Rogers <[EMAIL PROTECTED]> wrote:
> > I would start off with an array of strings, which is the simplest
> > thing that could possibly work (or the simpler of the two options, at
> > least).
> 
> Though I generally agree with the idea of going with the "simplest thing
> that could possibly work", in this case, I'm not so sure storing the line
> item in a string works.
Actually, I meant "structs" not "strings." But if I were writing this
code, I probably would actually start off with strings. I could
probably get a couple of methods in Order knocked out by representing
each item as a string (the name or ID of the item and nothing else).
There's no sense creating a structure that contains all the
information I'll ever need about an item if it doesn't help me write
the next line of code.



> > You can always switch from structures to objects as you design
> > grows, especially since such changes should be insulated by your Order
> > object.
> 
> Order items will usually need to be displayed at various points in the user
> interface (checkout, admin interface, e-mail notifications, etc.). Assuming
> your display logic is not in your Order component, there's going to be code
> sprinkled throughout the app that needs to know how to enumerate the order
> items. If you use a data structure, then that code may also need to know how
> to calculate price.

If I have a checkout form that needs to display the name, quantity,
and price of each order, and the total, I'll probably have code like
this.

<cfset items = order.itemsQuery()>
<table>
<cfloop query="#items#">
<tr><td>#items.name#</td><td>#items.quantity#</td><td>#items.price#</td></tr>
</cfloop>
</table>
Total: #order.totalPrice()#

Does this mean that the items are stored internally as a query? No. It
just means that Order can produce a query. The display code doesn't
know how Order keeps track of its items. It doesn't know if there's
such a thing as an OrderItem object. It doesn't have to worry about
calculating the price.

Patrick

-- 
Patrick McElhaney
704.560.9117
http://pmcelhaney.weblogs.us


----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to 
[email protected] with the words 'unsubscribe cfcdev' as the subject of the 
email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting 
(www.cfxhosting.com).

CFCDev is supported by New Atlanta, makers of BlueDragon
http://www.newatlanta.com/products/bluedragon/index.cfm

An archive of the CFCDev list is available at 
www.mail-archive.com/[email protected]


Reply via email to