Completed
Push — master ( 87fb07...159278 )
by Jerome
01:13
created

CommandManager.undo()   A

Complexity

Conditions 2

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
dl 0
loc 3
rs 10
1
from abc import abstractmethod
2
3
4
class Command(object):
5
    @abstractmethod
6
    def do(self):
7
        pass
8
9
class UndoableCommand(object):
10
    @abstractmethod
11
    def undo(self):
12
        pass
13
14
class CommandManager(object):
15
    def __init__(self,stack):
16
        self.stack = stack
17
18
    def execute(self,command):
19
        self.stack.push(command)
20
        command.do()
21
22
    def undo(self):
23
        if self.stack.count > 0:
24
            self.stack.pop().undo()
25
26
27