管理信息系统01

"""
  步骤一:
       数据模型类:StudentModel
          数据:姓名 name,年龄 age,成绩 score,编号 id
       逻辑控制类:StudentManagerController
          数据:学生列表 _stu_list
          行为:获取列表stu_List
               添加学生 add_student
"""


class StudentModel:
    def __init__(self, name, age, score, id=0):
        self.name = name
        self.age = age
        self.score = score
        self.id = id


class StudentManagerController:
    init_id = 1000
    @classmethod
    def __generate__id(cls,stu):
        stu.id=cls.init_id
        cls.init_id+=1
    def __init__(self):
        self.__stu_list = []
    @property
    def stu_list(self):
        return self.__stu_list

    def add_student(self, stu):
         StudentManagerController.__generate__id(stu)
         self.__stu_list.append(stu)

# 测试
controller = StudentManagerController()
data01=StudentModel('悟空',23,96)
controller.add_student(data01)
for i in controller.stu_list:
    print(i.id,i.name)

猜你喜欢

转载自blog.csdn.net/jtpython666/article/details/120619510