示例类图
示例代码
public abstract class Video {public abstract void produce();
}public class JavaVideo extends Video {@Overridepublic void produce() {System.out.println("录制Java课程视频");}
}public class PythonVideo extends Video {@Overridepublic void produce() {System.out.println("录制Python课程视频");}
}public class FEVideo extends Video {@Overridepublic void produce() {System.out.println("录制FE课程视频");}
}public abstract class VideoFactory {public abstract Video getVideo();
}public class FEVideoFactory extends VideoFactory {@Overridepublic Video getVideo() {return new FEVideo();}
}public class JavaVideoFactory extends VideoFactory {@Overridepublic Video getVideo() {return new JavaVideo();}
}public class PythonVideoFactory extends VideoFactory {@Overridepublic Video getVideo() {return new PythonVideo();}
}public class Test {public static void main(String[] args) {VideoFactory videoFactory = new JavaVideoFactory();Video video = videoFactory.getVideo();video.produce();}}
输出:
录制Java课程视频