Why are functions inherited in only one direction when CFCs extend each other?

148 Views Asked by At

I have the following two CFCs:

component extends="Controller" displayName="foo" {
    public void function minifoo() {
    }
}

component extends="Foo" displayName="bar" {
    public void function minibar() {
    }
}

I know that any functions present in Foo.cfc will be available to Bar.cfc. But it seems that the reverse is not true. Can I make functions in Bar.cfc also available to Foo.cfc? Or does inheritance only work one way?

2

There are 2 best solutions below

0
On BEST ANSWER

no, inheritance does not work that way.

Try Dependancy Injection, basically...

f = new Foo();
b = new Bar();
f.setBar(b);
b.setFoo(f);

And framework like ColdSpring or Lightwire or Wirebox can help you with that if you need.

Then they can talk to each other, but you should think HARD if that's really what you want. Maybe you would like to design them differently.

0
On

Inheritance only works in one direction as the name implies. Its a little difficult for the father to inherit the son. ;)

It you have some common functions that you want to be widely available you probably need to look at some form of helper or dependancy injection.

If its not common but specific to parent & child CFC then you perhaps need to look at your application structure, the relationship between these two CFCs and where the functionality actually lives.