Michael Rudolf a écrit :
(snip)
(pseudocode - this is *not* python ;)

class Machines (Object):
    @classmethod
    def shutdown(cls, Machine, emergency=False):
       try:
        if Machine is instanceof(Fileservers):


            if not emergency:
                Machine.unmount_raid_first()
                ...
            Machine.halt()
        if Machine is instanceof(Router):
            if not emergency:
                cls.shutdown(Machine.attachedmachines)
            ...
        ...
        finally:
        if emergency and Machine has powerswitch:
            Machine.powerswitch.Off()
    @classmethod
    def emergency(cls):
        for machine in cls.instances:
            cls.shutdown(machine, 1)


One could say that the machines have to know how to shut down itself,

Indeed !-)

but there might be dependencies they do not know about,

Then it's the "Machines" (or a "MachineShutdownProtocol" or whatever) responsability to manage correct operation order, and you need an API to allow communication between the Machine objects and the WhateverItsName object in charge of monitoring the process.

All this if you do care about correct OO design, of course - as far as I'm concerned, practicallity beats purity !-)

and as said, it clutters the emergency protocol all over the modules.

Tradeoff, tradeoff. The above won't work for a "plug&play" system.

There are cases where *no* solution is perfect,

There is always at least one "less worse" solution, depending on the concrete use case.
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to