学一个易懂的工厂设计模式

阅读更多
package com.javaeye.pattern.factory;
/**
 * 

Title:

*

Description:

*

Copyright: Copyright (c) 2002

*

Company: The9.com

* @author Jerry Shen * @version 0.5 */ public class Factory { public Window CreateWindow (String type) { if(type.equals("Big")) { return new WindowBig(); } else if(type.equals("Small")) { return new WindowSmall(); } else { return new WindowBig(); } } // The Main function only for our test public static void main(String[] args) { Factory myFactory = new Factory(); Window myBigWindow = myFactory.CreateWindow("Big"); myBigWindow.func(); Window mySmallWindow = myFactory.CreateWindow("Small"); mySmallWindow.func(); } }



package com.javaeye.pattern.factory;
/**
 * 

Title:

*

Description:

*

Copyright: Copyright (c) 2002

*

Company: The9.com

* @author Jerry Shen * @version 0.5 */ public abstract class Window { public abstract void func(); }




package com.javaeye.pattern.factory;
/**
 * 

Title:

*

Description:

*

Copyright: Copyright (c) 2002

*

Company: The9.com

* @author Jerry Shen * @version 0.5 */ import java.io.*; import java.lang.*; public class WindowBig extends Window { public void func() { System.out.println("This is Big Window !"); } }

package com.javaeye.pattern.factory;
/**
 * 

Title:

*

Description:

*

Copyright: Copyright (c) 2002

*

Company: The9.com

* @author Jerry Shen * @version 0.5 */ import java.io.*; import java.lang.*; public class WindowSmall extends Window { public void func() { System.out.println("This is Small Window !"); } }

你可能感兴趣的:(设计模式,Java,C,C++,C#)