第2章商场促销——策略模式-创新互联
背景:做一个商场收银软件
成都创新互联公司长期为超过千家客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为白塔企业提供专业的网站设计、网站制作,白塔网站改版等技术服务。拥有十年丰富建站经验和众多成功案例,为您定制开发。收费情形:正常收费、打八折、打七折、打五折 策略模式是一种定义一系列算法的方法,从概念上来看,所有这些算法完成的都是相同的工作,只是实现不同,它可以以相同的方式调用所有的算法,减少各种算法类与使用算法类之间的耦合。 策略模式的Strategy类参差为Context定义了一系列的可供重用的算法或行为。继承又助于析取出这些算法中的公共功能。 策略模式的优点是简化了单元测试,因为每个算法都有自己的类,可以通过自己的借口单独测试。 当不同的行为堆砌在一个类中时,就很难避免使用条件语句来选择合适的行为。将这些行为封装在一个个独立的Strategy类中,可以在使用这些行为的类中消除条件语句。 策略模式就是用来封装算法的,但在实践中,我们发现可以用它类封装几乎任何类型的规则,只要在分析过程中听到需要在不同时间应用不同的业务规则,就可以考虑使用策略模式来处理这种变化的可能性。 1:简单工厂实现面向对象的编程,并不是类越多越好,类的划分是为了封装,但分类的基础是抽象,具有相同属性和功能的对象的抽象集合才是类。






2:策略模式 它定义了算法家族,分别封装起来,它它们之间可以互相替换,此模式让算法的变化,不会影响到使用算法的客户。








文章标题:第2章商场促销——策略模式-创新互联
标题URL:http://scyanting.com/article/cecohs.html