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

📄 fruitgardener.java

📁 java语言中简单工厂模式的例子
💻 JAVA
字号:
//Source file: D:\\javaproject\\DesignPattern\\StaticFactoryPattern\\FruitGardener.java


public class FruitGardener 
{
   
   /**
    * @param which
    * @throws BadFruitException
    * @roseuid 41A09922001F
    */
   public static Fruit Fruitfactory(String which) throws BadFruitException 
   {
    if(which.equalsIgnoreCase("apple"))
    {
    	return new Apple();
    }
    else if(which.equalsIgnoreCase("strawberry"))
    {
    	return new Strawberry();
    }
    else if(which.equalsIgnoreCase("grape"))
    {
    	return new Grape();
    }
    else
    {
    	throw new BadFruitException("Bad fruit request");
    }
   }
}

⌨️ 快捷键说明

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