⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shapefactoryimplementation.java

📁 一个描述工厂设计模式的程序
💻 JAVA
字号:

public class ShapeFactoryImplementation implements ShapeFactory{
	private static ShapeFactoryImplementation sfi;
	
	private ShapeFactoryImplementation(){
	}
	
	public static ShapeFactoryImplementation getInstance(){
		if (sfi == null){
			sfi = new ShapeFactoryImplementation();
		}
		return sfi;
	}
	
	public Shape makeShape(String shapeName){
		Class c = null;
		Shape shape = null;
		try {
			c = Class.forName(shapeName);
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		try {
			shape = (Shape) c.newInstance();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return shape;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -