Seriously, I wonder if my parsing classes should be sub classes of a parent as they all have the same attributes (nearly) and only have the one method? So it would seem so but I'm not sure what benefit that would give me?
Also am I complicating things by returning objects of a different class? I think that my severity attribute is
only there so I don't have to call ref $obj in the calling
code.
As an aside I'm reading http://designpatternsinruby.com/ and since Ruby is Perl Lite I find it a readable and informative. Anyone know of a decent Perl design patterns reference?
package MailReader; BEGIN { push @INC, "U:\Perl"; } use Moose; use Harmless; use Critical; use UnSeen; has 'severity' => ( is => 'rw', isa => 'Str', default => 'unknown' ); has 'mailbody' => ( is => 'rw', isa => 'Str' ); sub parse_body { my $self = shift; # Look for Segmentation faults my $cm = Critical->new(data => $self->mailbody()); $cm->analysis(); if ($cm->is_critical) { $self->severity('critical'); return $cm; } # harmless my $hl = Harmless->new(data => $self->mailbody()); $hl->analysis(); if ($hl->is_harmless) { $self->severity('harmless'); return $hl; } # Still here then not seen this before my $us = UnSeen->new(data => $self->mailbody()); $us->analysis(); $self->severity('unknown'); return $us; } __PACKAGE__->meta->make_immutable; 1;
In reply to OO Design question. by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |