A Example of Factory Method for Java
来源:互联网 发布:麻将手游源码 编辑:程序博客网 时间:2024/05/22 11:35
1:please create a Cycle interface and its implementation class Unicycle,Bicycle and Tricycle。create factorys for each type of class,and use them in you code。
[code=java]interface Cycle{ ride(); fix();}interface CycleFactory{ createFactory();}class Unicycle implements Cycle{ Unicycle { } ride() { System.out.println("Unicycle riding..."); } fix() { System.out.println("Unicycle being fixed successfully,you can use it again!"); }}class UnicycleFactory implements CycleFactory{ createFactory() { return new Uincycle(); }}class Bicycle implements Cycle{ Bicycle { } ride() { System.out.println("Bicycle riding..."); } fix() { System.out.println("Bicycle being fixed successfully,you can use it again!"); }}class BicycleFactory implements CycleFactory{ createFactory() { return new Bicycle(); }}class Tricycle implements Cycle{ Tricycle { } ride() { System.out.println("Tricycle riding..."); } fix() { System.out.println("Tricycle being fixed successfully,you can use it again!"); }}classTricycleFactory implements CycleFactory{ createFactory() { return new Tricycle (); }}public class CycleUser{ public static useCycle(CycleFactory cycleFactory) { Cycle cycle = cycleFactory.createFactory(); cycle.ride(); cycle.fix(); } public static void main(String [] args) { CycleUser.useCycle(new Uincycle()); CycleUser.useCycle(new Bicycle()); CycleUser.useCycle(new Tricycle()); }}[/code]
- A Example of Factory Method for Java
- A factory method Pattern
- Simple Factory Vs Factory Method Vs Abstract Factory by Example
- Design Patterns - Factory Method - Example 1
- MACRO of a method of loop list for visit elements
- A example of Log4c
- A example of pointer
- BLEU: a Method for Automatic Evaluation of Machine Translation
- Why don't we use a constructor instead of factory method?
- Java工厂方法---Factory Method
- Java工厂方法---Factory Method
- Signature of a method
- a example for calling java code in javascript use dwr
- How Synchronization works in Java ? Example of synchronized Block and Method
- A wrong example of pointer
- A good example of equals()
- [JAVA]example for jfreechart
- A Code Example For SAML
- 二极管目录
- 安装Apache Installation Wizard Interrupted问题解决方案
- Vb.net2008 Direct编程(一)
- Extjs与struts2整合,ajax请求登录验证
- struts2下利用ajax实现异步刷新
- A Example of Factory Method for Java
- 常用软件下载地址
- php 翻页区间切割算法(翻页类)
- IT 人之囧境 - 单身的找不到对象,有老婆的没空陪
- hibernate_annotation
- Swing框架之Model
- Java io流
- 实现mapreduce多文件自定义输出
- DI(依赖注入)的进阶