>Taco,
> 
>I had a quick look through this link you posted go ahead an buy the book
because it is all valid.
>
>This is very legal code
>
><cfcomponent>
>    <cfset this.Firstname = "" />
>    <cfset this.Lastname - "" />
></cfcomponent>
> 
>The above code means that the data can be referenced outside the cfc like
this
> 
><cfset ci = CreateObject("component","test") />
><cfset ci.Firstname = "testing me out" />
> 
>Or you could write extra code and have getters and setters methods to do
the above, just use what you think will be best for you. 
> 

Although putting data in the this scope is perfectly valid and will not
cause any errors, it generally isn't seen as a good idea. The main reason
being that you lose the ability to tightly control that data from within the
CFC, so breaking the encapsulation. That leads to increased overhead when
you try to maintain the code, because you can't just look at what's
happening inside the CFC before making changes. You have to also look at
where it is used and how it is used to make sure none of the data in the
this scope is being added, modified or removed by external code.



Normally you will want to at least have an init() method that takes one or
more arguments to initialize the component. That init method should return
the this scope so you can write code like this:

<cfset dataService =
createObject('component','dataService').init(application.dsn)>

Rather than having to do this:

<cfset dataService = createObject('component','dataService')>
<cfset dataService.init(application.dsn)>

The problem being that the second one isn't thread safe which could lead to
problems depending on what you are doing.

Beyond that, there aren't many hard and fast rules about how to do things
other than to try to:

Increase cohesion - A component should do one thing only and do it well.
Deciding what the one thing should be is the tricky part

AND

Decrease coupling - A component should not need to know anything about it's
environment, so all variables and other components should be passed into the
methods rather than having the component read data from external scopes such
as application, session, request, form, URL. If you do need to access these
scopes, you can create a fa�ade component that provides access to the scope,
but hides exactly what is going on, so you can switch from using URL to Form
variables and the only thing that has to change is the fa�ade.


HTH

Spike


---
You are currently subscribed to cfaussie as: [EMAIL PROTECTED]
To unsubscribe send a blank email to [EMAIL PROTECTED]
Aussie Macromedia Developers: http://lists.daemon.com.au/

Reply via email to