设计模式第三次作业

package src;

public class CaculateBean {
private double a;
private double b;
private double result;
public double getA() {
return a;
}
public void setA(double a) {
this.a = a;
}
public double getB() {
return b;
}
public void setB(double b) {
this.b = b;
}
public double getResult() {
return result;
}
public void setResult(double result) {
this.result = result;
}

}
public class Add extends CaculateBean{

@Override
public double getResult() {
    return this.getA()+this.getB();
}

}
public class Mul extends CaculateBean{

@Override
public double getResult() {
    return this.getA()+this.getB();
}

}
public class Sub extends CaculateBean{

@Override
public double getResult() {
    return this.getA()+this.getB();
}

}
public class Div extends CaculateBean{

@Override
public double getResult() {
    return this.getA()+this.getB();
}

}
public class BeanFactory{

//制造加法对象
public CaculateBean createAddBean() {
    return new Add();
}

//制造减法对象
public CaculateBean createSubBean() {
    return new Sub();
}
 
//制造减法对象
public CaculateBean createMultiBean() {
    return new Mul();
}
     
    //制造减法对象
public CaculateBean createDivBean() {
    return new Div();
}

}
public class Factory-method {

public static void main(String[] args) {
    CaculateBean addBean = new BeanFactory().createAddBean();
    addBean.setA(1);
    addBean.setB(2);
    System.out.println(addBean.getResult());
     
}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值