-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathabstractFactory.py
More file actions
51 lines (32 loc) · 882 Bytes
/
abstractFactory.py
File metadata and controls
51 lines (32 loc) · 882 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import abc
__author__ = 'Bruno'
class GuiFactory(object):
__metaclass__ = abc.ABCMeta
@abc.abstractmethod
def create_button(self):
"""Create one button"""
raise NotImplementedError
@classmethod
def create_factory(cls, name):
if name == 'Gnome':
return GnomeFactory();
else:
return KDEFactory();
class GnomeFactory(GuiFactory):
def create_button(self):
return GnomeButton();
class KDEFactory(GuiFactory):
def create_button(self):
return KDEButton();
class Button(object):
__metaclass__ = abc.ABCMeta
@abc.abstractmethod
def paint(self):
"""Paint something"""
raise NotImplementedError
class GnomeButton(Button):
def paint(self):
print('GnomeButton');
class KDEButton(Button):
def paint(self):
print('KDEButton');