Richard,

If your project.add() method is adding a test - yeah, that sounds right.
Although I'd call it addTest().  And then internally the project would
delegate to a DAO to do the add.  So project.addTest() would call
TestDAO.add().

project.addTest() would take a parameter of type Test - i.e. you'd first
create a Test object, then pass it to addTest().  It's also often convient
to have a project.createTest(), which takes as parameters all the basic
properties required to create a new Test object and returns the new Test.
So you might say:
project.addTest(project.createTest(param1, param2));

OK, some details:

1.
In this example TestDAO is acting as a collection object, albeit
specifically a database-backed collection.  You can imagine you could do a
similar thing with an in-memory collection like a struct.  The natural
progression is to make in-memory collections act just like database-backed
collections so you can switch between the two, but in practice there are
some ColdFusion-specific issues with doing this.

2.
project.createTest() is a "factory method", which makes Project a "factory"
for Tests.  This makes sense if all tests have to live inside projects.  If
tests can stand alone, you need a different factory, maybe a dedicated
factory object that encapsulates the creation logic for your top-level
domain objects.  You'll probably need this for creating Project instances
anyway.  If this same top-level factory also has a DAO that lets it
manipulate existing Projects, it's starting to look like a "service" object.

3.
Where do all these DAOs come from?  You can have your top-level factory know
how to create them, and then the creation logic for your domain objects
would make sure that each domain object has it's DAO.  So you'd have
something like (in pseudocode):

component myAppFactory:

        method createTestDAO()
                return new TestDAO(DSN = "my_datasource")

        method createProject (name_param, description_param)
                return new Project(
                        name = name_param,
                        description = description_param,
                        dao = createTestDAO()
                )

Hope this helps

Jaime Metcher

> -----Original Message-----
> From: Richard White [mailto:[EMAIL PROTECTED]
> Sent: Monday, 26 May 2008 8:58 PM
> To: CF-Talk
> Subject: Re: cfcs good practise
>
>
> Thanks for your reply Jaime
>
> so am i correct in understanding that i should have a project
> class with methods such as add, remove, find etc... and
> properties such as name etc... and a test class with much the
> same methods and attributes, and a materials class, again with
> much the same attributes
>
> then in order to create a collection of the objects so i can
> manipulate and query the collections i should use dao (and gateways)
>
> is this what you mean?
>
> apologies, i understand the basic principles of OO but this is
> the first time i am putting it into practise!!!
>
> thanks again
>
> >Start with just a pure object model.  Later you can pick it
> apart and patch
> >up the bits that don't map real well to CF.
> >
> >So, Projects have Tests.  To me, that says that you have a Project class
> >with an instance variable Tests.  Tests is a collection that has methods
> >like add, remove, find etc.  The elements of the Tests collection are
> >instances of the Test class.
> >
> >Instances of Test *may* have an instance variable Project, which
> points to
> >the parent project - or may not.  The benefit is flexibility in
> navigating
> >between objects, the downside is another reference you have to manage.  I
> >tend to add these "back pointers" when and if I need them.
> >
> >Ditto for the tests->materials relationship.
> >
> >OK, so how do you do this in CF?  The biggest mismatches are:
> >1) no built-in collection classes
> >2) the need to avoid instantiating lots of objects
> >
> >The usual workaround is to build the "collection object" as a (or with a)
> >DAO (see also Gateway) and return a CF query from any method that might
> >return more than one item.  Within the DAO you can go crazy with
> naked SQL,
> >or abstract the SQL with a framework, or both.
> >
> >Just keeping this brief for the moment, but ask for more detail and you
> >shall receive.
> >
> >Jaime Metcher
> >
> >>
>
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to 
date
Get the Free Trial
http://ad.doubleclick.net/clk;192386516;25150098;k

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:306045
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4

Reply via email to