Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
Syntactic Confectionery Delight
 
PerlMonks  

Re: Class automators should be standard

by hardburn (Abbot)
on Jan 13, 2004 at 17:23 UTC ( [id://321127]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Class automators should be standard

No. While I'm not going to say using MethodMaker is always bad, it would encourage those new to OOP to design sloppy objects (such as accessors and mutators on every attribute). Further, it only teaches you one aspect of Perl OOP. There are already too many people who limit themselves to bless alone, and with MethodMaker, they wouldn't even learn that much.

If you happen to like MethodMaker, know how bless works already, and already understand why you should limit the use of accessors/mutators, then go ahead and use MethodMaker. I just don't want coders encouraged into bad practices too soon. There's quite enough of that as it is.

----
I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
-- Schemer

: () { :|:& };:

Note: All code is untested, unless otherwise stated

Replies are listed 'Best First'.
Re: Re: Class automators should be standard
by Arunbear (Prior) on Jan 14, 2004 at 04:30 UTC
    Hmm..., how does one create objects without bless?

      First, you have to recognize that the OO concept is much larger than most object systems can handle. bless just happens to be the most common object system in Perl, but we can implement the same concepts without using it.

      If you want no bless at all (not even hidden away by a module), there are a few ways to do it. You could simply have a hash that contains subroutine references along side its attributes, thus having a classless object.

      Perl's tied interface has many attributes of an object system, its interface being the standard Perl operators (I don't recall off the top of my head if it uses bless anywhere, though). It's actually a pretty strong object system, since its very difficult to break encapsulation.

      I've debated in the past if closures could be considered an object system. Here again, there is very strong encapsulation going on. I would agree with what others have noted, though, that calling closures an object system could limit their usefulness in your mind.

      Then there are the various modules that do the blessing for you. Too many to list here, but trawling through the Class:: namespace should find a few.

      The important point is not to limit yourself to Perl's common bless system. It's probably the most flexible of Perl's object system, but its also rather sucky (easy to break encapsulation, slow, etc.).

      ----
      I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
      -- Schemer

      : () { :|:& };:

      Note: All code is untested, unless otherwise stated

Re: Re: Class automators should be standard
by theguvnor (Chaplain) on Jan 14, 2004 at 09:38 UTC

    Arunbear asked how you do OOP in Perl without bless; I'd much rather know why you think it is important to know how to do that.

    Update: looks like hardburn already answered the question.

    [Jon]

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://321127]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.