Client.java 1.2 KB
Newer Older
ツぃ☆ve芜情's avatar
ツぃ☆ve芜情 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
package com.ice.creation.AbstractFactory;

import com.ice.creation.AbstractFactory.factory.*;
import com.ice.creation.AbstractFactory.product.Chair;
import com.ice.creation.AbstractFactory.product.CoffeeTable;
import com.ice.creation.AbstractFactory.product.Sofa;

import java.util.NoSuchElementException;

/**
 * @author ice
 * @blog https://blog.csdn.net/dreaming_coder
 * @description
 * @create 2021-10-13 10:51:49
 */
public class Client {
    private FurnitureFactory factory;

    public Client(FurnitureStyle style) {
        if (style == FurnitureStyle.Modern) {
            this.factory = new ModernLine();
        } else if (style == FurnitureStyle.Victorian) {
            this.factory = new VictorianLine();
        } else if (style == FurnitureStyle.ArtDeco) {
            this.factory = new ArtDecoLine();
        } else {
            throw new NoSuchElementException("没有此种风格生产线");
        }
    }

    public void purchaseFurniture() {
        Chair chair = factory.createChair();
        Sofa sofa = factory.createSofa();
        CoffeeTable coffeeTable = factory.createCoffeeTable();
        chair.info();
        sofa.info();
        coffeeTable.info();
    }
}