The specific itch you mentioned was having to write constructors for each of your objects. Could that have been solved via inheritence?
In most of the OO projects I've worked on, we create a Base class that has an inheritable constructor that most or all of the objects inherit from.
In that example, MyObject doesn't need it's on explicit constructor, as it will inherit the one from Base.package Base; use strict; use warnings; our @ISA = qw(); sub new { my $this = shift; my $class = ref($this) || $this; my $self = {}; bless $self, $class; $self->init(@_); return $self; } # default init, does nothing... sub init {1;} # get/set a scalar member variable sub _gss { @_ > 2 ? $_[0]->{$_[1]} = $_[2] : $_[0]->{$_[1]}; } sub throw { my $self = shift; my($p,$f,$l) = caller(); die "Exception at: ",$p,"->$f($l)\n ",join('',@_); } 1; ######################################## package MyObject; use strict; use warnings; our @ISA = qw(Base); sub init { my($self) = @_; $self->someSetting('default value'); return 1; } sub someSetting {shift->_gss('_myObject__someSetting',@_);} sub someAction { my($self) = @_; print "setting: ", $self->someSetting(), "\n"; } 1; ######################################## package main; use strict; use warnings; my $obj = MyObject->new(); $obj->someAction(); $obj->someSetting('new setting'); $obj->someAction(); exit 0;
Is this applicable to your project, or am I missing the point?
Best regards,
Kyle
In reply to Re: OO 2 death?
by mortis
in thread OO 2 death?
by Cestus
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |