thanx again Mark. It's leading to a couple of more questions, I'm afraid...


>> Neither - you aren't calling the method on a CFC. You are trying to call
it on a 
struct.

you've confused me now. The only thing I've done different from usual is not
used an argument in invoking the component and the CFC not having
properties. Perhaps I'm getting confused with CFC interfaces seemimg to be
like structs themselves, not like real objects eg: COM (actually, they feel
more like VBScript classes than objects).


>       <cfproperty name="aProducts" type="array">
>       
>       <!--- contructor --->   
>       <cfscript>
>               //place to store my carts
>               this.aProducts = ArrayNew(1);
>       </cfscript>

Ummm... why the array? is this for an array of structures or a struct of
arrays? 


> <!--- application.cfm --->
> 
> <cfif NOT isDefined("session.cart")>
> <cfscript>
>       session.cart = CreateObject(type, "com.Cart");
> </cfscript>
> </cfif>

> - Hence all data is stored in the CFC - and is specific TO the CFC, and
nothing else (which gives lower coupling).

so the instance is stored in the session? How does session.cart get updated
with new cart contents within the CFC? and what would you do if cookies or a
db have to be used instead? you've made a good point about the loose
coupling but it's satisfying the other side (tight cohesion) that worries me
on this bit.

thanx
barry.b


-----Original Message-----
From: Mark M [mailto:[EMAIL PROTECTED]
Sent: Monday, 29 September 2003 12:18 PM
To: CFAussie Mailing List
Subject: [cfaussie] Re: CFC error: "Method selection Exception" (was:
Shopping carts: Arr ays Vs Structs)


> 1) so I'm calling the method wrong? or not invoking the component
> correctly?

Neither - you aren't calling the method on a CFC. You are trying to call it
on a 
struct. Hence the error.  Dump out the 'objCart' variable, and I think you
will find 
what I mean.

> 2) >> A shopping cart should only manage the shopping cart.  It
> shouldn't
> look at if it exists or not.
> 
> yes good point but I was trying to tie the storage of cart data
> totally into
> the CFC. IMHO only the CFC should care how the cart data is stored
> and not
> be dependant on other files. The CFC becomes the data store
> interface. If
> the chosen storage doesn't exist, create it.

That is fine - however I would have built it like this:


<!--- component cart --->
<cfcomponent displayname="Cart">
        
        <cfproperty name="aProducts" type="array">
        
        <!--- contructor --->   
        <cfscript>
                //place to store my carts
                this.aProducts = ArrayNew(1);
        </cfscript>
        
<cffunction name="AddToCart" access="public" output="false">
                <cfargument name="key" required="true" type="numeric">
                <cfargument name="value" required="true" type="numeric">
                <!---  add the item --->
                <cfscript>
                        StructInsert(this.aProducts, arguments.key, 
arguments.value);
                </cfscript>
</cffunction>
                
</cfcomponent>


<!--- application.cfm --->

<cfif NOT isDefined("session.cart")>
<cfscript>
        session.cart = CreateObject(type, "com.Cart");
</cfscript>
</cfif>

- Hence all data is stored in the CFC - and is specific TO the CFC, and
nothing 
else (which gives lower coupling).

HTH

Mark

---
You are currently subscribed to cfaussie as: [EMAIL PROTECTED]
To unsubscribe send a blank email to [EMAIL PROTECTED]

MX Downunder AsiaPac DevCon - http://mxdu.com/

Reply via email to