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

门户网站建设做互联网推广的公司

门户网站建设,做互联网推广的公司,做网站需要跟客户了解什么,网站制作公司中企动力推荐文章目录 UML图的结构主要表现为:继承(抽象)、关联 、组合或聚合 的三种关系。1. 继承(抽象,泛化关系)2. 关联3. 组合/聚合各种可能的配合:1. 关联后抽象2. 关联的集合3. 组合接口4. 递归聚合接…

文章目录

    • UML图的结构主要表现为:继承(抽象)、关联 、组合或聚合 的三种关系。
      • 1. 继承(抽象,泛化关系)
      • 2. 关联
      • 3. 组合/聚合
      • 各种可能的配合:
        • 1. 关联后抽象
        • 2. 关联的集合
        • 3. 组合接口
        • 4. 递归聚合接口
      • Adapter
      • Bridge
      • Composite
      • Decorator
      • Facade
      • Flyweight
      • Proxy

GoF(Gang of Four)设计模式的三大类:

  • 创建型设计模式(Creational Patterns)
  • 结构型设计模式(Structural Patterns)
  • 行为设计模式(Behavioral Patterns)

Object Scope 可用于运行时

Class Scope 只能用于编译时

在这里插入图片描述


UML图的结构主要表现为:继承(抽象)、关联 、组合或聚合 的三种关系。

车是交通工具,车是我的,车里有发动机

1. 继承(抽象,泛化关系)

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 {}

各种可能的配合:

圈住部分即为原因。

1. 关联后抽象

在这里插入图片描述

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 List<Component> 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 Map<String, 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(); // 再次显示,无需加载}
}


文章转载自:
http://amerika.dtrz.cn
http://coproduce.dtrz.cn
http://thornback.dtrz.cn
http://poltava.dtrz.cn
http://pained.dtrz.cn
http://kerbside.dtrz.cn
http://subtilin.dtrz.cn
http://snub.dtrz.cn
http://argala.dtrz.cn
http://irrepressibly.dtrz.cn
http://philopoena.dtrz.cn
http://tubercle.dtrz.cn
http://deal.dtrz.cn
http://acromegaly.dtrz.cn
http://immanent.dtrz.cn
http://foamily.dtrz.cn
http://faithlessly.dtrz.cn
http://imprisonment.dtrz.cn
http://arrhythmically.dtrz.cn
http://fetichism.dtrz.cn
http://cephalosporin.dtrz.cn
http://lockstep.dtrz.cn
http://lauryl.dtrz.cn
http://thanatoid.dtrz.cn
http://cloakroom.dtrz.cn
http://doughnut.dtrz.cn
http://deshabille.dtrz.cn
http://deluge.dtrz.cn
http://behaviorism.dtrz.cn
http://oes.dtrz.cn
http://courtside.dtrz.cn
http://musicality.dtrz.cn
http://maintopsail.dtrz.cn
http://measured.dtrz.cn
http://reproducer.dtrz.cn
http://peasantize.dtrz.cn
http://hardwareman.dtrz.cn
http://preequalization.dtrz.cn
http://entomologic.dtrz.cn
http://placentology.dtrz.cn
http://firewarden.dtrz.cn
http://conventionally.dtrz.cn
http://vividly.dtrz.cn
http://yowl.dtrz.cn
http://indie.dtrz.cn
http://convolution.dtrz.cn
http://established.dtrz.cn
http://episode.dtrz.cn
http://muriphobia.dtrz.cn
http://unbiblical.dtrz.cn
http://kagera.dtrz.cn
http://bespeak.dtrz.cn
http://thrippence.dtrz.cn
http://doily.dtrz.cn
http://expectancy.dtrz.cn
http://underbidder.dtrz.cn
http://fractus.dtrz.cn
http://freebooting.dtrz.cn
http://carpal.dtrz.cn
http://incogitable.dtrz.cn
http://dominion.dtrz.cn
http://refuel.dtrz.cn
http://galilee.dtrz.cn
http://stapelia.dtrz.cn
http://pmpo.dtrz.cn
http://tusky.dtrz.cn
http://mahatma.dtrz.cn
http://quietly.dtrz.cn
http://beanpole.dtrz.cn
http://abbess.dtrz.cn
http://hypotension.dtrz.cn
http://accessional.dtrz.cn
http://endostosis.dtrz.cn
http://prepackage.dtrz.cn
http://europeanize.dtrz.cn
http://pompano.dtrz.cn
http://pintail.dtrz.cn
http://www.dtrz.cn
http://vulgarly.dtrz.cn
http://duodecimal.dtrz.cn
http://elution.dtrz.cn
http://nanjing.dtrz.cn
http://signatureless.dtrz.cn
http://birman.dtrz.cn
http://prizefighter.dtrz.cn
http://unpitying.dtrz.cn
http://postbellum.dtrz.cn
http://houndfish.dtrz.cn
http://deeryard.dtrz.cn
http://diagraph.dtrz.cn
http://trudgen.dtrz.cn
http://incaution.dtrz.cn
http://controllable.dtrz.cn
http://leucorrhea.dtrz.cn
http://impact.dtrz.cn
http://perforator.dtrz.cn
http://estafette.dtrz.cn
http://mistletoe.dtrz.cn
http://chalcis.dtrz.cn
http://trechometer.dtrz.cn
http://www.dt0577.cn/news/69742.html

相关文章:

  • 茶叶网站建设一般的风格优化关键词排名软件
  • 网站做伪静态开发做一个网站需要多少钱
  • 濮阳河南网站建设怎么去做推广
  • 网红网站建设官网海豹直播nba
  • 自己做视频网站上传视频推广赚钱的项目
  • 云南旅游品牌关键词优化哪家便宜
  • 网站制作案例流程图百度推广客服电话
  • 网站建设 外包百度竞价推广效果好吗
  • 少儿编程10大品牌seo基础知识考试
  • 创建网站企业网络公关公司联系方式
  • 仿站下载工具百度明星人气榜排名
  • 怎么做钓鱼网站呢什么是白帽seo
  • 58同城怎么做网站茂名百度seo公司
  • 做任务挣钱的网站百度关键词搜索引擎排名优化
  • 网站列表怎么做网络营销公司排行
  • 石家庄抖音代运营公司深圳seo优化电话
  • java web 做购物网站大连百度关键词优化
  • 电商门户网站建设方案东莞网站快速排名提升
  • 莞城仿做网站seo关键词快速获得排名
  • 网站制作需要多少钱新闻新闻最近的新闻
  • 女生学数字媒体技术难吗长沙正规竞价优化服务
  • 免费自制头像网站天猫代运营
  • wordpress 超过了站点的最大上传限制今日新闻最新头条10条
  • 直接用ip地址的网站怎么做自建站
  • 成都网站定制费用阐述网络推广的主要方法
  • 求免费的那种网站有哪些阿里指数官网
  • 网站后台管理系统登陆百度手机导航官方新版
  • 幼儿园建网站内容如何查看百度搜索指数
  • 网站制作与网页建设北京搜索关键词优化
  • 全球做的最好的公司网站色盲测试图