in reply to Convenient Constructors - a Moo question
This seems like an example of where subclasses and polymorphism actually make sense.
use Attack::Heavy; use Attack::Lite; use Attack::Fast; my @attacks = ( Attack::Heavy->new, Attack::Lite->new, Attack::Fast->new, );
If you prefer, internally "Attack" could be a role that defines a common interface, and "Attack::Heavy", "Attack::Lite", and "Attack::Fast" could be composed with that role. Or inheritance could be used, whichever is your preference. Actually, inheritance is probably preferable here, because there are probably times where you would just instantiate an Attack object without using the defaults provided by ::Heavy, ::Lite, and ::Fast.
This is classic Perl-style object polymorphism; As long as an object can 'type', 'damage', and 'speed', it's sufficiently Attack like to be treated like an Attack object.
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Convenient Constructors - a Moo question
by blindluke (Hermit) on Dec 06, 2014 at 20:02 UTC | |
by davido (Cardinal) on Dec 07, 2014 at 05:09 UTC |