Less APIs or more encapsulation?

Tycho Andersen tycho at tycho.ws
Wed Sep 9 21:43:16 EDT 2009


On Wed, Sep 9, 2009 at 10:08 AM, 一首诗<newptcai at gmail.com> wrote:
> But when C has many many methods to expose to outer user, 2nd choice
> seems to be more reasonable I In the first design, B.newMethod did
> nothing really useful.

Is there any reason you can't do something like the following?

class B(object):
  def __init__(self, c):
    self.__c = c;
  def __getattr__(self, name):
    return self.__c.__getattribute__(name)

class C(object):
  def sayHi(self):
    print "c says hi"

So that when you call B and it doesn't have the attribute, it looks at
it's instance of C?

\t



More information about the Python-list mailing list