首页 > 代码库 > Simple Factory Pattern

Simple Factory Pattern

public class PayMethodFactory

{

    public static AbstractPay getPayMethod(String type)

    {

        if(type.equalsIgnoreCase("cash"))

        {

            return new CashPay();       //根据参数创建具体产品

         }

        else if(type.equalsIgnoreCase("creditcard"))

        {

            return new CreditcardPay();   //根据参数创建具体产品

        }

        ……

    }

}

Simple Factory Pattern