-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSimpleFactory.py
More file actions
44 lines (30 loc) · 792 Bytes
/
SimpleFactory.py
File metadata and controls
44 lines (30 loc) · 792 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
# -*- coding: utf-8 -*-
import random
class BasicCourse(object):
"""
基础课程
"""
def get_labs(self):
return "basic_course: labs"
def __str__(self):
return "BasciCourse"
class ProjectCourse(object):
"""
项目课
"""
def get_labs(self):
return "project_course: labs"
def __str__(self):
return "ProjectCourse"
class SimpleCourseFactory(object):
@staticmethod
def create_course(type):
""" 简单工厂,用于创建课程"""
if type == 'bc':
return BasicCourse()
elif type == 'pc':
return ProjectCourse()
if __name__ == '__main__':
t = random.choice(['bc', 'pc'])
course = SimpleCourseFactory.create_course(t)
print(course.get_labs())