in reply to Re: Re: OOP - Sharing class methods
in thread OOP - Sharing class methods
Here's a naïve implementation:
Nothing wrong with that, is there? Well... yes, because stuff is hardcoded, you may find that, when you come to subclass foo, things will break. A better approach is:package Foo; use UtilityClass; sub some_method { my $self = shift; $self->UtilityClass::some_method(@_); }
You could go further and add per object customization, by turning 'helper_class' into an instance method, allowing you to choose which utility class to use on an object by object basis rather than class by class...package Foo; use UtilityClass; sub helper_class { 'UtilityClass' }; sub some_method { goto &{ $_[0]->helper_class->can('some_method') }; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Re: OOP - Sharing class methods
by perrin (Chancellor) on Aug 15, 2002 at 17:45 UTC | |
by pdcawley (Hermit) on Aug 15, 2002 at 21:41 UTC | |
by perrin (Chancellor) on Aug 15, 2002 at 22:11 UTC | |
by pdcawley (Hermit) on Aug 16, 2002 at 09:38 UTC |