TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Old School Object Oriented Perl

8 pointsby charliesomeabout 12 years ago

1 comment

ycamelabout 12 years ago
Shape is a retangle. Shape::Circle inherits from the Shape. Is it reasonable?<p>Shape class must have color attibute only. Shape::Retangle and Shape::Circle should inherit from the Shape.<p>And<p>...<p>package Shape::Retangle;<p>use parent 'Shape';<p>sub new {<p><pre><code> my ($class, $args) = @_; my $self = $class-&#62;SUPER::new( { color =&#62; $args-&#62;{color} || 'black' } ); $self-&#62;{length} = $args-&#62;{length} || 1; $self-&#62;{width} = $args-&#62;{width} || 1; return bless $self, $class; </code></pre> }<p>...<p>package Shape::Circle;<p>use parent 'Shape';<p>sub new {<p><pre><code> my ($class, $args) = @_; my $self = $class-&#62;SUPER::new( {color =&#62; $args-&#62;{color} || 'black' } ); $self-&#62;{diameter} = $args-&#62;{diameter} || 1; return bless $self, $class; </code></pre> }<p>...