2 Replies Latest reply on Oct 20, 2006 5:18 AM by digitalgm

    Extend Java object w/ CFC?

    digitalgm
      I have searched around and have not found a definitive answer.

      In my situation I have a ton of Java classes that Id like to extend using CFC's. My question is can CF inheirit from a Java class just like it does a CFC?

      Consider this situation. You have a java component called "Category" which is written in java. This class has a method called "getName()" Now, you'd like to extend this and have your CF component inheirit all of the java methods and properties. Is the following possible?

      <cfcomponent name="componentextender" extends "com.javastuff.Category">

      </cfcomponent>

      cfobject = createObject("component","com.cfstuff.CategoryExtender")
      cfobject.getName() **** REMEMBER, getName is part of the Java class
        • 1. Re: Extend Java object w/ CFC?
          Level 7
          > In my situation I have a ton of Java classes that Id like to extend using
          > CFC's. My question is can CF inheirit from a Java class just like it does a
          > CFC?

          No.

          Just because a CFC compiles down to a Java class, doesn't mean it *is* a
          Java class. A CFC can extend another CFC. That's it.

          I imagine the closest thing you could do for your requirement is to
          re-implement the entire Java class in CF. Not so nice.

          PS: "name" is not an attribute of <cfcomponent>, and can adversely conflict
          with CF's internal operations when building metadata,leading to
          "unexpected" results. Probably best to avoid that one. I don't think it
          serves any purpose adding a name attribute anyhow, as the CFCs metadata
          includes its (correct) name automatically anyhow.

          --
          Adam
          • 2. Re: Extend Java object w/ CFC?
            digitalgm Level 1
            Adam, thanks for your reply. I had a hunch that it wasnt possible but wasnt entirely sure. Certainly would be a very nice feature to have implemented in CF though.

            In any case, that only leaves me one more option and thats creating a facade for both classes. Basically what I have done is created a CFC called cfc.facades.Category which is what I always implement instead of the java one. In the constructor I init 2 classes, the first is the java class and the second is another class I have made in CF called rzCategory.

            Please check out this thread for exactly how I am doing this : Thread

            Thanks
            Adam R