• Java 工厂设计模式


     1 //接口的应用:工厂方法的设计模式
     2 public class TestFactoryMethod {
     3     public static void main(String[] args) {
     4         IWorkFactory i = new StudentWorkFactory();
     5         i.getWork().doWork();
     6         
     7         IWorkFactory i1 = new TeacherWorkFactory();
     8         i1.getWork().doWork();
     9     }
    10 }
    11 
    12 interface IWorkFactory{
    13     Work getWork();
    14 }
    15 class StudentWorkFactory implements IWorkFactory{
    16 
    17     @Override
    18     public Work getWork() {
    19         return new StudentWork();
    20     }
    21     
    22 }
    23 class TeacherWorkFactory implements IWorkFactory{
    24 
    25     @Override
    26     public Work getWork() {
    27         return new TeacherWork();
    28     }
    29     
    30 }
    31 
    32 interface Work{
    33     void doWork();
    34 }
    35 
    36 class StudentWork implements Work{
    37 
    38     @Override
    39     public void doWork() {
    40         System.out.println("学生写作业");
    41     }
    42     
    43 }
    44 class TeacherWork implements Work{
    45 
    46     @Override
    47     public void doWork() {
    48         System.out.println("老师批改作业");
    49     }
    50     
    51 }
  • 相关阅读:
    osg模型部分节点旋转
    IFC数据模型构件控制
    自定义基于IFC数据的施工进度数据结构
    QDateTime QString
    Qt获取屏幕分辨率
    Qt自定义类重写 copy
    removeEntry
    initGanttView
    IfcAxis2Placement3D IFC构件的位置和方向
    致我最爱的你
  • 原文地址:https://www.cnblogs.com/longc/p/5962903.html
Copyright © 2020-2023  润新知