Polymorphism the Python way
Daniel Klein
danielk at aracnet.com
Tue Sep 2 09:05:09 EDT 2003
More information about the Python-list mailing list
Tue Sep 2 09:05:09 EDT 2003
- Previous message (by thread): Polymorphism the Python way
- Next message (by thread): Polymorphism the Python way
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Sun, 31 Aug 2003 03:47:49 -0400, Graham Fawcett <fawcett at teksavvy.com> wrote: >Why not just use the same attribute name in each class? > > class Dead(object): > def __init__(self, deadthing): > self.thing = deadthing > > class Parrot(object): > def __init__(self, parrotthing): > self.thing = parrotthing > >Then you can access the attribute as `someobj.thing`. > >Given that you hate getters, and that you didn't title your message, >"Encapsulation the Python Way", accessing instance attributes directly >is fair game. ;-) Yes, I could do this, but a method provides better control over the state. Daniel Klein
- Previous message (by thread): Polymorphism the Python way
- Next message (by thread): Polymorphism the Python way
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list