The fruit seller explained the factory model and opened the next day~

Store link πŸ”— Fruit seller explains the factory mode of design mode

Open the next day

store business crisis

The store has been open for a while, and now the store can indeed sell different varieties of fruit, but if you notice it carefully, take apples as an example, our store can only sell ordinary apples, so this is too bland! So I thought, no way! How can I keep a shop like this open! then what should we do?
Then I can only chat with the owner of the fruit factory! Check to see if he has different varieties of apples, bananas, etc., so the next day you went to chat with the owner of the fruit factory. The boss said that now his fruit factory only has ordinary fruits and no other varieties of fruits. It’s not impossible, the boss contacted the boss of another fruit factory, and he has the variety I want! And he has two different varieties of apples, bananas and oranges! Now let’s take a look at how the stocking situation of our store is after combining with the new fruit factory!

Factory Retrofit

In order to better integrate the original factory with the new factory, three small factories producing ordinary fruits are combined. The
original fruit factory:
πŸ„πŸ„πŸ„πŸ„πŸ„

/*
The production process of the original fruit factory
* */ 
public  interface  Factory {
 // Produce ordinary apples 
    public Fruit createApple () ;
 // produce a normal banana 
    public Fruit createBanana () ;
 // produce ordinary oranges 
    public Fruit createOrange ();
}

New factory:
produce new varieties 1️⃣

The following is the variety information of the three new varieties produced by the new factory No. 1~1️⃣

public  class  Red_Fuji_Apple  implements  Fruit {
     @Override 
    public String getFruitInfo ()  {
         return  "I am a new red Fuji apple!" ;
    }
}

public  class  Rice_Banana  implements  Fruit {
     @Override 
    public String getFruitInfo ()  {
         return  "I am a new variety of Rice Banana!" ;
    }
}

public  class  Sugar_Orange  implements  Fruit {
     @Override 
    public String getFruitInfo ()  {
         return  "I am a new variety of Sugar Orange!" ;
    }
}

Below is the variety information of the three new varieties produced by the new factory No. 2~2️⃣

public  class  Pink_Beauty_Apple  implements  Fruit {
     @Override 
    public String getFruitInfo ()  {
         return  "I'm the new pink beauty!" ;
    }
}

public  class  Tribute_Orange  implements  Fruit {
     @Override 
    public String getFruitInfo ()  {
         return  "I am a new variety of Gongju!" ;
    }
}

public  class  Tribute_Orange  implements  Fruit {
     @Override 
    public String getFruitInfo ()  {
         return  "I am a new variety of Gongju!" ;
    }
}

Smart you will definitely think of a question, that is – why is it so messy! Apple and banana! A factory can be both bananas and apples! It’s okay when the number is small, but it’s not easy to manage when the number is too large! So after discussing with the other two bosses, you decide: then manage them separately, with one small factory specializing in apple production and the other specializing in banana production… It seems easier to go back to the old way of management!
πŸ™‹β€β™€οΈπŸ™‹β€β™€οΈπŸ™‹β€β™€οΈπŸ™‹β€β™€οΈ

/*
 * Apple factory: produce different varieties of apples
 * */
public class AppleFactory {

    public Apple createApple(){
        Apple apple = new Apple();
        apple.getFruitInfo();System.out 
        .println ( "Apple successfully produced!" );
         return apple;
    }

    public Red_Fuji_Apple createRedFujiApple(){
        Red_Fuji_Apple red_fuji_apple = new Red_Fuji_Apple();
        red_fuji_apple.getFruitInfo();
        System.out .println ( "Red Fuji apple production is successful!" );
         return red_fuji_apple ;
    }

    public Pink_Beauty_Apple createPinkBeautyApple(){
        Pink_Beauty_Apple pink_beauty_apple = new Pink_Beauty_Apple();
        pink_beauty_apple.getFruitInfo();
        System.out .println ( "Pink Beauty apple production is successful!" );
         return pink_beauty_apple ;
    }
}

/*
* Banana Factory: Produces bananas
* */
public class BananaFactory {
    public Banana createBanana(){
        Banana banana = new Banana();System.out 
        .println ( "Banana production is successful!" );
         return banana;
    }

    public Rice_Banana createRiceBanana(){
        Rice_Banana rice_banana = new Rice_Banana();
        rice_banana.getFruitInfo();
        System.out .println ( "Rice banana production is successful!" );
         return rice_banana ;
    }

    public Sesame_Banana createSesameBanana(){
        Sesame_Banana sesame_banana = new Sesame_Banana();
        sesame_banana.getFruitInfo();
        System.out .println ( "Successful production of sesame bananas!" );
         return sesame_banana ;
    }
}

/*
* Orange Factory: produces oranges
* */
public class OrangeFactory {
    public Orange createOrange(){
        Orange orange = new Orange();
        orange.getFruitInfo();System.out 
        .println ( "Orange production is successful!" );
         return orange;
    }

    public Sugar_Orange createSugarOrange(){
        Sugar_Orange sugar_orange = new Sugar_Orange();
        sugar_orange.getFruitInfo();
        System.out .println ( "Successfully produced sugar orange!" );
         return sugar_orange ;
    }

    public Tribute_Orange createTributeOrange(){
        Tribute_Orange tribute_orange = new Tribute_Orange();
        tribute_orange.getFruitInfo();
        System. out .println( "Success in producing tribute oranges!" );
         return tribute_orange;
    }
}

Incoming order is coming

Well, the factory is all arranged, the following is the latest purchase order, please check it!

public class Order {
    public static void main(String[] args) {System.out 
        .println ( "Hello boss, here is your latest purchase order!" );System.out 
        .println ( "Apples made by the Apple Factory...." );
        AppleFactory appleFactory = new AppleFactory();
        Apple apple = appleFactory.createApple();
        Red_Fuji_Apple redFujiApple = appleFactory.createRedFujiApple();
        Pink_Beauty_Apple pinkBeautyApple = appleFactory.createPinkBeautyApple();System.out 
        .println ( "Banana from the banana factory...." );
        BananaFactory bananaFactory = new BananaFactory();
        Banana banana = bananaFactory.createBanana();
        Rice_Banana riceBanana = bananaFactory.createRiceBanana();
        Sesame_Banana sesameBanana = bananaFactory.createSesameBanana();System.out 
        .println ( "Oranges produced by the orange factory...." );
        OrangeFactory orangeFactory = new OrangeFactory();
        Orange orange = orangeFactory.createOrange();
        Sugar_Orange sugarOrange = orangeFactory.createSugarOrange();
        Tribute_Orange tributeOrange = orangeFactory.createTributeOrange();System.out 
        .println ( "Purchase list as above" );
    }
}

Alright, it all looks perfect! , until one day:
“Boss, is there any peach cake for sale?”
Me: “Ah?”

Next notice~~

Leave a Comment

Your email address will not be published. Required fields are marked *