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

我买了一个域名怎么做网站房价查询

我买了一个域名怎么做网站,房价查询,intitle 郑州网站建设,久久建筑网会员怎么样策略模式是行为设计模式之一 。 当我们对一个特定任务有多种算法#xff0c;并且客户端决定在运行时使用的实际实现时#xff0c;将使用策略模式。 策略模式也称为策略模式 。 我们定义了多种算法#xff0c;并让客户端应用程序将算法用作参数。 此模式的最佳示例之一是采用… 策略模式是行为设计模式之一 。 当我们对一个特定任务有多种算法并且客户端决定在运行时使用的实际实现时将使用策略模式。 策略模式也称为策略模式 。 我们定义了多种算法并让客户端应用程序将算法用作参数。 此模式的最佳示例之一是采用Comparator参数的Collections.sort()方法。 基于Comparator接口的不同实现将以不同的方式对对象进行排序请查看此文章以使用Java Comparable和Comparator在Java中对对象进行排序。 对于我们的示例我们将尝试实现一个简单的购物车其中我们有两种付款策略-使用信用卡或使用PayPal。 首先我们将为我们的策略创建接口在本例中将支付作为参数传递的金额。 package com.journaldev.design.strategy;public interface PaymentStrategy {public void pay(int amount); } 现在我们将不得不创建使用信用卡/借记卡或通过Paypal付款的算法的具体实现。 package com.journaldev.design.strategy;public class CreditCardStrategy implements PaymentStrategy {private String name;private String cardNumber;private String cvv;private String dateOfExpiry;public CreditCardStrategy(String nm, String ccNum, String cvv, String expiryDate){this.namenm;this.cardNumberccNum;this.cvvcvv;this.dateOfExpiryexpiryDate;}Overridepublic void pay(int amount) {System.out.println(amount paid with credit/debit card);}}package com.journaldev.design.strategy;public class PaypalStrategy implements PaymentStrategy {private String emailId;private String password;public PaypalStrategy(String email, String pwd){this.emailIdemail;this.passwordpwd;}Overridepublic void pay(int amount) {System.out.println(amount paid using Paypal.);}} 现在我们的算法已经准备就绪我们可以实现购物车并且付款方式将需要输入作为付款策略。 package com.journaldev.design.strategy;public class Item {private String upcCode;private int price;public Item(String upc, int cost){this.upcCodeupc;this.pricecost;}public String getUpcCode() {return upcCode;}public int getPrice() {return price;}}package com.journaldev.design.strategy;import java.text.DecimalFormat; import java.util.ArrayList; import java.util.List;public class ShoppingCart {//List of itemsListItem items;public ShoppingCart(){this.itemsnew ArrayListItem();}public void addItem(Item item){this.items.add(item);}public void removeItem(Item item){this.items.remove(item);}public int calculateTotal(){int sum 0;for(Item item : items){sum item.getPrice();}return sum;}public void pay(PaymentStrategy paymentMethod){int amount calculateTotal();paymentMethod.pay(amount);} } 请注意购物车的付款方式需要付款算法作为参数而不是将其存储为实例变量。 让我们用一个简单的程序测试我们的设置。 package com.journaldev.design.strategy;public class ShoppingCartTest {public static void main(String[] args) {ShoppingCart cart new ShoppingCart();Item item1 new Item(1234,10);Item item2 new Item(5678,40);cart.addItem(item1);cart.addItem(item2);//pay by paypalcart.pay(new PaypalStrategy(myemailexample.com, mypwd));//pay by credit cardcart.pay(new CreditCardStrategy(Pankaj Kumar, 1234567890123456, 786, 12/15));}} 上面程序的输出是 50 paid using Paypal. 50 paid with credit/debit card策略模式类图 重要事项 我们本可以使用组合来创建策略的实例变量但应避免这种情况因为我们希望将特定策略应用于特定任务因此在Collections.sort和Arrays.sort方法中也遵循相同的方法将比较器用作论点。 策略模式与状态模式非常相似。 区别之一是Context包含状态作为实例变量并且可以有多个任务的实现可以依赖于状态而在策略模式中strategy作为参数传递给方法并且上下文对象没有任何变量来存储它。 当我们有多个用于特定任务的算法并且希望我们的应用程序灵活地在运行时为特定任务选择任何算法时策略模式很有用。 这就是Java中的Strategy Pattern的全部内容希望您喜欢它。 参考 Java中的策略设计模式 -JCG合作伙伴 Pankaj Kumar在开发人员食谱博客上的示例教程 。 翻译自: https://www.javacodegeeks.com/2013/08/strategy-design-pattern-in-java-example-tutorial.html
http://www.pierceye.com/news/110498/

相关文章:

  • 西宁建一个网站公司广东网站备案
  • 网站数据比较北京网站优化推广公司
  • 想做网站的客户在哪找美间在线设计平台
  • 网站设计规划的目的和要求营销外贸网站建设案例
  • 网站营销力一级a做爰片2017免费网站
  • 昌图网站网页界面设计的要求
  • 做一个网站赚钱什么 门户网站
  • 中国建设银行购物网站帝国织梦wordpress
  • 瑞安网站网站建设松原公司做网站的流程
  • 做网站按页面收费视频解析网站如何做搜索
  • 太原网站的公司赣州安全教育平台
  • 淮北建投网站网站推广与维护有什么不同
  • 深圳网站备案注销平果县免费网站哪家好
  • 如何区分网站开发语言做网站多少钱一般
  • 定制专业app开发seo数据统计分析工具有哪些
  • 某服装公司网站建设论文网站建设seo虾哥网络
  • 网站建设销售员工作内容网站访问量过大
  • 企业网站加快企业信息化建设设计网站名称
  • 做网站的技术要求高吗农业推广专业
  • 在百度做个卷闸门网站怎么做成都高端网站
  • 个人网站备案名称填写货运网站建设公司
  • 有网页源码 怎么做网站外链发布软件
  • 医疗网站建设基本流程wordpress速度加快
  • 网站建设优化开发公司哪家好泰州东方医院男科
  • 怎么自己做歌曲网站大连网站制作公司费用多少
  • 网站专题设计稿用vue做商城网站常用的js
  • 怎么在免费空间里面做网站深圳英文站seo
  • 学风建设网站版块如何用visual studio做网站
  • 山东响应式网站设置字体颜色的网站
  • 美容院网站建设西安有关做网站的公司有哪些