请教大家一个关于.NET的中一段代码的很简单的问题

在一个数据层里面的代码是这样的: namespace Calc1._0 { /// /// 基类 /// public abstract class Operation { public abstract Double GetResult(Double x, Double y); } /// /// "+"算法类 /// public class Add:Operation { public override Double GetResult(Double x, Double y) { return x + y; } } /// /// "-"算法类 /// public class Sub:Operation { public override Double GetResult(Double x, Double y) { return x - y; } } /// /// "*"算法类 /// public class Mul : Operation { public override Double GetResult(Double x, Double y) { return x * y; } } /// /// "/"算法类 /// public class Div : Operation { public override Double GetResult(Double x, Double y) { return x / y; } } /// /// 类工厂,实现算法 /// public class OperationFactory { Operation _op; public OperationFactory(string str) { switch (str) { case "+": _op= new Add(); break; case "-": _op= new Sub(); break; case "*": _op= new Mul(); break; case "/": _op= new Div(); break; } } public Double GetResult(Double x, Double y) { return _op.GetResult(x,y); } } } 而在调用的时候,我有一些代码看不懂: namespace Calce2._0 { public partial class Form1 : Form { bool isOpbtPress = false; Double A = 0; Double B = 0; Operation op = null; public Form1() { InitializeComponent(); } private void button11_Click(object sender, EventArgs e) { Button bt = sender as Button; textBox1.Text= (isOpbtPress?bt.Text:(textBox1.Text+bt.Text)); isOpbtPress = false; } private void button14_Click(object sender, EventArgs e) { isOpbtPress = true; B = Convert.ToDouble(textBox1.Text); if (op!=null) { A=op.GetResult(A, B); textBox1.Text = A.ToString(); } if (op == null) A = B; op = OperationFactory.Get((sender as Button).Text); } private void button17_Click(object sender, EventArgs e) { textBox1.Text = null; isOpbtPress = false; A = B = 0; op = null; } } } ” Operation op “这个是什么意思啊?为什么要是这样写啊?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值