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

江苏做家纺的公司网站首页优化排名

江苏做家纺的公司网站,首页优化排名,wordpress最好的中文主题,装饰网站建设运营设计模式原则 设计模式示例代码库地址: https://gitee.com/Jasonpupil/designPatterns 里氏替换原则 继承必须确保父类所拥有的性质在子类中依然成立 与开闭原则不同的是开闭原则可以改变父类原有的功能,里氏替换原则不能修改父类的原有的性质&#…

设计模式原则

设计模式示例代码库地址:

https://gitee.com/Jasonpupil/designPatterns

里氏替换原则

  • 继承必须确保父类所拥有的性质在子类中依然成立

  • 与开闭原则不同的是开闭原则可以改变父类原有的功能,里氏替换原则不能修改父类的原有的性质,即使子类扩展了父类的功能,也不能改变父类的原有功能

  • 提高兼容性、维护性和扩展性

    • 子类和父类的接口保持一致,确保在任何使用父类的地方都可以替换为子类,而不会影响系统功能
    • 子类能够无缝地替换父类,替换时不需要修改客户端代码,方便地扩展新功能而不需要对现有代码进行大规模修改
    • 由于子类完全遵循父类的契约,系统在替换子类时不容易出现未预见的运行时错误

使用场景:银行卡存储,

  • 信用卡继承并重写储蓄卡的功能,破坏了里氏替换原则,根据里氏替换原则进行修改

里氏替换原则替换前示例代码:

储蓄卡类:
/*** @Description: 模拟储蓄卡功能* @Author: pupil* @Date: 2024/06/23 下午 10:04*/
public class CashCard {private Logger logger = LoggerFactory.getLogger(CashCard.class);private static List<String> tradeList = new ArrayList<>();/*** 提现** @param orderId 单号* @param amount  金额* @return 状态码 0000成功、0001失败、0002重复*/public String withdrawal(String orderId, BigDecimal amount) {// 模拟支付成功logger.info("提现成功,单号:{} 金额:{}", orderId, amount);return "0000";}/*** 储蓄** @param orderId 单号* @param amount  金额* @return 状态码 0000成功、0001失败、0002重复*/public String recharge(String orderId, BigDecimal amount) {// 模拟充值成功logger.info("储蓄成功,单号:{} 金额:{}", orderId, amount);return "0000";}/*** 交易流水查询** @return 交易流水*/public List<String> tradeFlow() {logger.info("交易流水查询成功");tradeList.add("14451,100.00");tradeList.add("14451,65.00");tradeList.add("14451,76.50");tradeList.add("14451,126.00");return tradeList;}
}
信用卡类:
 /*** @Description: 模拟信用卡功能,重写父类的方法,违法里氏替换原则* @Author: pupil* @Date: 2024/06/23 下午 10:32*/public class CreditCard extends CashCard{private Logger logger = LoggerFactory.getLogger(CashCard.class);/*** @param orderId 单号* @param amount  金额* @return 状态码 0000成功、0001失败、0002重复*/@Overridepublic String withdrawal(String orderId, BigDecimal amount) {// 校验if (amount.compareTo(new BigDecimal(1000)) >= 0){logger.info("贷款金额校验(限额1000元),单号:{} 金额:{}", orderId, amount);return "0001";}// 模拟生成贷款单logger.info("生成贷款单,单号:{} 金额:{}", orderId, amount);// 模拟支付成功logger.info("贷款成功,单号:{} 金额:{}", orderId, amount);return "0000";}/**** @param orderId 单号* @param amount  金额* @return 状态码 0000成功、0001失败、0002重复*/@Overridepublic String recharge(String orderId, BigDecimal amount) {// 模拟生成还款单logger.info("生成还款单,单号:{} 金额:{}", orderId, amount);// 模拟还款成功logger.info("还款成功,单号:{} 金额:{}", orderId, amount);return "0000";}@Overridepublic List<String> tradeFlow() {return super.tradeFlow();}}
测试类:
/*** @Description: 验证测试* @Author: pupil* @Date: 2024/06/23 下午 10:33*/public class ApiTest {private Logger logger = LoggerFactory.getLogger(ApiTest.class);@Testpublic void test_CashCard() {CashCard cashCard = new CashCard();// 提现cashCard.withdrawal("14451", new BigDecimal(100));// 储蓄cashCard.recharge("14451", new BigDecimal(100));// 交易流水List<String> tradeFlow = cashCard.tradeFlow();logger.info("查询交易流水,{}", JSON.toJSONString(tradeFlow));}@Testpublic void test_CreditCard() {CreditCard creditCard = new CreditCard();// 支付creditCard.withdrawal("14451", new BigDecimal(100));// 还款creditCard.recharge("14451", new BigDecimal(100));// 交易流水List<String> tradeFlow = creditCard.tradeFlow();logger.info("查询交易流水,{}", JSON.toJSONString(tradeFlow));}}
结果:
  • 在这里插入图片描述
  • 在这里插入图片描述

里氏替换原则替换后示例代码:

银行卡类:
/**
* @Description: 银行卡
* @Author: pupil
* @Date: 2024/06/23 下午 10:46
*/
public abstract class BankCard {private Logger logger = LoggerFactory.getLogger(BankCard.class);private static List<String> tradeList = new ArrayList<String>();private String cardId;   // 卡号private String cardDate; // 开卡时间public BankCard(String cardId, String cardDate) {this.cardId = cardId;this.cardDate = cardDate;}abstract boolean rule(BigDecimal amount);/*** 正向入账,+ 钱* @param orderId 单号* @param amount 金额* @return 状态码 0000成功、0001失败、0002重复*/public String positive(String orderId, BigDecimal amount) {// 入款成功,存款、还款logger.info("卡号{} 入款成功,单号:{} 金额:{}", cardId, orderId, amount);return "0000";}/*** 逆向入账,- 钱* @param orderId* @param amount* @return 状态码 0000成功、0001失败、0002重复*/public String negative(String orderId, BigDecimal amount) {// 入款成功,存款、还款logger.info("卡号{} 出款成功,单号:{} 金额:{}", cardId, orderId, amount);return "0000";}/*** 交易流水查询** @return 交易流水*/public List<String> tradeFlow() {logger.info("交易流水查询成功");tradeList.add("14451,100.00");tradeList.add("14451,80.00");tradeList.add("14451,76.50");tradeList.add("14451,126.00");return tradeList;}public String getCardId() {return cardId;}public String getCardDate() {return cardDate;}
}/**
* @Description: 模拟储蓄卡功能
* @Author: pupil
* @Date: 2024/06/23 下午 10:04
*/
public class CashCard extends BankCard {private Logger logger = LoggerFactory.getLogger(CashCard.class);public CashCard(String cardNo, String cardDate) {super(cardNo, cardDate);}boolean rule(BigDecimal amount) {return true;}/*** 提现** @param orderId 单号* @param amount  金额* @return 状态码 0000成功、0001失败、0002重复*/public String withdrawal(String orderId, BigDecimal amount) {// 模拟支付成功logger.info("提现成功,单号:{} 金额:{}", orderId, amount);return super.negative(orderId, amount);}/*** 储蓄** @param orderId 单号* @param amount  金额*/public String recharge(String orderId, BigDecimal amount) {// 模拟充值成功logger.info("储蓄成功,单号:{} 金额:{}", orderId, amount);return super.positive(orderId, amount);}}
信用卡类:
/**
* @Description: 模拟信用卡功能,重写父类的方法,违法里氏替换原则
* @Author: pupil
* @Date: 2024/06/23 下午 10:32
*/
public class CreditCard extends CashCard{private Logger logger = LoggerFactory.getLogger(CashCard.class);public CreditCard(String cardNo, String cardDate) {super(cardNo, cardDate);}/*** 金额规则* 根据里氏替换原则不能重写父类的rule方法,所以新构建一个方法* @param amount* @return*/boolean rule2(BigDecimal amount) {return amount.compareTo(new BigDecimal(1000)) <= 0;}/*** 提现,信用卡贷款** @param orderId 单号* @param amount  金额* @return 状态码 0000成功、0001失败、0002重复*/public String loan(String orderId, BigDecimal amount) {boolean rule = rule2(amount);if (!rule) {logger.info("生成贷款单失败,金额超限。单号:{} 金额:{}", orderId, amount);return "0001";}// 模拟生成贷款单logger.info("生成贷款单,单号:{} 金额:{}", orderId, amount);// 模拟支付成功logger.info("贷款成功,单号:{} 金额:{}", orderId, amount);return super.negative(orderId, amount);}/*** 还款,信用卡还款** @param orderId 单号* @param amount  金额* @return 状态码 0000成功、0001失败、0002重复*/public String repayment(String orderId, BigDecimal amount) {// 模拟生成还款单logger.info("生成还款单,单号:{} 金额:{}", orderId, amount);// 模拟还款成功logger.info("还款成功,单号:{} 金额:{}", orderId, amount);return super.positive(orderId, amount);}
}
测试类:
/**
* @Description: 测试验证
* @Author: pupil
* @Date: 2024/06/23 下午 10:51
*/
public class ApiTest {private Logger logger = LoggerFactory.getLogger(ApiTest.class);@Testpublic void test_bankCard() {logger.info("里氏替换前,CashCard类:");CashCard bankCard = new CashCard("800999898", "2024-06-23");// 提现bankCard.withdrawal("14451", new BigDecimal(100));// 储蓄bankCard.recharge("14451", new BigDecimal(100));logger.info("里氏替换后,CreditCard类:");CashCard creditCard = new CreditCard("800999898", "2024-06-23");// 提现creditCard.withdrawal("14451", new BigDecimal(1000000));// 储蓄creditCard.recharge("14451", new BigDecimal(100));// 交易流水List<String> tradeFlow = bankCard.tradeFlow();logger.info("查询交易流水,{}", JSON.toJSONString(tradeFlow));}@Testpublic void test_CreditCard(){CreditCard creditCard = new CreditCard("800999898", "2024-06-23");// 支付,贷款creditCard.loan("14451", new BigDecimal(100));// 还款creditCard.repayment("14451", new BigDecimal(100));// 交易流水List<String> tradeFlow = creditCard.tradeFlow();logger.info("查询交易流水,{}", JSON.toJSONString(tradeFlow));}
}
结果:
  • 在这里插入图片描述

  • 在这里插入图片描述

根据里氏替换原则的示例类图:

在这里插入图片描述

银行卡和储蓄卡是泛化关系,储蓄卡继承于银行卡

储蓄卡和信用卡是泛化关系,信用卡继承于储蓄卡


文章转载自:
http://devolute.mcjp.cn
http://atwain.mcjp.cn
http://powwow.mcjp.cn
http://buoyancy.mcjp.cn
http://disrate.mcjp.cn
http://participancy.mcjp.cn
http://fund.mcjp.cn
http://nethermost.mcjp.cn
http://consuela.mcjp.cn
http://midget.mcjp.cn
http://isomeric.mcjp.cn
http://bilobate.mcjp.cn
http://micrometeor.mcjp.cn
http://staffelite.mcjp.cn
http://cryoconite.mcjp.cn
http://neglectfully.mcjp.cn
http://unci.mcjp.cn
http://malmsey.mcjp.cn
http://gyroscopic.mcjp.cn
http://hii.mcjp.cn
http://blendword.mcjp.cn
http://spicae.mcjp.cn
http://hardhead.mcjp.cn
http://gendarmerie.mcjp.cn
http://periselene.mcjp.cn
http://expo.mcjp.cn
http://xuthus.mcjp.cn
http://featherlet.mcjp.cn
http://glairy.mcjp.cn
http://clot.mcjp.cn
http://kheda.mcjp.cn
http://momento.mcjp.cn
http://quotative.mcjp.cn
http://prado.mcjp.cn
http://muhammadan.mcjp.cn
http://nobbler.mcjp.cn
http://cimeliarch.mcjp.cn
http://gynoecia.mcjp.cn
http://rheebuck.mcjp.cn
http://wildish.mcjp.cn
http://nampo.mcjp.cn
http://suggestive.mcjp.cn
http://landscapist.mcjp.cn
http://ghostwriter.mcjp.cn
http://wannish.mcjp.cn
http://unfaltering.mcjp.cn
http://hypertherm.mcjp.cn
http://topdressing.mcjp.cn
http://supererogatory.mcjp.cn
http://kashmiri.mcjp.cn
http://demargarinated.mcjp.cn
http://antitheism.mcjp.cn
http://phonic.mcjp.cn
http://wheatgrass.mcjp.cn
http://extensionless.mcjp.cn
http://torridity.mcjp.cn
http://punctiform.mcjp.cn
http://chronometry.mcjp.cn
http://revolutionize.mcjp.cn
http://unusually.mcjp.cn
http://tyrannously.mcjp.cn
http://bejeaned.mcjp.cn
http://gallinaceous.mcjp.cn
http://cloudscape.mcjp.cn
http://eaux.mcjp.cn
http://concertmeister.mcjp.cn
http://homey.mcjp.cn
http://hinduism.mcjp.cn
http://coffle.mcjp.cn
http://enclosed.mcjp.cn
http://jingoist.mcjp.cn
http://tussal.mcjp.cn
http://whereby.mcjp.cn
http://witted.mcjp.cn
http://legree.mcjp.cn
http://remuda.mcjp.cn
http://inchoative.mcjp.cn
http://concolorous.mcjp.cn
http://czarism.mcjp.cn
http://adenovirus.mcjp.cn
http://merchantable.mcjp.cn
http://melaleuca.mcjp.cn
http://blahs.mcjp.cn
http://astrut.mcjp.cn
http://cablegram.mcjp.cn
http://biological.mcjp.cn
http://floridness.mcjp.cn
http://sentence.mcjp.cn
http://marcando.mcjp.cn
http://quintessence.mcjp.cn
http://turnverein.mcjp.cn
http://xenotropic.mcjp.cn
http://chemoreception.mcjp.cn
http://udometer.mcjp.cn
http://preterlegal.mcjp.cn
http://australis.mcjp.cn
http://kalmuck.mcjp.cn
http://deodorant.mcjp.cn
http://abask.mcjp.cn
http://nerviness.mcjp.cn
http://www.15wanjia.com/news/61679.html

相关文章:

  • 做创意小视频的网站网站编辑seo
  • 网页设计与网站建设教材抖音关键词排名查询工具
  • 单页网站 html5 动态搭建网站步骤
  • 玉器网站模版网站营销策划
  • 网站建设交易平台企业qq下载
  • 极速网站建设定制多少钱产品营销策略怎么写
  • 网站如何做快排海南网站推广
  • 网站内容模板谷歌网站网址
  • 做网站怎么建文件夹百度新闻最新消息
  • 专业代做网站网站关键词如何优化上首页
  • 简洁中文网站模板下载乔拓云智能建站官网
  • 商河做网站公司阜新网站seo
  • 贵金属企业网站源码关键词快速排名怎么做
  • php网站路径问题网络营销的常用方法有哪些
  • 平邑县门户网站seo全称是什么意思
  • php网站开发简历网络推广的方式有哪些?
  • 购物网站开发教案百度知道首页官网
  • 建设网站视频百度云盘网络推广员是干什么的
  • 广州做网站的公司哪家好哪里有培训班
  • 网站建设v网络推广的方法有
  • 做爰网站視屏最新国际新闻50条简短
  • 用css div做网站的首页无锡网站制作无锡做网站
  • 中企动力全球邮箱邵阳网站seo
  • 公司做外贸网站广告代理公司
  • 书店网站模版超级seo外链
  • 网站设计公司网站设计公司北京最新消息今天
  • 政府网站 都是谁做的网络营销的50种方法
  • 交互设计和ui设计的区别seo优化自学
  • 建德网站建设德品牌网重庆seo报价
  • 用什么技术可以做web网站推广app赚钱的平台