当前位置: 首页 > news >正文

网站开发众包平台网址信息查询

网站开发众包平台,网址信息查询,成年人适合看的电视剧,专业做棋牌网站的返回首页 前言 感谢各位同学的关注与支持,我会一直更新此专题,竭尽所能整理出更为详细的内容分享给大家,但碍于时间及精力有限,代码分享较少,后续会把所有代码示例整理到github,敬请期待。 此章节介绍策…

返回首页

前言

感谢各位同学的关注与支持,我会一直更新此专题,竭尽所能整理出更为详细的内容分享给大家,但碍于时间及精力有限,代码分享较少,后续会把所有代码示例整理到github,敬请期待。

此章节介绍策略模式。


1、策略模式

在策略模式中,一个类的行为或其算法可以在运行时更改。

在策略模式中,我们创建表示各种策略的对象和一个行为随着策略对象改变而改变的context对象。策略对象改变context对象的执行算法。

定义一系列的算法,把它们一个个封装起来,并且使它们可相互替换。

1.1、UML图

在这里插入图片描述
在这里插入图片描述

1.2、示例代码

// 版本一:未使用面向对象思想
//if (string.IsNullOrEmpty(tbPrice.Text) || string.IsNullOrEmpty(tbCount.Text))
//{
//    MessageBox.Show("单价或数量不能为空");
//    return;
//}
//double total = Convert.ToDouble(tbPrice.Text) * Convert.ToDouble(tbCount.Text);
//_total += total;
//rtbList.AppendText("单价:" + tbPrice.Text + " 数量:" + tbCount.Text + " 合计:" + total + "\n");
//lbTotal.Text = _total.ToString();// 版本二(增加打折):重复代码过多、未使用面向对象思想
//if (string.IsNullOrEmpty(tbPrice.Text) || string.IsNullOrEmpty(tbCount.Text))
//{
//    MessageBox.Show("单价或数量不能为空");
//    return;
//}
//double total = 0;
//switch (cbxType.SelectedIndex)
//{
//    case 0:
//        total = Convert.ToDouble(tbPrice.Text) * Convert.ToDouble(tbCount.Text);
//        break;
//    case 1:
//        total = Convert.ToDouble(tbPrice.Text) * Convert.ToDouble(tbCount.Text) * 0.8;
//        break;
//    case 2:
//        total = Convert.ToDouble(tbPrice.Text) * Convert.ToDouble(tbCount.Text) * 0.7;
//        break;
//    case 3:
//        total = Convert.ToDouble(tbPrice.Text) * Convert.ToDouble(tbCount.Text) * 0.5;
//        break;
//}
//_total += total;
//rtbList.AppendText("单价:" + tbPrice.Text + " 数量:" + tbCount.Text + " " + cbxType.SelectedItem + " 合计:" + total + "\n");
//lbTotal.Text = _total.ToString();// 版本三:简单工厂模式
//if (string.IsNullOrEmpty(tbPrice.Text) || string.IsNullOrEmpty(tbCount.Text))
//{
//    MessageBox.Show("单价或数量不能为空");
//    return;
//}
//Factory.CashSuper cash = Factory.CashFactory.CreateFactory(cbxType.SelectedItem.ToString());
//double total = cash.acceptCash(Convert.ToDouble(tbPrice.Text) * Convert.ToDouble(tbCount.Text));
//_total += total;
//rtbList.AppendText("单价:" + tbPrice.Text + " 数量:" + tbCount.Text + " " + cbxType.SelectedItem + " 合计:" + total + "\n");
//lbTotal.Text = _total.ToString();版本三:策略模式
//if (string.IsNullOrEmpty(tbPrice.Text) || string.IsNullOrEmpty(tbCount.Text))
//{
//    MessageBox.Show("单价或数量不能为空");
//    return;
//}
//Strategy.CashContext cashContext = null;
//switch (cbxType.SelectedItem)
//{
//    case "正常收费":
//        cashContext = new Strategy.CashContext(new Strategy.CashNormal());
//        break;
//    case "打八折":
//        cashContext = new Strategy.CashContext(new Strategy.CashRebate(0.8));
//        break;
//    case "满300返100":
//        cashContext = new Strategy.CashContext(new Strategy.CashReturn(300, 100));
//        break;
//    default:
//        break;
//}
//double total = cashContext.GetResult(Convert.ToDouble(tbPrice.Text) * Convert.ToDouble(tbCount.Text));
//_total += total;
//rtbList.AppendText("单价:" + tbPrice.Text + " 数量:" + tbCount.Text + " " + cbxType.SelectedItem + " 合计:" + total + "\n");
//lbTotal.Text = _total.ToString();// 版本四:策略模式、简单工厂模式
if (string.IsNullOrEmpty(tbPrice.Text) || string.IsNullOrEmpty(tbCount.Text))
{MessageBox.Show("单价或数量不能为空");return;
}
Strategy.CashContextFactory ccf = new Strategy.CashContextFactory(cbxType.SelectedItem.ToString());
double total = ccf.GetResult(Convert.ToDouble(tbPrice.Text) * Convert.ToDouble(tbCount.Text));
_total += total;
rtbList.AppendText("单价:" + tbPrice.Text + " 数量:" + tbCount.Text + " " + cbxType.SelectedItem + " 合计:" + total + "\n");
lbTotal.Text = _total.ToString();
http://www.jinmujx.cn/news/116201.html

相关文章:

  • 做网站说什么5.0啥意思网页设计模板网站免费
  • 沈阳seo排名外包seo公司发展前景
  • 20亿做网站推广平台下载
  • 网站建设的6个基本步骤seo门户网站优化
  • 简述网站建设基本流程图怎么找百度客服
  • 做任务得得q币的网站保定seo排名外包
  • 域名和空间都有了怎么做网站合肥网络推广外包
  • jquery 显示 wordpressseo顾问赚钱吗
  • 网站备案取消重新备案百度开户资质
  • 建设网站框架网站优化招聘
  • 国网福州seo结算
  • 海南今日新闻最新消息北京网站优化常识
  • 优质网站建设哪家好百度一下你就知道官网新闻
  • 北京定制网络营销收费曹操博客seo
  • 网站建设如何盈利培训seo哪家学校好
  • 两学一做网站无法做题搜索引擎优化的完整过程
  • 遂宁市住房与城乡建设厅网站舆情危机公关公司
  • 建门户网站哪家最好十堰seo优化
  • dnf做心悦宠物的网站公司网站的作用
  • 开展农业信息网站建设工作沈阳seo优化新势力
  • 沧州哪里有做网站的公司4000-小区推广最有效的方式
  • 高端网站制作公免费网络推广平台
  • 昆明做网站建设方案使用 ahrefs 进行 seo 分析
  • 蜜雪冰城网站建设策划方案网站友情链接美化代码
  • 个人制作网站的流程网站推广的工作内容
  • 建设比较好网站附近广告公司联系电话
  • 做公司网站需要什么程序nba最新排名东西部
  • 哪个网站做视频钱多seo实战培训费用
  • 烟台外贸网站建设河南推广网站的公司
  • 中文网站站内优化怎么做查权重的软件