Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Re: Re: Re: Tutorial: Introduction to Object-Oriented Programming

by BrowserUk (Pope)
on Dec 12, 2002 at 20:40 UTC ( #219420=note: print w/ replies, xml ) Need Help??


in reply to Re: Re: Re: Tutorial: Introduction to Object-Oriented Programming
in thread Tutorial: Introduction to Object-Oriented Programming

Sorry fruiture, could you explain your point a bit more.

I have read your post 3 times and keep wanting to react to it, but I'm sure I'm missing the salient point.

I get lost right around "...a registry of all members of all instances...". Don't all members of a given class have the same members? And isn't the point of OO that one class should not know (nor care) what members another class has, related or not.

I know C++ has that "freind" declaration, but I think even Stroustrup admitted afterwards that the whole private/protected/friend/public/static stuff was a mistake.

"...you'll see that if you write accessor methods for the same member with different names in two related classes..."

How can you have "the same member" in "two ... classes", related or not?


Okay you lot, get your wings on the left, halos on the right. It's one size fits all, and "No!", you can't have a different color.
Pick up your cloud down the end and "Yes" if you get allocated a grey one they are a bit damp under foot, but someone has to get them.
Get used to the wings fast cos its an 8 hour day...unless the Govenor calls for a cyclone or hurricane, in which case 16 hour shifts are mandatory.
Just be grateful that you arrived just as the tornado season finished. Them buggers are real work.


Comment on Re: Re: Re: Re: Tutorial: Introduction to Object-Oriented Programming
Re^5: Tutorial: Introduction to Object-Oriented Programming
by fruiture (Curate) on Dec 12, 2002 at 21:12 UTC

    Perhaps it helps if i use "attribute" instead of "member", so one can't confuse "member" with "instance"...

    Abigail's proposal is to store attribute values of instances in lexical (or only package-global) hashes to make them safe from subclasses that might clobber attributes that are private to the superclass:

    sub some_method { my $self = shift; $self->{'_very_internal_flag'} = 1; #... }

    A subclass might also need a '_very_internal_flag' (stored as attribute of an instance) and suddenly it all breaks.

    So the idea is to store the attribute data in kind-of "registry": a central repository that keeps thes attributes in it's defining class.

    My first thought on that was to write a module that is a superclass and contains such a registry for all classes. It gives you two methods: get( attribute ) and set(attribute,value) (probably with diofferent names). These methods get/store these values in that central registry and determine the class, in which that actual attribute was defined and thus must be kept apart from other descending classes defining the same attribute. I thought of something like that because of my lazyness: it would save typing for many classes based on that principle.

    Such a module is easy to write:

    --
    http://fruiture.de
      Maybe I'm missing something with your implementation but wouldn't something like:
      package Rover; #a class of it's own ;) sub get_set_color { my $self = shift; if( @_ ){ $self->oo_set( 'color' , $_[0] ); } else { $self->oo_get( 'colour' ); } }
      lead to the same problem that Abigail-II was talking about in the first place?

      rdfield

        Well, as long as you base such a thing upon a hash (and a variable solution like the Superclass must use a hash), you cannot avoid that, but it's limited to a few lines of accessor method code. I don't think it's productive to assume a typo wherever possible and to make it impossible to break things.

        This cannot happen when you create an accessor method automatically.

        --
        http://fruiture.de

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://219420]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2014-12-29 03:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (184 votes), past polls