4 Replies Latest reply on Nov 6, 2006 8:20 PM by RobGonda

    CFC Design Practices

    David R S
      I am attempting to determine what the best way to handle the following situation is and would like to get some input or general suggestions.

      I have created a Customer component and WorkOrder component . I have also created "collection" objects, Customers and WorkOrders, which have members that arrays which store objects of each.
      I am not sure the best way to set up the relationship between the two. I could have a member in each WorkOrder component that stores a Customer object or a WorkOrders collection object, which contains multiple WorkOrder objects the Customer object. Why is one way better than the other or should both be used? Business rule: A work order can not exist without a customer but a customer can exist without a work order.

      Any insights?
        • 1. Re: CFC Design Practices
          Dan Bracuk Level 5
          Your title says cfc but your narrative sounds like database design. For me, a cfc is nothing more than a way to create re-useable code. Anything beyond that is an unnecessary complication.
          • 2. Re: CFC Design Practices
            RobGonda
            David, depending how you create your objects, nothing prevents you from doing both.

            1.
            customer = getCustomerById(n);
            workOrderIterator = customer.getWordOrderIterator();
            do {
            workOrder = workOrderIterator.getNext();
            }
            while (workOrderIterator.hasNext());

            2.
            workOrder = getWorkOrderById(n);
            customer = workOrder.getCustomer();

            There are some good frameworks to help you with this. ColdSpring will allow you to wire your objects together thru dependency injection, and Reactor or Transfer can help you create your objects from your database.

            HTH


            Dan, a CFC is an object, not just a better-organized spaghetti code. ColdFusion is transitioning to be a nice Object Oriented Language so please try not to confuse people heading in the right direction.

            • 3. Re: CFC Design Practices
              David R S Level 1
              Thanks Rob. This is exactly where I was headed with this.
              On initial population from database data, I will want to make sure to have already created a WorkOrders collection reference within the customer object. This way, I can populate both the general WorkOrders collection and the specific Customer WorkOrders colelction with the same memory referenced object.

              I recognize that Coldfusion is not a stict OO language but by developing as closely to the OO paradigm, I will benefit by easily migrating into other OO languages. I must admit, I orginally developed CFC's to act more like UDF's until I learned true OO development. I have even separated all database code from my base objects. I am certain I will always have more to learn but I least I am using CFC's as objects.
              • 4. Re: CFC Design Practices
                RobGonda Level 1
                Mark Mandel presented his Transfer ORM this afternoon. I highly recommend you check out this Breeze Recording. He covers using an ORM for your CRUD needs, including setting up relations. Transfer can easily create your objects including your oneToMany and manyToOne relations.
                Basically Transfer takes care of DAO, so all you have to do is to create your service layer, and well, gateways if needed. Feel free to drop me an email if you need more details: rob[at]robgonda[dot]com.