I've seen in some scripts definitions of classes within other classes or functions like this:
class Grok(object):
class Foo(object):
...
...
What is the reason for this practice? Is it just to not allow direct instantiation of the internally defined class, and is this really a good practice or should I avoid its use at any cost?
class Circle:
class DrawingAPIOne:
'''Implementation-specific abstraction'''
def drawCircle(self, x, y, radius):
print("API 1 is drawing a circle at ({}, {}) with radius {}".format(x, y, radius))
class DrawingAPITwo:
'''Implementation-specific abstraction'''
def drawCircle(self, x, y, radius):
print("API 2 is drawing a circle at ({}, {}) with radius {}".format(x, y, radius))
def __init__(self, x, y, radius):
'''Implementation-independent abstraction; Initialize the necessary attributes'''
self._x = x
self._y = y
self._radius = radius
def drawWithAPIOne(self):
'''Implementation-specific abstraction'''
objectOfAPIone = self.DrawingAPIOne()
objectOfAPIone.drawCircle(self._x, self._y, self._radius)
def drawWithAPITwo(self):
'''Implementation-specific abstraction'''
objectOfAPItwo = self.DrawingAPITwo()
objectOfAPItwo.drawCircle(self._x, self._y, self._radius)
def scale(self, percent):
'''Implementation-independent abstraction'''
self._radius *= percent
I saw this code on the site: link