Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

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

by BrowserUk (Patriarch)
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.

"'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

Replies are listed 'Best First'.
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:

      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?


        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.


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (1)
As of 2023-03-26 03:26 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (63 votes). Check out past polls.