in reply to Abusing Exporter for Conditional Inheritance

I dislike abusing Exporter (really the import method) and mix-ins. Your problem sounds pretty easy to solve with a class factory. Check out some of the class factory modules on CPAN.
  • Comment on Re: Abusing Exporter for Conditional Inheritance

Replies are listed 'Best First'.
Re^2: Abusing Exporter for Conditional Inheritance
by mojotoad (Monsignor) on Mar 17, 2005 at 18:21 UTC
    I'm not so sure that class factories are the right approach in this case. From the Class::Factory docs:
    Factory classes are used when you have different implementations for the same set of tasks but may not know in advance what implementations you will be using.
    In my case it's the reverse: I have the same implementation for a different set of tasks.

    Thanks for your thoughts,
    Matt

      A class factory can be a way to hand back the same class with different initialization parameters. The point is to hide the initialization stuff behind a simple call.

      In the case you describe here, if the code calling this thing knows which one it wants, I think you should actually either just make the two classes and call them or make a class that has some kind of method like "set_collection_color()" for switching the behavior.

        Yet the only difference between the two cases is the contents of @ISA. And localizing @ISA is probably not a good idea. Last night tye pointed out that it's probably not thread safe, and look here for an explanation from gbarr as to why it's not efficient.

        Matt