I am building a Path Planner that will help people plan a path through an RPG console game.
I want to create a table that shows each step through the stage. I have actually implemented a working version of this, however, it is seemingly awful OOP design; it breaks all sorts of principles, and I believe it is not even legitimate OOP. The problem is, clearly, that Table
is a God Class.
Due to this, I have decided to rewrite it while trying to keep in mind proper OOP principles. I want to break up Table
into multiple classes.
My problem is I need various objects to talk to each other. However, my solution is to always use composition. This breaks the dependency principle as well as the single responsibility principle.
Here is the main Table that will store the player's steps:
class PathTable(object):
''' A path table. '''
def __init__(self):
# table is a list of dicts, representing rows
self._table = []
@property
def table(self):
return self._table
def addStep(self, step):
''' Adds a step to the table. '''
self._table.append(step)
def rmStep(self):
''' Removes the last step from the table. '''
try:
del self._table[-1]
except:
raise IndexError('Tried to remove item from an empty table.')
Now, I have created an InputManager
that is responsible for accepting and validating user input:
class InputManager(object):
''' Responsible for managing user input. '''
def __init__(self):
pass
def addFight(self, position):
''' Add a 'fight' at table[position]. '''
# table._table[position]['input'] = 'fight'
# Need to somehow edit a particular row in the Table.
However, now I do not know how I can access PathTable._table[position]
. Without breaking all kinds of OO design principles.
It is frustrating, because the entire job of InputManager
is to access PathTable
. But I cannot use composition to place InputManager
inside PathTable
, because it is bad design.
What is a clean way to accomplish this?
I am a beginner, and I am trying to learn.