in reply to Class or Object composition ??
The example you give is not appropriate for inheritence, since a Server is not a SendRecv, and instead it is more like a Server does SendRecv. This is the role model of class composition, sometimes called allomorphism (at least thats what chromatic always calls it).
You might want to take a look at Moose, and in particular the (Perl 6 style) role features. Alternately there is Class::Trait or Perl6::Roles as well (there are some other "Role" modules on CPAN, but they are either incomplete or incorrect).
As for composing the class vs. composing the object, I think this is probably something which should be dictated by the requirements. If you really need to have multiple instances all of which can do different types of servering, then use object composition. But the minute you might have several instances of one type of server, you might want to consider going with class compostion, and making custom subclasses for your needs.
As for how you can do the object composition (if you choose that route), the Class::Trait module has a stable "runtime trait composition" feature which Ovid added several months ago. Perl6::Roles has that feature as well (and in fact was the primary reason dragonchild wrote that module). Moose only recently added this feature, and it is completely undocumented (aside from a test script in the t/ directory), so unless you really want Moose's other features, I would not recommend it yet.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Class or Object composition ??
by aufflick (Deacon) on Oct 04, 2006 at 08:12 UTC | |
|
Re^2: Class or Object composition ??
by rootcho (Pilgrim) on Oct 04, 2006 at 22:49 UTC | |
by stvn (Monsignor) on Oct 05, 2006 at 00:05 UTC |