Python double inheritance -
i'm trying find suitable inheritance configuration following problem:
my base class agent class has 3 abstract methods:
class agent(): __metaclass__ = abc.abcmeta def __init__(self): @abc.abstractmethod def bidding_curve(self): @abc.abstractmethod def evaluate_bidding_curve(self): @abc.abstractmethod def action(self):
an agent can either simulated using executable (dymo) or using fmu (a zip file of c-source code). created 2 different types of agents inherit base agent , implement way of communicating simulation. here implementation of dymo simulation environment same goes fmu.
class dymoagent(agent): def __init__(self, power, dymo): """ agent based on dymosim simulation environment. @param dymo: dymo needs run """ super(dymoagent, self).__init__() self.dymo = dymo def bidding_curve(self): pass def evaluate_bidding_curve(self, priority): pass def action(self, priority): self.dymo.action()
the dymoagent , fmuagent determine how agent interact simulation environment.
next need implementation of agent determine how agent interact application. however, want interaction independent of simulation environment. e.g. want create agent can communicate heater application , implements logic so.
class heater(whatagentshouldiusehere): pass
i want heater class implement abstract methods agent base-class , implementation of dymo- or fmuagent knows how interact simulation. don't want write 2 heater classes same logic (and same code) inheriting different simulation agents. summarized question in image:
is there way use inheritance prevent this?
/arnout
make heater
simple object accepts agent in constructor:
class heater(object): def __init__(self, agent): self.agent = agent # define other methods interaction heater application # in can access agent methods self.agent.a_method(...)
Comments
Post a Comment