Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

TheNomad (7014)

  (email not shown publicly)

Journal of TheNomad (7014)

Tuesday June 20, 2006
08:20 AM

Factories and Interfaces

[ #29976 ]

Recently, needing to implement a factory pattern, I started using Class::Factory. It is a nice, easy-to-use base class for factory classes.

But what of the objects produced by my new, nice and shiny factory class, what are they like?

This is important because, if I am going to use a factory, then I need to know that objects produced by it respond to methods in a predictable way. They need the same, or almost the same, interface.

But of course, it's my factory class, and they are my objects, so I will write them all so that they conform to the interface.

The question is, is that enough? Should the factory classes check that any classes registered with them conform to the required interface?

And if I think I need this, should I do it with Class::Roles?

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • I would suggest either using Class::Trait, Perl6::Roles or Moose (more specifically Moose::Role). Both Class::Role and Class::Roles are fairly old, and not very robust. But to be honest,.. Roles might actually be overkill for what you are doing.

    But if you just want to define an interface, and not any implementation, you could use Class::Interfaces []. It makes it very easy to make a Java style interface without needing to make a bunch of .pm files.

    - Stevan