首页
统计
关于
Search
1
Sealos3.0离线部署K8s集群
1,079 阅读
2
类的加载
739 阅读
3
Spring Cloud OAuth2.0
725 阅读
4
SpringBoot自动装配原理
690 阅读
5
集合不安全问题
583 阅读
笔记
Java
多线程
注解和反射
JVM
JUC
设计模式
Mybatis
Spring
SpringMVC
SpringBoot
MyBatis-Plus
Elastic Search
微服务
Dubbo
Zookeeper
SpringCloud
Nacos
Sentinel
数据库
MySQL
Oracle
PostgreSQL
Redis
MongoDB
工作流
Activiti7
Camunda
消息队列
RabbitMQ
前端
HTML5
CSS
CSS3
JavaScript
jQuery
Vue2
Vue3
Linux
容器
Docker
Kubernetes
Python
登录
Search
标签搜索
Java
CSS
mysql
RabbitMQ
JavaScript
Redis
JVM
Mybatis-Plus
Camunda
多线程
CSS3
Python
Spring Cloud
注解和反射
Activiti
工作流
SpringBoot
Mybatis
Spring
html5
蘇阿細
累计撰写
388
篇文章
累计收到
4
条评论
首页
栏目
笔记
Java
多线程
注解和反射
JVM
JUC
设计模式
Mybatis
Spring
SpringMVC
SpringBoot
MyBatis-Plus
Elastic Search
微服务
Dubbo
Zookeeper
SpringCloud
Nacos
Sentinel
数据库
MySQL
Oracle
PostgreSQL
Redis
MongoDB
工作流
Activiti7
Camunda
消息队列
RabbitMQ
前端
HTML5
CSS
CSS3
JavaScript
jQuery
Vue2
Vue3
Linux
容器
Docker
Kubernetes
Python
页面
统计
关于
搜索到
29
篇与
的结果
2022-08-27
迪米特法则
定义:如果两个软件实体无需直接通信,那么就不应当发生直接的相互调用,可以通过第三方转发该调用,其目的是降低耦合,提高模块的相对独立性以明星和经纪人为例:Agentpublic class Agent { private Star star; private Fans fans; private Company company; public Star getStar() { return star; } public void setStar(Star star) { this.star = star; } public Fans getFans() { return fans; } public void setFans(Fans fans) { this.fans = fans; } public Company getCompany() { return company; } public void setCompany(Company company) { this.company = company; } public void meeting() { System.out.println(star.getName() + "和粉丝:" + fans.getName() + "见面"); } public void business() { System.out.println(star.getName() + "和" + company.getName() + "进行洽谈"); } }Starpublic class Star { private String name; public Star(String name) { this.name = name; } public String getName() { return name; } }Fanspublic class Fans { private String name; public Fans(String name) { this.name = name; } public String getName() { return name; } }Companypublic class Company { private String name; public Company(String name) { this.name = name; } public String getName() { return name; } }Clientpublic class Client { public static void main(String[] args) { //经纪人 Agent agent = new Agent(); //明星 Star star = new Star("孙笑川"); agent.setStar(star); //粉丝 Fans fans = new Fans("药水哥"); agent.setFans(fans); //媒体公司 Company company = new Company("xxxTV"); agent.setCompany(company); //粉丝见面会 agent.meeting(); //商务洽谈 agent.business(); } }
2022年08月27日
34 阅读
0 评论
0 点赞
2022-08-22
接口隔离原则
定义:客户端不应该被迫依赖于它不使用的方法,即:一个类对另一个类的依赖应该建立在最小的接口上以安全门为例:存在的问题:如果要增加新的品牌的安全门,则违背了开闭原则SafetyDoorpublic interface SafetyDoor { /** * 防盗 */ void antiTheft(); /** * 防火 */ void fireproof(); /** * 防水 */ void waterproof(); }TestSafetyDoorpublic class TestSafetyDoor implements SafetyDoor { @Override public void antiTheft() { System.out.println("防盗"); } @Override public void fireproof() { System.out.println("防火"); } @Override public void waterproof() { System.out.println("防水"); } }Clientpublic class Client { public static void main(String[] args) { //存在的问题:如果要增加新的品牌的安全门,则违背了开闭原则 TestSafetyDoor testSafetyDoor = new TestSafetyDoor(); testSafetyDoor.antiTheft(); testSafetyDoor.fireproof(); testSafetyDoor.waterproof(); } }改进:抽象出安全门各个功能的接口,新增其他品牌的安全门时只需实现对应功能的接口AntiTheftpublic interface AntiTheft { /** * 防盗 */ void antiTheft(); }Fireproofpublic interface Fireproof { /** * 防火 */ void fireproof(); }Waterproofpublic interface Waterproof { /** * 防水 */ void waterproof(); }TestSafetyDoorpublic class TestSafetyDoor implements AntiTheft, Fireproof, Waterproof { @Override public void antiTheft() { System.out.println("防盗"); } @Override public void fireproof() { System.out.println("防火"); } @Override public void waterproof() { System.out.println("防水"); } }Test01SafetyDoorpublic class Test01SafetyDoor implements AntiTheft, Fireproof { @Override public void antiTheft() { System.out.println("防盗"); } @Override public void fireproof() { System.out.println("防火"); } }Clientpublic class Client { public static void main(String[] args) { //Test品牌安全门 TestSafetyDoor testSafetyDoor = new TestSafetyDoor(); testSafetyDoor.antiTheft(); testSafetyDoor.fireproof(); testSafetyDoor.waterproof(); System.out.println("================="); //Test品牌安全门 Test01SafetyDoor test01SafetyDoor = new Test01SafetyDoor(); test01SafetyDoor.antiTheft(); test01SafetyDoor.fireproof(); } }
2022年08月22日
41 阅读
0 评论
0 点赞
2022-08-22
依赖倒置原则
定义:高层模块不应该依赖低层模块,两者都应该依赖其抽象;抽象不应该依赖细节,细节应该依赖抽象以组装电脑为例:存在的问题:现在的电脑只能使用给定的组件,如果要使用其他的,则违背了开闭原则XiJiepublic class XiJie { public void save(String data) { System.out.println("使用希捷硬盘存储数据:" + data); } public String get() { System.out.println("使用希捷硬盘读取数据"); return "数据"; } }Intelpublic class Intel { public void run() { System.out.println("使用Intel cpu"); } }Kingstonpublic class Kingston { public void save() { System.out.println("使用金士顿内存条"); } }Computerpublic class Computer { private XiJie hardDisk; private Intel cpu; private Kingston memory; public XiJie getHardDisk() { return hardDisk; } public void setHardDisk(XiJie hardDisk) { this.hardDisk = hardDisk; } public Intel getCpu() { return cpu; } public void setCpu(Intel cpu) { this.cpu = cpu; } public Kingston getMemory() { return memory; } public void setMemory(Kingston memory) { this.memory = memory; } public void run() { System.out.println("电脑运行了"); String data = hardDisk.get(); System.out.println("从硬盘上获取的数据是:" + data); cpu.run(); memory.save(); } }ComputerDemopublic class ComputerDemo { public static void main(String[] args) { //创建组件对象 XiJie hardDisk = new XiJie(); Intel cpu = new Intel(); Kingston memory = new Kingston(); Computer computer = new Computer(); //组装计算机 computer.setHardDisk(hardDisk); computer.setCpu(cpu); computer.setMemory(memory); //运行 //存在的问题:现在的电脑只能使用给定的组件,如果要使用其他的,则违背了开闭原则 computer.run(); } }改进:抽象出各个配件的接口,让Computer类依赖抽象,而不是依赖于各组件的具体实现类HardDiskpublic interface HardDisk { /** * 存储数据 * * @param data 数据 */ void save(String data); /** * 读取数据 * * @return */ String get(); }Cpupublic interface Cpu { /** * 运行 */ void run(); }Memorypublic interface Memory { /** * 保存 */ void save(); }XiJiepublic class XiJie implements HardDisk { @Override public void save(String data) { System.out.println("使用希捷硬盘存储数据:" + data); } @Override public String get() { System.out.println("使用希捷硬盘读取数据"); return "数据"; } }Intelpublic class Intel implements Cpu { @Override public void run() { System.out.println("使用Intel cpu"); } }AMDpublic class Amd implements Cpu { @Override public void run() { System.out.println("使用AMD cpu"); } }Kingstonpublic class Kingston implements Memory { @Override public void save() { System.out.println("使用金士顿内存条"); } }Computerpublic class Computer { private HardDisk hardDisk; private Cpu cpu; private Memory memory; public HardDisk getHardDisk() { return hardDisk; } public void setHardDisk(HardDisk hardDisk) { this.hardDisk = hardDisk; } public Cpu getCpu() { return cpu; } public void setCpu(Cpu cpu) { this.cpu = cpu; } public Memory getMemory() { return memory; } public void setMemory(Memory memory) { this.memory = memory; } public void run() { System.out.println("电脑运行了"); String data = hardDisk.get(); System.out.println("从硬盘上获取的数据是:" + data); cpu.run(); memory.save(); } }ComputerDemopublic class ComputerDemo { public static void main(String[] args) { //创建组件对象 HardDisk xiJie = new XiJie(); //Cpu intel = new Intel(); Cpu intel = new Amd(); Memory kingston = new Kingston(); //创建计算机对象 Computer computer = new Computer(); //组装计算机 computer.setHardDisk(xiJie); computer.setCpu(intel); computer.setMemory(kingston); //运行 computer.run(); } }
2022年08月22日
36 阅读
0 评论
0 点赞
2022-08-22
里氏替换原则
定义:子类可以扩展父类的功能,但不能改变父类原有的功能(子类继承父类时,除了添加新的方法和功能外,尽量不要重写父类的方法)以正方形不是长方形为例:在resize方法中,Rectangle类型的参数不能被Square类型的参数所代替,如果进行了替换,则不能得到预期的打印结果Rectanglepublic class Rectangle { private double length; private double width; public double getLength() { return length; } public void setLength(double length) { this.length = length; } public double getWidth() { return width; } public void setWidth(double width) { this.width = width; } }Squarepublic class Square extends Rectangle { @Override public void setLength(double length) { super.setLength(length); super.setWidth(length); } @Override public void setWidth(double width) { super.setWidth(width); super.setLength(width); } }RectangleDemopublic class RectangleDemo { public static void main(String[] args) { //创建长方形对象 Rectangle rectangle = new Rectangle(); rectangle.setLength(20); rectangle.setWidth(10); //扩宽 resize(rectangle); printLengthAndWidth(rectangle); System.out.println("===================="); //创建正方形 Square square = new Square(); square.setWidth(20); resize(square); //在resize方法中,Rectangle类型的参数不能被Square类型的参数所代替,如果进行了替换,则不能得到预期的打印结果 printLengthAndWidth(square); } public static void resize(Rectangle rectangle) { //如果长 > 宽,进行扩宽操作 while (rectangle.getLength() >= rectangle.getWidth()) { rectangle.setWidth(rectangle.getWidth() + 1); } } public static void printLengthAndWidth(Rectangle rectangle) { System.out.println("长:" + rectangle.getLength()); System.out.println("宽:" + rectangle.getWidth()); } }改进:抽象出四边形接口,长方形、正方形实现四边形接口Quadrilateralpublic interface Quadrilateral { /** * 获取长 * * @return */ double getLength(); /** * 获取宽 * * @return */ double getWidth(); }Rectanglepublic class Rectangle implements Quadrilateral { private double length; private double width; public void setLength(double length) { this.length = length; } public void setWidth(double width) { this.width = width; } @Override public double getLength() { return length; } @Override public double getWidth() { return width; } }Squarepublic class Square implements Quadrilateral { private double side; public double getSide() { return side; } public void setSide(double side) { this.side = side; } @Override public double getLength() { return side; } @Override public double getWidth() { return side; } }RectangleDemopublic class RectangleDemo { public static void main(String[] args) { //创建长方形对象 Rectangle rectangle = new Rectangle(); rectangle.setLength(20); rectangle.setWidth(10); resize(rectangle); printLengthAndWidth(rectangle); System.out.println("===================="); //创建正方形对象(此时正方形和长方形不存在父子关系) Square square = new Square(); square.setSide(10); printLengthAndWidth(square); } public static void resize(Rectangle rectangle) { //如果长 > 宽,进行扩宽操作 while (rectangle.getLength() >= rectangle.getWidth()) { rectangle.setWidth(rectangle.getWidth() + 1); } } public static void printLengthAndWidth(Quadrilateral quadrilateral) { System.out.println("长:" + quadrilateral.getLength()); System.out.println("宽:" + quadrilateral.getWidth()); } }
2022年08月22日
22 阅读
0 评论
0 点赞
2022-08-19
开闭原则
定义:对扩展开放,对修改关闭以输入法更换皮肤为例抽象皮肤类public abstract class AbstractSkin { /** * 显示方法 */ public abstract void display(); } 默认皮肤public class DefaultSkin extends AbstractSkin { @Override public void display() { System.out.println("默认皮肤"); } }自定义皮肤public class TestSkin extends AbstractSkin { @Override public void display() { System.out.println("测试皮肤"); } } 搜狗输入法public class SouGouInput { private AbstractSkin skin; public void setSkin(AbstractSkin skin) { this.skin = skin; } public void display() { skin.display(); } }测试public class Client { public static void main(String[] args) { //1.创建输入法对象 SouGouInput input = new SouGouInput(); //2.创建默认皮肤对象 //DefaultSkin skin = new DefaultSkin(); TestSkin skin = new TestSkin(); //3.将皮肤设置到输入法中 input.setSkin(skin); //4.显示皮肤 input.display(); } }
2022年08月19日
33 阅读
0 评论
0 点赞
1
...
3
4