My personal experience has been that when I code using OO techniques, I actualy write less (usualy significantly less) code.

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.

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;
In that example, MyObject doesn't need it's on explicit constructor, as it will inherit the one from Base.

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.