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

UndoableCommand   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 4
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A undo() 0 3 1
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