Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Nice introduction. I would like to offer a few comments.

One concept that you haven't touched and should deserve some explanation is Encapsulation, which in Perl has a few peculiar aspects.

Encapsulation is restricting data into an object container, with the purpose of protecting data against accidental manipulation and reducing the program complexity. One basic idea of OOP is to allow (or at least to recommend) data access through class methods only.

Perl encourages encapsulation "by good manners", as Damian Conway puts it, even though it allows stronger encapsulation through some tricks.

Also, Polymorphism should be explained a bit more. Perl allows polymorphism with and without inheritance. For example, you can do something like the following even with a non-OOP language. (Actually this is what I used to do - using C - in the late 1980s, when I learned OOP but C++ compilers weren't easy to get.)

#!/usr/bin/perl -w use strict; # polymorphism without inheritance my @objects = ( { name => 'sheep', speak => sub { print "baaah"; } }, { name => 'dog', speak => sub {print "woof";} }, { name => 'mouse', speak => sub {print "squeak (almost silently)" ;} }, { name => 'fish', speak => sub { print ".oO()" } } ); for (@objects) { print "a $_->{name} goes "; &{$_->{speak}}; print "\n" } __END__ a sheep goes baaah a dog goes woof a mouse goes squeak (almost silently) a fish goes .oO()

Polymorphism through inheritance is what is more commonly accepted as part of the OOP paradigm and it is the basis for object reuse. (At least in theory. Things in the real world could take different shapes).

 _  _ _  _  
(_|| | |(_|><
 _|   

In reply to Re: Object Terminology by gmax
in thread Object Terminology by stvn

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



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (5)
As of 2024-04-25 09:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found