网站恶意镜像专业电子网站建设
- 作者: 五速梦信息网
- 时间: 2026年04月20日 08:09
当前位置: 首页 > news >正文
网站恶意镜像,专业电子网站建设,中建八局第一建设有限公司宁文忠,wordpress英文怎么转换中文文章目录 UML图的结构主要表现为#xff1a;继承#xff08;抽象#xff09;、关联 、组合或聚合 的三种关系。1. 继承#xff08;抽象#xff0c;泛化关系#xff09;2. 关联3. 组合/聚合各种可能的配合#xff1a;1. 关联后抽象2. 关联的集合3. 组合接口4. 递归聚合接… 文章目录 UML图的结构主要表现为继承抽象、关联 、组合或聚合 的三种关系。1. 继承抽象泛化关系2. 关联3. 组合/聚合各种可能的配合1. 关联后抽象2. 关联的集合3. 组合接口4. 递归聚合接口 AdapterBridgeCompositeDecoratorFacadeFlyweightProxy GoF(Gang of Four)设计模式的三大类 创建型设计模式Creational Patterns结构型设计模式Structural Patterns行为设计模式Behavioral Patterns Object Scope 可用于运行时 Class Scope 只能用于编译时 UML图的结构主要表现为继承抽象、关联 、组合或聚合 的三种关系。 车是交通工具车是我的车里有发动机
- 继承抽象泛化关系 class Vehicle {String name;void move() {} }class Car extends Vehicle {void drive() {} }2. 关联 class Person {Car car; // 关联关系 }class Car {String model; }3. 组合/聚合 class Car {Engine engine; // 组合关系GPS gps; // 聚合关系 }class Engine {} class GPS {}各种可能的配合 圈住部分即为原因。
- 关联后抽象 2. 关联的集合 3. 组合接口 4. 递归聚合接口 这里递归怎么理解
其实是虽然我的装饰器实现了这个接口但是我的装饰器类内部成员可能还有有这个接口类。 Adapter 适配器模式能够将不兼容的接口转换成兼容的接口从而使得原本无法直接交互的类能够合作。 可以在不修改现有代码的情况下重用第三方的功能或代码。 可以在不同的系统间进行灵活的接口转换尤其适用于系统集成和迁移。 Adapter适配器设计模式
继承关联 “关联后抽象”
“ 加一层新接口。”
“R”标记可运行时改变实心箭头指实现空心指泛化 设计逻辑的层次 先从具体类ConcreteAdapter的实现入手明确其与其他类的关联如 Adaptee。然后在其上进一步抽象出一个统一的接口Adapter以适应多种实现需求。 // 老版本的播放器接口 class OldMediaPlayer {void playAudio() {System.out.println(Playing audio…);} }// 新播放器接口 interface ModernPlayer {void play(); }// 适配器类 class PlayerAdapter implements ModernPlayer {private OldMediaPlayer oldMediaPlayer;public PlayerAdapter(OldMediaPlayer oldMediaPlayer) {this.oldMediaPlayer oldMediaPlayer;}Overridepublic void play() {oldMediaPlayer.playAudio(); // 使用旧方法适配新接口} }// 客户端代码 public class AdapterExample {public static void main(String[] args) {OldMediaPlayer oldPlayer new OldMediaPlayer();ModernPlayer modernPlayer new PlayerAdapter(oldPlayer);modernPlayer.play(); // 使用新接口播放} }Bridge 解耦抽象和实现桥接模式将抽象部分与实现部分分离可以独立地扩展两者。 新增抽象层或者实现层时不会影响到对方增强了系统的可扩展性。 避免重复代码增加代码复用性。 Bridge桥设计模式 组合接口 “ 比如形状类里加个颜色类。 而该形状可以在各种地方使用”
// 实现接口 interface Color {String fill(); }class Red implements Color {public String fill() {return Color is Red;} }class Blue implements Color {public String fill() {return Color is Blue;} }// 抽象类 abstract class Shape {protected Color color;public Shape(Color color) {this.color color;}abstract void draw(); }class Circle extends Shape {public Circle(Color color) {super(color);}public void draw() {System.out.println(Drawing Circle. color.fill());} }// 客户端代码 public class BridgeExample {public static void main(String[] args) {Shape redCircle new Circle(new Red());Shape blueCircle new Circle(new Blue());redCircle.draw();blueCircle.draw();} }Composite 树形结构组合模式允许你以树形结构来组合对象简化了对象的管理和处理。 统一操作可以统一对单个对象和组合对象的处理客户端不需要知道是单一对象还是组合对象。 递归结构支持递归组合使得层次结构更易于表示和管理特别适用于有层次结构的对象模型。 Composite组合设计模式 递归聚合接口 “可以都放进一个容器装满书的书包” 书包里可能还有一个书包所以书包的“聚合”里还有component抽象类——递归。
// 组件接口 interface Component {void operation(); }// 叶子节点 class Leaf implements Component {private String name;public Leaf(String name) {this.name name;}public void operation() {System.out.println(Leaf: name);} }// 容器节点 class Composite implements Component {private ListComponent children new ArrayList();public void add(Component component) {children.add(component);}public void operation() {for (Component child : children) {child.operation();}} }// 客户端代码 public class CompositeExample {public static void main(String[] args) {Composite root new Composite();Leaf leaf1 new Leaf(Leaf 1);Leaf leaf2 new Leaf(Leaf 2);Composite subTree new Composite();subTree.add(new Leaf(SubTree Leaf 1));root.add(leaf1);root.add(leaf2);root.add(subTree);root.operation(); // 遍历树形结构} }Decorator 动态扩展功能装饰器模式可以在运行时动态地给对象添加新的功能而不改变原有类的代码。 增加灵活性通过装饰器可以为对象添加多种功能客户端可以根据需求进行组合增加了系统的灵活性。 符合开放/关闭原则装饰器通过扩展功能而不是修改类本身符合开放/关闭原则。 Decorator装饰器设计模式 递归聚合接口 “对不同物品可以进行不同装饰” “两组抽象和实现。 装饰器里有【具体部件】和新的方法”
// 抽象组件饮料 interface Beverage {String getDescription();double cost(); }// 具体组件 class Coffee implements Beverage {public String getDescription() {return Coffee;}public double cost() {return 5.0;} }// 装饰器 abstract class AddOnDecorator implements Beverage {protected Beverage beverage;public AddOnDecorator(Beverage beverage) {this.beverage beverage;} }class Milk extends AddOnDecorator {public Milk(Beverage beverage) {super(beverage);}public String getDescription() {return beverage.getDescription() , Milk;}public double cost() {return beverage.cost() 1.0;} }class Sugar extends AddOnDecorator {public Sugar(Beverage beverage) {super(beverage);}public String getDescription() {return beverage.getDescription() , Sugar;}public double cost() {return beverage.cost() 0.5;} }// 客户端代码 public class DecoratorExample {public static void main(String[] args) {Beverage beverage new Coffee();beverage new Milk(beverage);beverage new Sugar(beverage);System.out.println(beverage.getDescription() costs beverage.cost());} }Facade 简化接口外观模式为复杂子系统提供了一个统一的、高层的接口简化了客户端的调用方式。 降低耦合客户端不需要了解各个子系统的实现细节只需要与外观类交互从而降低了系统的耦合度。 便于扩展如果需要修改子系统的实现可以在外观类中进行修改而不影响客户端代码。 Façade门面设计模式 关联的集合 “将各个组件集成在一起”
class CPU {public void start() {System.out.println(CPU started.);} }class Memory {public void load() {System.out.println(Memory loaded.);} }class HardDrive {public void readData() {System.out.println(HardDrive read data.);} }// 门面类 class ComputerFacade {private CPU cpu;private Memory memory;private HardDrive hardDrive;public ComputerFacade() {this.cpu new CPU();this.memory new Memory();this.hardDrive new HardDrive();}public void start() {cpu.start();memory.load();hardDrive.readData();} }// 客户端代码 public class FacadeExample {public static void main(String[] args) {ComputerFacade computer new ComputerFacade();computer.start(); // 一键启动} }Flyweight 内存优化享元模式通过共享相同的对象实例减少了内存的消耗尤其适用于大量相似对象的场景。 提高性能由于共享对象的使用可以减少对象的创建和销毁提高了系统的性能。 Flyweight享元设计模式 关联的集合 “共享的懒汉模式”
// 抽象享元 interface Shape {void draw(); }// 具体享元 class Circle implements Shape {private String color;public Circle(String color) {this.color color;}public void draw() {System.out.println(Drawing color Circle);} }// 享元工厂 class ShapeFactory {private static MapString, Shape shapeMap new HashMap();public static Shape getCircle(String color) {if (!shapeMap.containsKey(color)) {shapeMap.put(color, new Circle(color));System.out.println(Created new color Circle);}return shapeMap.get(color);} }// 客户端代码 public class FlyweightExample {public static void main(String[] args) {Shape redCircle ShapeFactory.getCircle(Red);Shape blueCircle ShapeFactory.getCircle(Blue);Shape anotherRedCircle ShapeFactory.getCircle(Red);redCircle.draw();blueCircle.draw();anotherRedCircle.draw(); // 复用红色圆} }Proxy 控制访问代理模式可以控制对真实对象的访问例如延迟加载、权限控制、缓存等。 增强功能代理类可以为目标对象增加额外的功能比如日志记录、安全控制等而不需要修改目标对象的代码。 降低耦合代理类和目标类相互独立客户端通过代理类访问目标对象减少了对目标类的直接依赖。 Proxy代理设计模式 关联后抽象 “懒汉模式”
// 抽象接口 interface Image {void display(); }// 真实类 class RealImage implements Image {private String fileName;public RealImage(String fileName) {this.fileName fileName;loadFromDisk();}private void loadFromDisk() {System.out.println(Loading fileName);}public void display() {System.out.println(Displaying fileName);} }// 代理类 class ProxyImage implements Image {private RealImage realImage;private String fileName;public ProxyImage(String fileName) {this.fileName fileName;}public void display() {if (realImage null) {realImage new RealImage(fileName); // 延迟加载}realImage.display();} }// 客户端代码 public class ProxyExample {public static void main(String[] args) {Image image new ProxyImage(test.jpg);image.display(); // 加载并显示image.display(); // 再次显示无需加载} }
- 上一篇: 网站恶意点击软件厦门35网站建设公司
- 下一篇: 网站二次开发多少钱微信运营模式
相关文章
-
网站恶意点击软件厦门35网站建设公司
网站恶意点击软件厦门35网站建设公司
- 技术栈
- 2026年04月20日
-
网站多长时间到期vue可以做pc的网站
网站多长时间到期vue可以做pc的网站
- 技术栈
- 2026年04月20日
-
网站多语言界面建设方案wordpress改google字体
网站多语言界面建设方案wordpress改google字体
- 技术栈
- 2026年04月20日
-
网站二次开发多少钱微信运营模式
网站二次开发多少钱微信运营模式
- 技术栈
- 2026年04月20日
-
网站二次开发合同网站建设项目招标书
网站二次开发合同网站建设项目招标书
- 技术栈
- 2026年04月20日
-
网站二级目录怎么做长沙房产交易中心官网
网站二级目录怎么做长沙房产交易中心官网
- 技术栈
- 2026年04月20日






