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

网站建设框架编写目的友情链接英语

网站建设框架编写目的,友情链接英语,网站首页phpcms怎么添加,网站最佳颜色搭配结构者模式(Structural Design Patterns)指的是一组设计模式,旨在帮助设计者将对象或类组合成更大的结构,以便于形成更复杂的系统。这些模式关注如何将对象或类组织起来,以构建更大的结构或系统。主要目的是提高系统的…

结构者模式(Structural Design Patterns)指的是一组设计模式,旨在帮助设计者将对象或类组合成更大的结构,以便于形成更复杂的系统。这些模式关注如何将对象或类组织起来,以构建更大的结构或系统。主要目的是提高系统的灵活性和可维护性。

常见的结构者模式包括:

  1. 适配器模式(Adapter Pattern)
  2. 桥接模式(Bridge Pattern)
  3. 组合模式(Composite Pattern)
  4. 装饰者模式(Decorator Pattern)
  5. 外观模式(Facade Pattern)
  6. 享元模式(Flyweight Pattern)
  7. 代理模式(Proxy Pattern)

1. 适配器模式(Adapter Pattern)

目的:将一个类的接口转换成客户端所期望的另一个接口,使得原本接口不兼容的类可以协同工作。

结构

  • 目标接口(Target Interface):客户端期望的接口。
  • 适配者(Adaptee):已经存在的接口,接口与客户端的期望接口不兼容。
  • 适配器(Adapter):实现目标接口,并将客户端请求转发到适配者对象。

示例代码(Java)

 

java

复制代码

// 目标接口 interface Target { void request(); } // 适配者 class Adaptee { void specificRequest() { System.out.println("Specific request"); } } // 适配器 class Adapter implements Target { private Adaptee adaptee; public Adapter(Adaptee adaptee) { this.adaptee = adaptee; } @Override public void request() { adaptee.specificRequest(); } } // 客户端代码 public class Main { public static void main(String[] args) { Adaptee adaptee = new Adaptee(); Target target = new Adapter(adaptee); target.request(); } }

2. 桥接模式(Bridge Pattern)

目的:将抽象部分与实现部分分离,使得两者可以独立变化。

结构

  • 抽象类(Abstraction):定义抽象的接口。
  • 修正抽象类(RefinedAbstraction):扩展抽象类。
  • 实现接口(Implementor):定义实现类的接口。
  • 具体实现类(ConcreteImplementor):实现实现接口。

示例代码(Java)

 

java

复制代码

// 实现接口 interface Implementor { void operationImpl(); } // 具体实现类 class ConcreteImplementorA implements Implementor { @Override public void operationImpl() { System.out.println("ConcreteImplementorA operation"); } } // 抽象类 abstract class Abstraction { protected Implementor implementor; protected Abstraction(Implementor implementor) { this.implementor = implementor; } abstract void operation(); } // 修正抽象类 class RefinedAbstraction extends Abstraction { protected RefinedAbstraction(Implementor implementor) { super(implementor); } @Override void operation() { implementor.operationImpl(); } } // 客户端代码 public class Main { public static void main(String[] args) { Implementor impl = new ConcreteImplementorA(); Abstraction abs = new RefinedAbstraction(impl); abs.operation(); } }

3. 组合模式(Composite Pattern)

目的:允许客户以一致的方式处理单个对象和对象集合。

结构

  • 组件接口(Component):声明叶子和容器的共同接口。
  • 叶子(Leaf):实现组件接口,表示树的叶节点。
  • 容器(Composite):实现组件接口,表示树的节点,包含子组件。

示例代码(Java)

 

java

复制代码

import java.util.ArrayList; import java.util.List; // 组件接口 interface Component { void operation(); } // 叶子 class Leaf implements Component { @Override public void operation() { System.out.println("Leaf operation"); } } // 容器 class Composite implements Component { private List<Component> children = new ArrayList<>(); void add(Component component) { children.add(component); } void remove(Component component) { children.remove(component); } @Override public void operation() { for (Component child : children) { child.operation(); } } } // 客户端代码 public class Main { public static void main(String[] args) { Component leaf1 = new Leaf(); Component leaf2 = new Leaf(); Composite composite = new Composite(); composite.add(leaf1); composite.add(leaf2); composite.operation(); } }

4. 装饰者模式(Decorator Pattern)

目的:动态地给对象添加功能,不改变其结构。

结构

  • 组件接口(Component):定义对象的接口。
  • 具体组件(ConcreteComponent):实现组件接口的基本对象。
  • 装饰器(Decorator):持有一个组件对象的引用,并提供相同的接口。
  • 具体装饰器(ConcreteDecorator):扩展装饰器,添加额外的功能。

示例代码(Java)

 

java

复制代码

// 组件接口 interface Component { void operation(); } // 具体组件 class ConcreteComponent implements Component { @Override public void operation() { System.out.println("ConcreteComponent operation"); } } // 装饰器 abstract class Decorator implements Component { protected Component component; protected Decorator(Component component) { this.component = component; } @Override public void operation() { component.operation(); } } // 具体装饰器 class ConcreteDecorator extends Decorator { public ConcreteDecorator(Component component) { super(component); } @Override public void operation() { super.operation(); additionalOperation(); } private void additionalOperation() { System.out.println("ConcreteDecorator additional operation"); } } // 客户端代码 public class Main { public static void main(String[] args) { Component component = new ConcreteComponent(); Component decorator = new ConcreteDecorator(component); decorator.operation(); } }

5. 外观模式(Facade Pattern)

目的:为复杂子系统提供一个统一的接口,使得子系统更易于使用。

结构

  • 外观类(Facade):提供一个简单接口,隐藏子系统的复杂性。
  • 子系统类(Subsystem):复杂的子系统类,提供具体功能。

示例代码(Java)

 

java

复制代码

// 子系统类 class SubsystemA { void operationA() { System.out.println("SubsystemA operation"); } } class SubsystemB { void operationB() { System.out.println("SubsystemB operation"); } } // 外观类 class Facade { private SubsystemA subsystemA = new SubsystemA(); private SubsystemB subsystemB = new SubsystemB(); void operation() { subsystemA.operationA(); subsystemB.operationB(); } } // 客户端代码 public class Main { public static void main(String[] args) { Facade facade = new Facade(); facade.operation(); } }

6. 享元模式(Flyweight Pattern)

目的:通过共享对象来减少内存消耗,提高效率。

结构

  • 享元接口(Flyweight):声明操作方法。
  • 具体享元(ConcreteFlyweight):实现享元接口,处理共享的状态。
  • 享元工厂(FlyweightFactory):管理享元对象的创建和共享。

示例代码(Java)

 

java

复制代码

import java.util.HashMap; import java.util.Map; // 享元接口 interface Flyweight { void operation(String extrinsicState); } // 具体享元 class ConcreteFlyweight implements Flyweight { private String intrinsicState; public ConcreteFlyweight(String intrinsicState) { this.intrinsicState = intrinsicState; } @Override public void operation(String extrinsicState) { System.out.println("Intrinsic State: " + intrinsicState + ", Extrinsic State: " + extrinsicState); } } // 享元工厂 class FlyweightFactory { private Map<String, Flyweight> flyweights = new HashMap<>(); Flyweight getFlyweight(String intrinsicState) { if (!flyweights.containsKey(intrinsicState)) { flyweights.put(intrinsicState, new ConcreteFlyweight(intrinsicState)); } return flyweights.get(intrinsicState); } } // 客户端代码 public class Main { public static void main(String[] args) { FlyweightFactory factory = new FlyweightFactory(); Flyweight flyweight1 = factory.getFlyweight("StateA"); flyweight1.operation("ExtrinsicA"); Flyweight flyweight2 = factory.getFlyweight("StateA"); flyweight2.operation("ExtrinsicB"); Flyweight flyweight3 = factory.getFlyweight("StateB"); flyweight3.operation("ExtrinsicC"); } }

7. 代理模式(Proxy Pattern)

目的:为其他对象提供一种代理以控制对该对象的访问。

结构

  • 抽象主题(Subject):定义真实对象和代理对象的共同接口。
  • 真实主题(RealSubject):实际实现对象的类。
  • 代理(Proxy):持有对真实主题对象的引用,并控制对它的访问。

示例代码(Java)

 

java

复制代码

// 抽象主题 interface Subject { void request(); } // 真实主题 class RealSubject implements Subject { @Override public void request() { System.out.println("RealSubject request"); } } // 代理 class Proxy implements Subject { private RealSubject realSubject; @Override public void request() { if (realSubject == null) { realSubject = new RealSubject(); } System.out.println("Proxy request"); realSubject.request(); } } // 客户端代码 public class Main { public static void main(String[] args) { Subject proxy = new Proxy(); proxy.request(); } }

总结

结构者模式帮助我们以不同的方式组织和构建系统中的类和对象,从而提高系统的灵活性和可维护性。通过合理选择和应用这些模式,可以有效地管理和扩展系统的复杂性。

http://www.dtcms.com/wzjs/57575.html

相关文章:

  • 案例较少如何做设计公司网站网上商城建设
  • 上海做网站的小公司有哪些被忽悠去做网销了
  • 重庆綦江网站制作公司推荐免费b站推广
  • 监控网站开发湖南长沙seo
  • 网站制作知名公司传智播客培训机构官网
  • 如果盗用网站模板杭州优化商务服务公司
  • 中山网站设计公司英雄联盟更新公告最新
  • 做网站用什么团建广州网络seo优化
  • 北京b2c网站建设百度信息流广告
  • 海南免费做网站搜索引擎优化策略不包括
  • 如皋网站制作营销推广的工具有哪些
  • 网站开发中常用的技术和工具长沙网站推广公司排名
  • 襄垣城乡建设管理局的网站营业推广经典案例
  • 做期货黄金哪个网站信息数据准cba目前排行
  • 财务网站模板厦门seo小谢
  • 帮企网站建设代运营百度手机浏览器
  • 网站营销单页怎么做杭州网站优化搜索
  • 网站建设与维护课件提升seo搜索排名
  • 天津市工程信息网谷歌搜索优化
  • 网站建设3d插件培训总结精辟句子
  • 大学生做网上英语翻译兼职网站网络推广一般怎么收费
  • 江苏赛华建设监理有限公司网站优化seo招聘
  • 签约网站做PPT怎样制作属于自己的网站
  • 网页布局实训心得体会太原建站seo
  • 一般建设一个网站多少钱优化推广
  • 营销型商务网站应用商店下载
  • 做外贸没有网站需要注意什么问题厦门最快seo
  • 公司邮箱怎么注册流程黑帽seo优化软件
  • 家具网站建设规划书国内最好的搜索引擎
  • 怎么推广自己做的网站吗2020国内搜索引擎排行榜