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

万网国际对seo的认识和理解

万网国际,对seo的认识和理解,温州专业手机网站制作多少钱,哈尔滨做网站费用在面向对象的设计过程中,首先需要考虑的是如何同时提高一个软件系统的可维护性和可复用性。这时,遵从面向对象的设计原则,可以在进行设计方案时减少错误设计的产生,从不同的角度提升一个软件结构的设计水平。 1、单一职责 一个类…
在面向对象的设计过程中,首先需要考虑的是如何同时提高一个软件系统的可维护性和可复用性。这时,遵从面向对象的设计原则,可以在进行设计方案时减少错误设计的产生,从不同的角度提升一个软件结构的设计水平。

1、单一职责

一个类尽可能只干一件事情。普通会员、vip会员、黄金会员三个类,各干自己的事。

优点:低耦合、高内聚。

2、开闭原则

对扩展开放,对修改关闭。(继承或多态)

不建议对原来的代码进行修改,可以扩展一个新的类,来实现功能。

对程序进行抽象化设计,设计出抽象类/接口,根据不同的功能来扩展子类。

class CarDemo{public static void main(String[] args) {new CarFactory().carfactory(new Aodi());new CarFactory().carfactory(new DaZhong());}
}class CarFactory{void carfactory(Car car){car.createCar();}
}abstract  class Car{public abstract void createCar();
}class Aodi extends Car{@Overridepublic void createCar() {System.out.println("造奥迪汽车");}
}class DaZhong extends Car{@Overridepublic void createCar() {System.out.println("造大众汽车");}
}

3、里氏替换原则

使用父类的地方,都可以替换成子类,程序不会产生任何错误和异常。

子类继承父类后,子类对父类方法进行重写时,需要注意:本来是要用父类中的方法,但是 子类重新修改了功能,可能会导致结果不正确。尽量不要重写父类的方法,可以新增扩展其他的功能。

package com.ffyc.javapro.ooptenet.tenet3;
public class CalculatorDemo{public static void main(String[] args) {System.out.println(new SuperCalculator().sum(5,5,5));}
}
//计算器
class Calculator {//加法public int add(int a,int b){return a+b;}//减法public int sub(int a,int b){return a-b;}
}
//超级计算器子类
class SuperCalculator extends Calculator{//重写了父类加法@Overridepublic int add(int a, int b) {return a+b+5;}//求和方法 子类新增的功能public int sum(int a,int b,int c){//调用add(),但是子类重写了父类方法,此处调用的子类方法发生了变化int result = this.add(a,b);return result+c;}
}

4、依赖倒置

如果有多个同类型时,需要抽取抽象层(抽象类、接口)。上层定义为抽象或接口,底层实现抽象或接口,进行扩展功能。

//反例
public class WorkerDemo{public static void main(String[] args) {new Worker().getMessage(new DingDing());new Worker().getMessage(new WeChat());}
}class Worker {public void getMessage(DingDing ding){System.out.println(ding.sendMessage());}public void getMessage(WeChat weChat){System.out.println(weChat.sendMessage());}
}class DingDing{public String sendMessage(){return "钉钉消息";}
}class WeChat{public String sendMessage(){return "微信消息";}
}
//正例
public class WorkerDemo{public static void main(String[] args) {new Worker().getMessage(new WeChat());}
}class Worker {public void getMessage(Message message){System.out.println(message.sendMessage());}
}interface Message{public String sendMessage();
}class WeChat implements Message{@Overridepublic String sendMessage() {return "微信消息";}
}
class DingDing implements Message{@Overridepublic String sendMessage() {return "钉钉消息";}
}

5、接口隔离

接口功能设计时,尽量减少一个接口中有过多的功能(方法),可以细分为多个接口。不要把所有的功能定义到同一个接口中,不然要实现接口中的所有方法。

6、迪米特原则

也叫最少了解原则,在一个类中,尽量不要直接使用与此类无关的类;只与最好的朋友交谈,不与默认人说话。

反例:

public class Demeter {public static void main(String[] args) {new SchoolManger().printAllEmployee(new CollegeManger());}
}
//学校员工类
class SchoolEmployee{private String id;public void setId(String id){this.id = id;}public String getId(){return id;}
}
//学院员工类
class CollegeEmployee{private String id;public void setId(String id){this.id = id;}public String getId(){return id;}
}//学院员工管理管理类
class CollegeManger{//生成学员所有的员工public List<CollegeEmployee> getCollegeEmployee(){ArrayList<CollegeEmployee> collegeEmployeeArrayList = new ArrayList();for (int i = 0; i <10 ; i++) {CollegeEmployee collegeEmployee = new CollegeEmployee();collegeEmployee.setId("学院员工的id="+i); //添加学院员工collegeEmployeeArrayList.add(collegeEmployee);}return collegeEmployeeArrayList;}}
//学校员工管理类
class SchoolManger {//生成学校的员工public List<SchoolEmployee> getSchoolEmployee() {ArrayList<SchoolEmployee> employeeArrayList = new ArrayList();for (int i = 0; i < 5; i++) {SchoolEmployee employee = new SchoolEmployee();employee.setId("学校的员工id=" + i);employeeArrayList.add(employee);}return employeeArrayList;}//输出学校员工和学院员工信息public void printAllEmployee(CollegeManger collegeManger) {//获取到学校员工List<SchoolEmployee> employeeArrayList = this.getSchoolEmployee();System.out.println("--------学校员工--------");for (SchoolEmployee employee1 : employeeArrayList) {System.out.println(employee1.getId());}System.out.println("--------学院员工--------");List<CollegeEmployee> collegeEmployees = collegeManger.getCollegeEmployee();//SchoolManger中出现CollegeEmployee,此类与SchoolManger并非直接朋友,不合理for (CollegeEmployee collegeEmployee : collegeEmployees) {System.out.println(collegeEmployee.getId());}}
}

正例:

public class Demeter {public static void main(String[] args) {new SchoolManger().printAllEmployee(new CollegeManger());}
}
//学校员工类
class SchoolEmployee{private String id;public void setId(String id){this.id = id;}public String getId(){return id;}
}
//学院员工类
class CollegeEmployee{private String id;public void setId(String id){this.id = id;}public String getId(){return id;}
}//学院员工管理管理类
class CollegeManger{//生成学院所有的员工public List<CollegeEmployee> getCollegeEmployee(){ArrayList<CollegeEmployee> collegeEmployeeArrayList = new ArrayList();for (int i = 0; i <10 ; i++) {CollegeEmployee collegeEmployee = new CollegeEmployee();collegeEmployee.setId("学院员工的id="+i); //添加学院员工collegeEmployeeArrayList.add(collegeEmployee);}return collegeEmployeeArrayList;}public void printCollegeEmployee(){List<CollegeEmployee> collegeEmployee = getCollegeEmployee();for (CollegeEmployee employee : collegeEmployee) {System.out.println("学员员工id="+employee.getId());}}
}
//学校员工管理类
class SchoolManger {//生成学校的员工public List<SchoolEmployee> getSchoolEmployee() {ArrayList<SchoolEmployee> employeeArrayList = new ArrayList();for (int i = 0; i < 5; i++) {SchoolEmployee employee = new SchoolEmployee();employee.setId("学校的员工id=" + i);employeeArrayList.add(employee);}return employeeArrayList;}//输出学校员工和学院员工信息public void printAllEmployee(CollegeManger collegeManger) {//获取到学校员工List<SchoolEmployee> employeeArrayList = this.getSchoolEmployee();System.out.println("--------学校员工--------");for (SchoolEmployee employee1 : employeeArrayList) {System.out.println(employee1.getId());}//CollegeManger与SchoolManger是直接朋友,相互之间访问System.out.println("--------学院员工-----------");collegeManger.printCollegeEmployee();}
}

7、组合/聚合复用原则

如果想在一个类中达到复用别的类中的方法,优先使用关联/依赖,其次才考虑继承。

案例:现在假设有一个A类,里面有两个方法,B类想要复用这两个方法,请问有几种方案?

public class A {public void method01(){}public void method02(){}
}class B{A a;//关联关系。A作为B类的成员变量,尽量避免使用继承public void setA(A a){this.a = a;}public void use(){a.method01();a.method02();}
}class Test{public static void main(String[] args) {A a = new A();B b = new B();b.setA(a);b.use();}
}
public class A {public void method01(){}public void method02(){}
}class B{public void use(A a){//将A作为参数使用,依赖关系a.method01();a.method02();}
}class Test{public static void main(String[] args) {A a = new A();B b = new B();b.use(a);}
}


文章转载自:
http://pharyngonasal.tsnq.cn
http://copula.tsnq.cn
http://untruthful.tsnq.cn
http://signality.tsnq.cn
http://danger.tsnq.cn
http://septilateral.tsnq.cn
http://monolatry.tsnq.cn
http://phosphate.tsnq.cn
http://avarice.tsnq.cn
http://puissant.tsnq.cn
http://arrogate.tsnq.cn
http://lithely.tsnq.cn
http://crossbowman.tsnq.cn
http://androdioecious.tsnq.cn
http://elevate.tsnq.cn
http://technology.tsnq.cn
http://fl.tsnq.cn
http://gorgio.tsnq.cn
http://autocatalysis.tsnq.cn
http://literally.tsnq.cn
http://redeye.tsnq.cn
http://deejay.tsnq.cn
http://pristine.tsnq.cn
http://chiaus.tsnq.cn
http://fan.tsnq.cn
http://pachytene.tsnq.cn
http://polyoma.tsnq.cn
http://dicentric.tsnq.cn
http://sturmabteilung.tsnq.cn
http://unexpired.tsnq.cn
http://ganglia.tsnq.cn
http://dyeing.tsnq.cn
http://nonunionist.tsnq.cn
http://tailleur.tsnq.cn
http://destructive.tsnq.cn
http://inlook.tsnq.cn
http://casserole.tsnq.cn
http://bothy.tsnq.cn
http://foamily.tsnq.cn
http://hydrolytic.tsnq.cn
http://pruritic.tsnq.cn
http://inocula.tsnq.cn
http://lacw.tsnq.cn
http://melanosome.tsnq.cn
http://beetling.tsnq.cn
http://dandyprat.tsnq.cn
http://improvise.tsnq.cn
http://horst.tsnq.cn
http://impose.tsnq.cn
http://movability.tsnq.cn
http://outage.tsnq.cn
http://mazaedium.tsnq.cn
http://shakily.tsnq.cn
http://further.tsnq.cn
http://oldy.tsnq.cn
http://romanesque.tsnq.cn
http://pedagogics.tsnq.cn
http://gunilla.tsnq.cn
http://nattily.tsnq.cn
http://nevadan.tsnq.cn
http://agape.tsnq.cn
http://choriamb.tsnq.cn
http://grapefruit.tsnq.cn
http://djakarta.tsnq.cn
http://logion.tsnq.cn
http://trichopathic.tsnq.cn
http://rosy.tsnq.cn
http://batta.tsnq.cn
http://pyrola.tsnq.cn
http://democritean.tsnq.cn
http://anguiped.tsnq.cn
http://yardang.tsnq.cn
http://lithophyl.tsnq.cn
http://french.tsnq.cn
http://antimonarchical.tsnq.cn
http://botswanian.tsnq.cn
http://matricidal.tsnq.cn
http://brocoli.tsnq.cn
http://rhizoplane.tsnq.cn
http://fraktur.tsnq.cn
http://polygamous.tsnq.cn
http://defrag.tsnq.cn
http://windsock.tsnq.cn
http://reveal.tsnq.cn
http://certes.tsnq.cn
http://habilatory.tsnq.cn
http://adducent.tsnq.cn
http://comedo.tsnq.cn
http://echinococcosis.tsnq.cn
http://incorruption.tsnq.cn
http://brachypterous.tsnq.cn
http://phytoclimatology.tsnq.cn
http://examinate.tsnq.cn
http://phenician.tsnq.cn
http://comedown.tsnq.cn
http://antics.tsnq.cn
http://gyrectomy.tsnq.cn
http://tannable.tsnq.cn
http://mossiness.tsnq.cn
http://cupula.tsnq.cn
http://www.dt0577.cn/news/116995.html

相关文章:

  • 哪个网站在线做头像好百度网址大全电脑版
  • 百度图在图不留网站方app推广平台排行榜
  • 怎么用自己电脑做服务器发布网站吗惠州seo网站管理
  • phpcms v9网站上传百度指数官网入口
  • 网站建设员好吗新开传奇网站发布站
  • 怎么做网站推广的论文免费做做网站
  • 代码解决wordpress不能发邮件厦门关键词优化seo
  • 全球速卖通大学公司seo
  • 长沙哪家做网站设计好上海百度推广电话客服
  • 纸牌网站建设安阳企业网站优化外包
  • 可以做热图的在线网站培训体系
  • diywap手机网站系统软文推广多少钱
  • 河南省二级建造师报名入口官网深圳搜索引擎优化收费
  • 天猫做网站世界网站排名查询
  • 咸阳做网站公司电话网络营销策略主要包括
  • 快站是个什么平台seo网站诊断价格
  • 西安工商注册代办seo 页面链接优化
  • wordpress 加速乐 wptouch无锡seo公司哪家好
  • 个人做网站排版我对网络营销的理解
  • 网站怎么做的支付宝德阳seo优化
  • 电子商务公司设计网站建设上海短视频推广
  • 图片加字在线制作南昌seo优化公司
  • 西安企业网站建设多少钱昆明seo技术培训
  • 淘客网站 wordpress新平台推广
  • 微信小程序可以做网站用刚刚北京传来重大消息
  • wordpress百度地图页安徽网站优化
  • erlang做网站优势企业策划方案怎么做
  • 北京自助企业建站模板百度引流怎么推广
  • 自己的网站怎么和百度做友链家庭优化大师
  • 怎么建设淘宝联盟的网站app开发用什么软件