1 Reply Latest reply on Apr 2, 2008 10:19 AM by Newsgroup_User

    Nesting Objects

    josheby Level 1
      I am looking for advice on how to nest objected created from cfcs...

      The place I have seen this sdone is in the fusebox framwork in the following:

      What I would like to do is create an object called called users from a users.cfc with methods such as listUsers() and findUser(userID)...

      Ex. #users.findUser(34)#

      Then from there I want to next another object (object might not be the correct term) or set of functions that deal with the user specified such as getName() and getEmail()...

      Ex. #users.findUser(34).getName()#
      Ex. #users.findUser(34).getEmail()#

      Can someone explain to me how this can be done? Thanks!
        • 1. Re: Nesting Objects
          Level 7
          jeby wrote:

          > Can someone explain to me how this can be done? Thanks!

          How this is done depends largely on how the objects are related to each
          other. I.E. Does one object extend (inherit) the other object creating
          an is-a or parent child relationship. Or does one object contain an
          instance of the other as a property|variable (composite) creting an
          has-a relationship.

          I'm doing some web service with complex object testing and I have just
          written this simple testing code. See if it makes some sense to you.

          <cfproperty name="foo" type="string">
          <cfproperty name="bar" type="string">

          this.foo = "George";
          variables.bar = "Gracie";

          <cffunction name="getBar" access="remote" returntype="string">
          <cfreturn variables.bar>

          <cfproperty name="anObj" type="basic">

          variables.anObj = createObject("component","basic");

          <cffunction name="getObj" access="remote" returntype="basic">
          <cfreturn variables.anObj>

          complexComp = createObject("component","complex");

          <cfdump var="#basicComp#" expand="no">

          <dd><cfdump var="#complexComp.getObj()#"></dd>