[Tutor] rationale for nested classes?
Serdar Tumgoren
zstumgoren at gmail.com
Fri Aug 14 17:26:53 CEST 2009
Hi everyone,
I was wondering if there's anyone who can offer a use case/rationale
for nested class?
For, instance, in the following example (taken from here:
http://www.brpreiss.com/books/opus7/html/page598.html):
class A(object):
def __init__(self):
self.y = 0
class B(object):
def __init__(self):
self.x = 0
def f(self):
pass
My initial thought was that perhaps they inherit the behavior of
parent classes, but that apparently is not the case:
Are there specific situations when nested classes come in handy
(perhaps for grouping conceptually related classes that don't share
attributes?).
Or is it typically better to keep all classes on the same level of a
heirarchy, and then just use inheritance to establish parent-child
relationships where appropriate?
Thanks!
More information about the Tutor
mailing list