Общее правило будет параметром.
Вопрос в том, имеет-а имеет-а:
Is the box a grid?
yes: # if so, then is it really a box???
The box should inherit grid
no:
The box should get a reference to the grid
#(generally through a setter or constructor parameter).
Редактировать
Пример:
class Grid:
def __init__(self,width=1,height=1):
this.width = width; this.height = height;
def getDimensions(self):
return (this.width, this.height)
class Box:
def __init__(self, grid):
this.__grid = grid; this.x = 0; this.y = 0
def verify(self):
width, height = this.__grid.dimensions()
if this.x < width and this.y < height:
print( "A-OK!" );
else
print( "I am off the grid!!!" )
grid = Grid();
box = Box(grid);
box.verify();