On the contrary, to me, Acme::Playmate is a very good example of a simple
object, and it encapsulates at least those three attributes you had in your
sample code. Most importantly, the class does abstract an entity the author
perceives.
I'm with Ovid on this one. The example under discussion is just a plain
old data structure dressed up in a little OO clothing. If you remove the
bless line from the constructor, you get back a plain ordinary hash
reference that has *all* of the functionality of the so-called object. It
is useless OO, as is the following:
#!/usr/bin/perl -w
use strict;
sub whatever {
bless {name => 'pg', forum => 'perlmonks'}, 'NonObject';
}
my $obj = whatever();
print $obj->{name},"\n";
print $obj->{forum},"\n";
1.Everything in the real world is an object (class is the collective abstraction of object).
Everything in the real world is *not* an object, and, conversely, a good
many of the objects we create in our programs are 'objectifications' of
process (not that that is a bad thing).
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|