Our emails just crossed!

Agree that multiple inheritance can get messy and Python's 'super' is error prone, but forcing a "has-a" relation here means that I should activate the Process object from the constructor of Resource.  It would make more sense to leave the activation and the rest of the Process interface to the user of MyMachine, isn't it?

On Sun, Oct 17, 2010 at 11:46 AM, Klaus Muller <kgmuller@xs4all.nl> wrote:
Lorenzo,
I don't like multiple inheritance (in Python or elsewhere). It is messy.

I would model this machine not by "is-a" Resource and Process (inheritance), but by "has-a" (composition), like so:

class Machine(Resource):
   class MachineProcess(Process):
       def __init__(self, owner):
           self.owner = owner

       def ACTIONS(self):
           etc.

   def __init__(self, res):
       self.mp = MachineProcess(self)
       activate(self.mp)


This approach even allows multiple processes to be associated with the same Resource, e.g. a usage process and a repair process. You get the idea.

What dou you think?

Klaus Müller


Sent from my iPad

On 17.10.2010, at 10:29, Lorenzo Di Gregorio <lorenzo.digregorio@gmail.com> wrote:

> Hi,
>
> I would like to model a set of processes which exclusively access a resource to store items into it.  Furthermore, this resource has a process which consumes the stored items.
> One clean way to model the resource with a process seems to me to inherit both Resource and Process, like:
>
> class MyMachine(Resource,Process):
>     def __init__(self,*args,**kwargs):
>         super(Resource,self).__init__(*args,**kwargs)
>         super(Process,self).__init__(*args,**kwargs)
>         <MyCodeHere>
>         return
>
>     def ACTIONS(self):
>         <MyCodeHere>
>
> Using *args and **kwargs solves some problems with Python's multiple inheritance and 'super', but *args and **kwargs cause an error if Resource and Process get passed arguments they do not know about, because they do not include these catchalls.  On the other hand, it would be more portable to avoid naming all arguments explicitly within the 'super' statements.
>
> How would you do this?
>
> Best Regards,
> Lorenzo
>
> ------------------------------------------------------------------------------
> Download new Adobe(R) Flash(R) Builder(TM) 4
> The new Adobe(R) Flex(R) 4 and Flash(R) Builder(TM) 4 (formerly
> Flex(R) Builder(TM)) enable the development of rich applications that run
> across multiple browsers and platforms. Download your free trials today!
> http://p.sf.net/sfu/adobe-dev2dev
> _______________________________________________
> Simpy-users mailing list
> Simpy-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/simpy-users