At 01:02 PM 1/7/02 -0600, Skip Montanaro wrote: > >> I understand the assignment to $self and $class. What I don't > >> understand is how new and flush_buffer are associated with a specific > >> class. For example, is there anything that keeps me from calling > >> flush_buffer with an instance of a class other than ApacheHandler or > >> calling new with some other class? > > Peter> Only if that class inherits from the class the method is defined > Peter> in. Otherwise there's no way for Perl to find that code. > > >> Should the class author be doing some type checking? > > Peter> I've never seen anyone bother. I suppose you could check $class > Peter> or ref $self against __PACKAGE__ if you wanted to make sure that > Peter> no-one could call your methods from a subclass, but that sounds > Peter> very antisocial. > >I wasn't thinking about being antisocial. Perhaps Perl's packaging >structure prevents the problem I'm worrying about?
Exactly. > In Python, you can >easily define two classes in the same file. There's no confusion between >the methods of the two classes because the method definitions are nested in >the class's definitions, e.g.: > > class Foo: > def __init__(self, ...): > do_fun_stuff() > > class Bar: > def __init__(self, ...): > do_other_fun_stuff() Python::Perl::::class::package >There's no way you could accidentally initialize a Foo object with the >__init__ method for Bar objects. I guess that's what I was getting at. >Since the ApacheHandler's new method is defined at the outermost scope of >the file, what keeps it from (accidentally?) being called to initialize some >other object? Methods live in packages, not lexical scopes. -- Peter Scott Pacific Systems Design Technologies http://www.perldebugged.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]