C#面象对象的语言也有类似的反射 reflection
便于根据配置文件,方便切换数据库。切换DAL层即可。
# encoding: utf-8 # 版权所有 2024 ©涂聚文有限公司 # 许可信息查看:言語成了邀功盡責的功臣,還需要行爲每日來值班嗎 # 描述: # Author : geovindu,Geovin Du 涂聚文. # IDE : PyCharm 2023.1 python 3.11 # OS : windows 10 # Datetime : 2024/11/19 20:36 # User : geovindu # Product : PyCharm # Project : IctGame # File : AbstractFactory.py # explain : 学习 from __future__ import annotations from abc import ABC, abstractmethod import os import sys from sqlserverinterface.school import ISchool #from sqlserverdal.school import SchoolDal from sqlserverinterface.teacher import ITeacher #from sqlserverdal.teacher import TeacherDal from sqlserverinterface.schoolWinner import ISchoolWinner #from sqlserverdal.schoolWinner import SchoolWinnerDal from sqlserverinterface.studentWinner import IStudentWinner #from sqlserverdal.studentWinner import StudentWinnerDal from sqlserverinterface.student import IStudent #from sqlserverdal.student import StudentDal from sqlserverinterface.answer import IAnswer #from sqlserverdal.answer import AnswerDal from sqlserverinterface.question import IQuestion #from sqlserverdal.question import QuestionDal from sqlserverinterface.studentGrade import IStudentGrade #from sqlserverdal.studentGrade import StudentGradeDal from sqlserverinterface.prizeSchool import IPrizeSchool #from sqlserverdal.prizeSchool import PrizeSchoolDal from sqlserverinterface.prizeStudent import IPrizeStudent #from sqlserverdal.prizeStudent import PrizeStudentDal from common.jsonHelper import JsonHelper class AbstractFactory(ABC): """ 工厂方法类 """ def __init__(self): """ sqlserver、mysql、postgresql """ self.__strsql=self.getDal() #"postgresql" # 可以根据配置文件,进行切换数据库如是mysql,postgreSQL,sql server def getDal(self)->str: """ :return: """ jsn = JsonHelper() self.__strsql = jsn.readDal() jsn.readDal() return jsn.readDal() @abstractmethod def createSchool(self) -> ISchool: """ 生成(创建)接口 :return: """ #dal = SchoolDal() module = __import__(self.__strsql + 'dal.school') dal = getattr(module, "SchoolDal")() return dal @abstractmethod def createTeacher(self) -> ITeacher: """ 生成(创建)接口 :return: """ #dal = TeacherDal() module = __import__(self.__strsql + 'dal.teacher') dal = getattr(module, "TeacherDal")() return dal @abstractmethod def createSchoolWinner(self) -> ISchoolWinner: """ 生成(创建)接口 :return: """ #dal = SchoolWinnerDal() module = __import__(self.__strsql + 'dal.schoolWinner') dal = getattr(module, "SchoolWinnerDal")() return dal @abstractmethod def createStudentWinner(self) -> IStudentWinner: """ 生成(创建)接口 :return: """ #dal = StudentWinnerDal() module = __import__(self.__strsql + 'dal.studentWinner') dal = getattr(module, "StudentWinnerDal")() return dal @abstractmethod def createStudent(self) -> IStudent: """ 生成(创建)接口 :return: """ #dal = StudentDal() module = __import__(self.__strsql + 'dal.student') dal = getattr(module, "StudentDal")() return dal @abstractmethod def createAnswer(self) -> IAnswer: """ 生成(创建)接口 :return: """ #dal = AnswerDal() module = __import__(self.__strsql + 'dal.answer') dal = getattr(module, "AnswerDal")() return dal @abstractmethod def createQuestion(self) -> IQuestion: """ 生成(创建)接口 :return: """ #dal = QuestionDal() module = __import__(self.__strsql + 'dal.question') dal = getattr(module, "QuestionDal")() return dal @abstractmethod def createStudentGrade(self) -> IStudentGrade: """ 生成(创建)接口 :return: """ #dal = StudentGradeDal() module = __import__(self.__strsql + 'dal.studentGrade') dal = getattr(module, "StudentGradeDal")() return dal @abstractmethod def createPrizeSchool(self) -> IPrizeSchool: """ 生成(创建)接口 :return: """ #dal = PrizeSchoolDal() module = __import__(self.__strsql + 'dal.prizeSchool') dal = getattr(module, "PrizeSchoolDal")() return dal @abstractmethod def createPrizeStudent(self) -> IPrizeStudent: """ 生成(创建)接口 :return: """ #dal = PrizeStudentDal() module = __import__(self.__strsql + 'dal.prizeStudent') dal = getattr(module, "PrizeStudentDal")() return dal
标签:__,反射,return,reflection,python,self,module,dal,import From: https://www.cnblogs.com/geovindu/p/18555670