in reply to Re: Is Perl Truly an Object Oriented Language?
in thread Is Perl Truly an Object Oriented Language?

At some point, an inherited class has to know a little more about the internals of its parent than other code. This goes for any language, not just Perl. Not necessarily all the details, just more than normal.

Further, I never consider data in the object's underlieing reference to be private. Rather, it's more analagous to Java's protected variables, which are explicitly allowed to be fiddled with by classes in the same namespace and/or subclasses. Java enforces this, though obviously Perl doesn't (without doing a lot of extra work, anyway).

If the parent wants a truely private variable, it should have done:

package Foo; my ($host, $port); # Private vars # rest of class

Lexically scoped variables are very hard to get at outside the given lexical scope. At least as hard as a private var in Java.

"There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.

Replies are listed 'Best First'.
Re^3: Is Perl Truly an Object Oriented Language?
by William G. Davis (Friar) on Dec 03, 2004 at 19:11 UTC

    At some point, an inherited class has to know a little more about the internals of its parent than other code. This goes for any language, not just Perl. Not necessarily all the details, just more than normal.

    Not in Smalltalk. You inherit from classes all the time without knowing their internals; only what messages they respond to. In fact, *every* object inherits--at some point--from "Object", the root of the inheritance hierarchy. I honestly have no idea how Object's methods are implemented internally by the Smalltalk distro I'm using right now (Squeak), but I know what messages I can send to objects derived from it and how they'll respond to those messages, and that's good enough.

    It's not the fact that Perl doesn't prevent you from fiddling with the internals that rubs me the wrong way, it's the fact that you really can't do anything without fiddling.

    I'm not trying to bash Perl and I don't think OO is the be-all end-all, but this is one area where, unfortunately, Perl is exceptionally weak. But that's ok, because it's good at everything else :)

      If you don't want to fiddle don't. Declare accessor methods like in the other languages, allocate private dictionary (inside-out-design, or simply __PACKAGE__ or an allocationmethod in the base class TIMTOMTDI), and put your variables into that.