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

php 自动做网站点击量游戏 网站模板

php 自动做网站点击量,游戏 网站模板,社群营销的十大步骤,企业内容管理系统1、开闭原则#xff08;Open-closed Principle#xff09; 开闭原则#xff0c;是面向设计中最基础的设计原则。 一个软件实体类、模块、函数应该对扩展开放、对修改关闭。 强调的是用抽象构建框架#xff0c;用实现扩展细节。可以提高软件系统的可复用性和可维护性。 实…1、开闭原则Open-closed Principle 开闭原则是面向设计中最基础的设计原则。 一个软件实体类、模块、函数应该对扩展开放、对修改关闭。 强调的是用抽象构建框架用实现扩展细节。可以提高软件系统的可复用性和可维护性。 实例 public interface ICourse {Integer getId();String getName();Double getPrice();}public class JavaCourse implements ICourse{private Integer id;private String name;private Double price;public Integer getId() {return this.id;}public String getName() {return this.name;}public Double getPrice() {return this.price;}public JavaCourse(Integer id, String name, Double price) {this.id id;this.name name;this.price price;} }public class JavaDiscountCourse extends JavaCourse {public JavaDiscountCourse(Integer id, String name, Double price) {super(id, name, price);}public Double getOriginPrice() {return super.getPrice();}public Double getPrice() {return super.getPrice() * 0.6;}}2、本末倒置原则Dependence Inversion Principle 高层模块不应该依赖底层模块二者都应该依赖其抽象。 抽象不应该依赖细节细节应该依赖抽象。 本末倒置可以减少类与类之间的耦合性提高系统的稳定性提高代码的可读性和可维护性降低修改程序造成的风险。 实例 public interface ICourse {void study();}public class JavaCourse implements ICourse{Overridepublic void study() {System.out.println(学习Java);}}public class PythonCourse implements ICourse{Overridepublic void study() {System.out.println(学习Python);}}/*** 方式一依赖注入每次学习一个新课程就多创建一个类*/ public class PersonOne {public void study(ICourse iCourse){iCourse.study();}public static void main(String[] args) {PersonOne personOne new PersonOne();personOne.study(new JavaCourse());personOne.study(new PythonCourse());} }/*** 方式二构造器注入调用时每次都要创建实例*/ public class PersonTwo {private ICourse iCourse;public PersonTwo(ICourse iCourse) {this.iCourse iCourse;}public void study() {iCourse.study();}public static void main(String[] args) {PersonTwo personTwo new PersonTwo(new JavaCourse());personTwo.study();} }/*** 方式三Setter方式注入*/ public class PersonThree {private ICourse iCourse;public void setCourse(ICourse iCourse) {this.iCourse iCourse;}public void study() {iCourse.study();}public static void main(String[] args) {PersonThree personTwo new PersonThree();personTwo.setCourse(new JavaCourse());personTwo.study();} }3、单一职责Simple Responsibility Principle 不要存在多于一个导致类变更的原因 一个对象应该只包含单一的职责并且该职责被完整地封装在一个类中。 /*** course存在两种处理逻辑这个地方修改代码*/ public class Course {public void study(String name){if(直播.equals(name)){System.out.println(不能快进);}else {System.out.println(2xx倍速);}}public static void main(String[] args) {Course course new Course();course.study(直播);}}修改下的代码这样把两个课程给分开控制。 public class LiveCourse {public void study(String name){System.out.println(不能快进);} }public class ReplayCourse {public void study(String name){System.out.println(2xx倍速);} }public class Test {public static void main(String[] args) {LiveCourse liveCourse new LiveCourse();liveCourse.study(直播);ReplayCourse replayCourse new ReplayCourse();replayCourse.study(测试);}}在这里插入代码片4、接口隔离原则Interface Segregation Principle 用多个专门的接口而不使用单一的接口客户端不应该依赖它不需要的接口 一个类对一类的依赖应该建立在最小的接口上建立单一接口不要建立庞大的接口尽量细化接口接口中的方法尽量少 实例: public interface Animal {void eat();void fly();void swimming(); }public class Bird implements Animal{Overridepublic void eat() {}Overridepublic void fly() {}Overridepublic void swimming() {} }public class Dag implements Animal{Overridepublic void eat() {}Overridepublic void fly() {}Overridepublic void swimming() {} }当dog不能飞鸟儿不能游泳的时候这个方法就会空这时候需要根据动物行为设计不同的接口 public interface EatAnimal {void eat();}public interface FlyAnimal {void fly();}public interface SwimmingAnimal {void swimming();}public class Dog implements SwimmingAnimal, EatAnimal{Overridepublic void eat() {}Overridepublic void swimming() {} }5、迪米特法则Law of demeter LoD 一个对象应该对其他对象保持最少的了解。只和朋友交流不喝陌生人说话。 出现在成员变量、方法的输入、输出参数中的类都可以称为成员朋友类出现在方法体内内部的类不属于朋友类。 实例 public class Course { }public class Employee {public void checkNumOfCourse(ListCourse courseList) {System.out.println(课程数量 courseList.size());} }public class Leader {public void CommandCheckNumber(Employee employee){ListCourse courseList new ArrayListCourse();for (int i 0; i 20; i) {courseList.add(new Course());}employee.checkNumOfCourse(courseList);}public static void main(String[] args) {Leader leader new Leader();Employee employee new Employee();leader.CommandCheckNumber(employee);} }根据迪米特法则Leader只想要结果不需要和Course有直接的接触所以这个地方修改 public class EmployeeCp {public void checkNumOfCourse() {ListCourse courseList new ArrayListCourse();for (int i 0; i 20; i) {courseList.add(new Course());}System.out.println(课程数量 courseList.size());} }public class LeaderCp {public void CommandCheckNumber(EmployeeCp employee){employee.checkNumOfCourse();}public static void main(String[] args) {LeaderCp leader new LeaderCp();EmployeeCp employee new EmployeeCp();leader.CommandCheckNumber(employee);} }6、里氏替换原则Liskov Substitution Priciple 如果针对一个类型为T1的对象O1都有类型T2的对象O2使得以T1定义的所有程序P在所有的对象O1都替换成O2时程序P的行为没有发生变化那么类型T2还是类型T1的子类型。 1子类可以实现父类的抽象方法但不能覆盖父类的非抽象方法 2子类仲可以增加自己特有的方法 3当子类的方法重载父类的方法时方法的前置条件入参要比父类方法的输入参数更宽松 4当子类的方法实现 父类的方法时方法的后置条件输出/返回值要比父类更严格或相等 优点 1约束继承泛滥开闭原则的一种体现 2加签程序的健壮性同时变更也可以做到好的兼容提高程序的维护性、扩展性降低需求变更时的风险 实例 public class Rectangle {private Long height;private Long width;public Long getHeight() {return height;}public Long getWidth() {return width;}public void setHeight(Long height) {this.height height;}public void setWidth(Long width) {this.width width;} }public class Square extends Rectangle {private Long length;public Long getLength() {return length;}public void setLength(Long length) {this.length length;}Overridepublic Long getHeight() {return getLength();}Overridepublic void setHeight(Long height) {setLength(height);}Overridepublic Long getWidth() {return getLength();}Overridepublic void setWidth(Long width) {setLength(width);}}public class Test {public static void resize(Rectangle rectangle){while (rectangle.getWidth() rectangle.getHeight()){rectangle.setHeight(rectangle.getHeight()1);System.out.printf(width: %s, height:%s, rectangle.getWidth(), rectangle.getHeight());}System.out.printf(width: %s, height:%s, rectangle.getWidth(), rectangle.getHeight());}public static void main(String[] args) {Rectangle rectangle new Rectangle();rectangle.setWidth(20L);rectangle.setHeight(10L);resize(rectangle);//死循环Square square new Square();square.setLength(10L);resize(square);} }当是正方形的时候陷入死循环违背里氏替换原则父类替换成子类后结果不是预期。 修改代码创建一个抽象四边形 public interface QuadRectangle {Long getWidth();Long getHeight(); }public class RectangleCp implements QuadRectangle{private Long height;private Long width;public Long getHeight() {return height;}public Long getWidth() {return width;}public void setHeight(Long height) {this.height height;}public void setWidth(Long width) {this.width width;} }public class SquareCp implements QuadRectangle {private Long length;public Long getLength() {return length;}public void setLength(Long length) {this.length length;}Overridepublic Long getHeight() {return getLength();}Overridepublic Long getWidth() {return getLength();}}7、合成复用原则Composite Reuse Principle 尽量使用对象组合has-a/聚合contain-a而不是继承达到软件复用的目的。 继承叫做“白箱复用”把所有的实现细节暴露给子类 组合/聚合称为“黑箱复用”对类以外的对象是无法获取到实现细节的 实例 public class DBConnection {public String getConnection() {return MySql连接;} }public class ProductDao {private DBConnection dbConnection;public void setDbConnection(DBConnection dbConnection){this.dbConnection dbConnection;}public void addProduct(){String conn dbConnection.getConnection();System.out.println(创建商品);}}如果这时候不只是mysql还有其他类型的数据库违反开闭原则 修改代码 public abstract class DBConnectionCp {public abstract String getConnection(); }public class MysqlConnection extends DBConnection{Overridepublic String getConnection() {return mysql;} }public class OracleConnection extends DBConnection{Overridepublic String getConnection() {return Oracle;} }
http://www.yutouwan.com/news/57970/

相关文章:

  • 潍坊网站建设首荐创美网络怎么做品牌推广和宣传
  • 检察院门户网站建设网页布局设计说明
  • 自贡住房和城乡建设厅网站网站怎么做切换图片
  • 什么是展示型网站建设网站如何做超级链接
  • 接做施工图的网站seo推广优化平台
  • 网站建设要求卖货到海外的免费平台
  • asp网站配置典型的网站开发人员
  • 沈阳做公司网站的公司无锡企业网站设计公司
  • 工作做ppt课件的网站2000个免费货源网站
  • 网站建设淘宝模板宁波企业seo外包
  • 怎么筛选一家做网站做的好的公司重庆网站建设优斗士
  • 响应式网站开发哪家好设计精美的中文网站
  • 无锡公司建立网站做跨境的网站有哪些
  • 网站建设能解决哪些问题大连甘井子区地图
  • 西安网站排名优化做效果图网站有哪些
  • 微网站缺点网站重定向怎么做
  • 企业网站建设需要哪些步骤科技部网站
  • 视频网站开发教程我花钱买了一个函授本科
  • app网站建设需要什么软件最有性价比的网站建设
  • 网站建设技术架构和语言网站建设过程与思路
  • 推广app网站企业网站设计报名
  • 网站开发建设与维护邯郸网站建设安联网络公司
  • 著名网站设计师c 手机版网站开发
  • 电子商务与网站建设嘉兴网站建设哪家做得好
  • 网站监控 重启企业官网如何设计
  • 网站如何做搜狗搜索引擎上海闵行邮编
  • 网站建设 中企动力wordpress 优酷去广告插件
  • 公司内部网站管理系统天天广告联盟
  • 一个网站如何做cdn加速器西安大兴医院网站建设
  • 都是做面食网站建设工程合同在性质上属于什么合同