Skip to main content
Participant
July 1, 2008
Question

OO-design

  • July 1, 2008
  • 3 replies
  • 387 views
I am developing with an OO-design in mind and I have most of my code written. I have a directory in the webroot
called 'com'.
I want to use/create an object/component in another manager-like object in the same directory. So I have a product component (com/product.cfc) which is just a Bean-like component. I also have a productmanager component (com/productmanager.cfc) which has methods manage products and specifically one to return a product object. What should that method's returntype be? And when i create an instance of a product inside some productmanager method do i call createobject with "com.product" or just "product"?

<cffunction name="getProduct" returntype="com.product" ... >

OR

<cffunction name="getProduct" returntype="product" ... >

I'm guess I'm just missing the basics about when to specify the path and when not to. I create an instance of the productmanager in the application scope and reference that in my display pages. Any body have any advice on best practices here?
This topic has been closed for replies.

3 replies

BKBK
Community Expert
Community Expert
July 6, 2008
Topic Title OO-design
Topic Summary should i specify the whole path or just the component name?


Take as much advice as you can from Vurcease and Adam, but rest assured that what you seek has little or nothing to do with objected-oriented design.





Inspiring
July 1, 2008
> the same directory. So I have a product component (com/product.cfc) which is

You might want to extend that dir structure a bit to include your company
name and your application name:

com.acme.eStore.Product


> to return a product object. What should that method's returntype be? And

com.product

Either will work, but I think the full dotted path is less ambiguous.


> when i create an instance of a product inside some productmanager method do i
> call createobject with "com.product" or just "product"?

Again, I'd use the full path.


> I'm guess I'm just missing the basics about when to specify the path and when
> not to.

I'm not sure there's a "right" way, per se, but deciding on an approach and
sticking with it uniformly is perhaps a good way to do things.


> I create an instance of the productmanager in the application scope
> and reference that in my display pages. Any body have any advice on best
> practices here?

That's a pretty vague question...

--
Adam
Participating Frequently
July 1, 2008
I'm fairly confident that if you don't specify the full path, and the CF server is configured to validate component paths (this is an option in 8) an exception will be thrown.

I've made a habit of specifying full paths for these reasons, as well as to avoid duplicate named component confusion amongst the team.

To further accommodate this setup, we use a central API, which is mapped for all the applications and sites. So we instantiate things such as API.com.mydomain.service. The full path for that component is always available on all sites and environments.