-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathfactory_pattern.py
41 lines (28 loc) · 901 Bytes
/
factory_pattern.py
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
from abc import ABCMeta, abstractstaticmethod
class LPerson(metaclass=ABCMeta):
@abstractstaticmethod
def personMethod():
"""iface method"""
class Student(LPerson):
def __init__(self):
self.name = "zulkepretes"
def personMethod(self):
print("Student name {}".format(self.name))
class Teacher(LPerson):
def __init__(self):
self.name = "sayutes"
def personMethod(self):
print("Teacher name {}".format(self.name))
class PersonFactory:
@staticmethod
def build_person(person_type):
if person_type == "Student":
return Student()
if person_type == "Teacher":
return Teacher()
print("invalid type")
return -1
if __name__ == "__main__":
choice = input("what category (Student / Teacher): ")
person = PersonFactory.build_person(choice)
person.personMethod()