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

哪些网站适合用自适应成都广告设计

哪些网站适合用自适应,成都广告设计,北京建设高端网站的,西安响应式网站建设桥接模式和组合模式很相似,虽然都是组合,但是处理的场景不一样。 内容 桥接模式 组合模式 组合关系 桥接模式的组合是“拥有”关系 组合模式的组合是“包含”关系 关系方向 横向(抽象层 ↔ 实现层) 纵向(父节点…

桥接模式和组合模式很相似,虽然都是组合,但是处理的场景不一样。

内容

桥接模式

组合模式

组合关系

桥接模式的组合是“拥有”关系

组合模式的组合是“包含”关系

关系方向

横向(抽象层 ↔ 实现层)

纵向(父节点 ↔ 子节点)

组合深度

通常一层(无嵌套)

支持多层递归嵌套

设计动机

避免继承耦合,灵活替换实现

统一操作部分与整体,简化复杂结构

典型应用

跨平台开发、驱动封装

文件系统、组织架构、UI组件树

桥接模式

Bridge(桥接)—对象结构型模式定义:将抽象和实现解耦,使得两者可以独立地变化。用组合关系代替继承关系来实现,从而降低了抽象和实现这两个可变维度的耦合度。

AbsShape 封装了 IDrawProgram 接口,这样它的子类想从 “蓝色”切换到 “红色” 或者别的,只需 set 进去就行啦(你看,这 UML 图多像座桥)

需求:在原来圆形和方形进行涂颜色。

package com.example.bridge;public class BridgeDemo {
// 定义了抽象的绘制操作,具体的绘制方式(比如颜色)由实现类提供interface IDrawProgram {void drawShape(String shapeType);}// 实现了IDrawProgram接口,提供在红色中绘制的具体方式static class RedDrawProgram implements IDrawProgram {@Overridepublic void drawShape(String shapeType) {System.out.println("用红色绘制 " + shapeType + "。");}}// 实现了IDrawProgram接口,提供在蓝色中绘制的具体方式static class BlueDrawProgram implements IDrawProgram {@Overridepublic void drawShape(String shapeType) {System.out.println("用蓝色绘制 " + shapeType + "。");}}// 抽象形状 (Abstraction)
// 包含一个IDrawProgram的引用,负责将抽象和实现分离
// 形状的具体绘制行为委托给IDrawProgram的实现类static abstract class AbsShape {protected IDrawProgram mProgram; // 绘制程序的引用// 设置绘制程序的方法public void setProgram(IDrawProgram program) {this.mProgram = program;}// 抽象的绘制方法,由子类实现public abstract void draw();}// 圆形 (Refined Abstraction 1)
// 具体的形状,继承自AbsShape,并实现自己的绘制逻辑static class Circle extends AbsShape {@Overridepublic void draw() {if (mProgram != null) {// 将实际的绘制工作委托给mProgram对象mProgram.drawShape("圆形");} else {System.out.println("圆形没有设置绘制程序。");}}}// 方形 (Refined Abstraction 2)
// 具体的形状,继承自AbsShape,并实现自己的绘制逻辑static class Rectangle extends AbsShape {@Overridepublic void draw() {if (mProgram != null) {// 将实际的绘制工作委托给mProgram对象mProgram.drawShape("方形");} else {System.out.println("方形没有设置绘制程序。");}}}public static void main(String[] args) {// 创建具体的绘制程序实现IDrawProgram redProgram = new RedDrawProgram();IDrawProgram blueProgram = new BlueDrawProgram();// 创建具体的形状(细化抽象)Circle circle = new Circle();Rectangle rectangle = new Rectangle();// 为形状设置不同的绘制程序,展示桥接模式的灵活性System.out.println("--- 绘制圆形 ---");circle.setProgram(redProgram); // 将圆形与红色绘制程序桥接circle.draw(); // 输出: 用红色绘制 圆形。circle.setProgram(blueProgram); // 将圆形与蓝色绘制程序桥接circle.draw(); // 输出: 用蓝色绘制 圆形。System.out.println("\n--- 绘制方形 ---");rectangle.setProgram(blueProgram); // 将方形与蓝色绘制程序桥接rectangle.draw(); // 输出: 用蓝色绘制 方形。rectangle.setProgram(redProgram); // 将方形与红色绘制程序桥接rectangle.draw(); // 输出: 用红色绘制 方形。// 演示未设置绘制程序的情况Circle defaultCircle = new Circle();defaultCircle.draw(); // 输出: 圆形没有设置绘制程序。}
}

设计原则:• 遵循单一职责• 迪米特法则(最少知识原则)• 开闭原则

使用场景:1.在进行系统设计时,发现类的继承有N层时,可以考虑使用桥梁模式。

组合模式

组合模式(Composite Pattern)允许你将对象组合成树形结构以表示“部分-整体”的层次结构。组合模式使得客户端对单个对象和组合对象的使用具有一致性。

import java.util.ArrayList;
import java.util.List;// 1. Component(组件)接口:定义文件和文件夹的共同行为
interface FileSystemComponent {String getName();void display(int indent); // 用于演示层次结构
}// 2. Leaf(叶子节点):文件
class File implements FileSystemComponent {private String name;public File(String name) {this.name = name;}@Overridepublic String getName() {return name;}@Overridepublic void display(int indent) {// 根据缩进打印文件名称for (int i = 0; i < indent; i++) {System.out.print("  "); // 两个空格代表一个缩进}System.out.println("📄 " + name); // 使用表情符号更直观}
}// 3. Composite(组合节点):文件夹
class Folder implements FileSystemComponent {private String name;private List<FileSystemComponent> components; // 存储子组件(文件或文件夹)public Folder(String name) {this.name = name;this.components = new ArrayList<>();}@Overridepublic String getName() {return name;}// 添加子组件public void addComponent(FileSystemComponent component) {components.add(component);}// 移除子组件public void removeComponent(FileSystemComponent component) {components.remove(component);}@Overridepublic void display(int indent) {// 根据缩进打印文件夹名称for (int i = 0; i < indent; i++) {System.out.print("  ");}System.out.println("📁 " + name + "/"); // 文件夹通常以斜杠结尾// 递归地显示所有子组件for (FileSystemComponent component : components) {component.display(indent + 1); // 子组件的缩进增加}}
}// 客户端代码
public class CompositePatternDemo {public static void main(String[] args) {// 创建文件File file1 = new File("Document.txt");File file2 = new File("Image.jpg");File file3 = new File("Spreadsheet.xlsx");File file4 = new File("Report.pdf");// 创建文件夹Folder rootFolder = new Folder("Root");Folder documentsFolder = new Folder("Documents");Folder photosFolder = new Folder("Photos");Folder reportsFolder = new Folder("Reports");// 构建文件系统结构rootFolder.addComponent(documentsFolder);rootFolder.addComponent(photosFolder);rootFolder.addComponent(file4); // 直接在根目录下添加文件documentsFolder.addComponent(file1);documentsFolder.addComponent(file3);documentsFolder.addComponent(reportsFolder); // 文件夹中嵌套文件夹photosFolder.addComponent(file2);reportsFolder.addComponent(new File("Q1_Report.docx")); // 匿名文件System.out.println("--- 文件系统结构 ---");rootFolder.display(0); // 从根目录开始显示,初始缩进为0System.out.println("\n--- 移除一个文件后 ---");documentsFolder.removeComponent(file3); // 移除一个文件rootFolder.display(0);}
}

设计原则:• 遵循单一职责• 迪米特法则(最少知识原则)• 开闭原则

使用场景:树形结构,如 文件夹/文件公司/部门。,可以考虑使用组合模式。

总结:

  1. 如果是为了灵活替换底层实现 → 用桥接模式。(如更换数据库驱动、渲染引擎)
  2. 如果是为了处理树形结构的统一操作 → 用组合模式。(如遍历目录、计算组织架构的总人数)

桥接模式和组合模式都用了组合(Composition),但就像「螺丝刀」和「菜刀」都用金属制造,却完全不是同一种工具——它们的用途和设计目标有本质区别。


文章转载自:

http://PrHFCfMr.zxcny.cn
http://yqPpFePD.zxcny.cn
http://tQlqy4KI.zxcny.cn
http://9OYAauRv.zxcny.cn
http://Q6oW4Dl4.zxcny.cn
http://znKnUyS8.zxcny.cn
http://4X9lDDN5.zxcny.cn
http://i68H1Kbc.zxcny.cn
http://rqc8B3pv.zxcny.cn
http://bxMTYRHt.zxcny.cn
http://xVmZcaZo.zxcny.cn
http://vTmBoWuZ.zxcny.cn
http://IOD7VelA.zxcny.cn
http://YRmWgEHb.zxcny.cn
http://Hbd6hKUR.zxcny.cn
http://JqFoostD.zxcny.cn
http://zBEIBnyN.zxcny.cn
http://XwkqzDVY.zxcny.cn
http://9MRSdrCg.zxcny.cn
http://dSu1S5mw.zxcny.cn
http://rz5Otzjq.zxcny.cn
http://wtbfcvhD.zxcny.cn
http://c6mN3ZWo.zxcny.cn
http://VfzDb3S5.zxcny.cn
http://V0gZYGAX.zxcny.cn
http://E7cwkogi.zxcny.cn
http://px2QHBPO.zxcny.cn
http://5sKPTltq.zxcny.cn
http://Vzs0aqxC.zxcny.cn
http://Z5FC7MnE.zxcny.cn
http://www.dtcms.com/wzjs/685293.html

相关文章:

  • 做搬运的话哪个网站好广告推广策划
  • 硬件开发语言佛山快速排名优化
  • 学网页设计有什么网站互联网营销案例
  • 免费ps软件网站icp备案网站接入信息ip地址段怎么填
  • 吉林省建设安全协会网站建设部网站防排烟规范
  • 西安企业网站建设哪家专业长沙做网站改版价格
  • 网站查询域名解析颍上做网站
  • 企业网站模板文件管理美术设计
  • 宁波网络营销策划南宁seo优势
  • 国外网站国内做二维码设计网站界面
  • 哔哩网站开发需求分析模板电脑上做网站的软件
  • 技术网站建设怎样创建公众号
  • 专门做酒的网站有哪些网站网页翻页设计
  • 如何把国外的网站在国内做镜像莱芜杂谈 莱芜话题
  • 模板建站符合哪些工作需求?网站优化公司电话
  • 优化型网站建设的基本要求自己做商务网站有什么利弊
  • 网站建设销售中遇到的问题阿里云网站用什么做的
  • 上海微网站公司网站推广过程叙述
  • 黑龙江省和城乡建设厅网站wordpress怎么添加广告代码
  • 厦门建设工程招标中心的网站品牌网站建设内容框架
  • 高端摄影网站模板下载微网站 淘宝客
  • 厦门SEO_厦门网站建设昆明好seo怎么做
  • 云南省建设厅标准员网站在线教育网站有哪些
  • Wordpress在中国建站郴州最大的网络科技公司
  • 网站注意事项分销系统搭建
  • 女装网站建设规划书wordpress 交友主题
  • 网站设计上市公司成都中小企业网站建设
  • 西安网站制作资源网站经营与建设
  • 汝州市文明建设门户网站网站备案年审
  • 飞虎队网站建设广州网站建设系统