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

使用dw如何给网站做电影内网网站建设的步骤过程

使用dw如何给网站做电影,内网网站建设的步骤过程,齐河网站建设价格,网站空间租用合同装饰器模式#xff08;Decorator Pattern#xff09; 装饰器模式#xff08;Decorator Pattern#xff09;是一种结构型设计模式#xff0c;它允许向一个现有的对象添加新的功能#xff0c;同时又不改变其结构。装饰器模式通过创建一个装饰类来包装原有的类#xff0c;…装饰器模式Decorator Pattern 装饰器模式Decorator Pattern是一种结构型设计模式它允许向一个现有的对象添加新的功能同时又不改变其结构。装饰器模式通过创建一个装饰类来包装原有的类并在保留原有类的接口的情况下提供额外的功能。 装饰器模式的应用场景 在不影响其他对象的情况下以动态、透明的方式给单个对象添加职责如给一个图形对象添加边框、颜色等属性。当不能采用生成子类的方法进行扩展时如有大量独立的扩展或扩展是动态的。 装饰器模式的实现方式 1. 传统实现方式 思想通过定义一个抽象的组件类所有的具体组件和装饰类都继承自该组件类。装饰类包含一个组件对象并在调用其方法前后进行增强。 实现方式 // 抽象组件 abstract class Component {public abstract void operation(); }// 具体组件 class ConcreteComponent extends Component {public void operation() {System.out.println(ConcreteComponent operation);} }// 抽象装饰类 abstract class Decorator extends Component {protected Component component;public Decorator(Component component) {this.component component;}public void operation() {component.operation();} }// 具体装饰类A class ConcreteDecoratorA extends Decorator {public ConcreteDecoratorA(Component component) {super(component);}public void operation() {super.operation();addedBehavior();}public void addedBehavior() {System.out.println(ConcreteDecoratorA added behavior);} }// 具体装饰类B class ConcreteDecoratorB extends Decorator {public ConcreteDecoratorB(Component component) {super(component);}public void operation() {super.operation();addedBehavior();}public void addedBehavior() {System.out.println(ConcreteDecoratorB added behavior);} }// 客户端代码 public class DecoratorPattern {public static void main(String[] args) {Component component new ConcreteComponent();Component decoratorA new ConcreteDecoratorA(component);Component decoratorB new ConcreteDecoratorB(decoratorA);decoratorB.operation();} }优点 可以动态地添加和删除对象的职责比静态继承更加灵活。通过使用不同的具体装饰类以及这些装饰类的排列组合可以创造出很多不同行为的组合。符合开闭原则可以在不修改原有代码的情况下扩展对象的新功能。 缺点 会产生许多小对象增加了系统的复杂性。多层装饰时会增加调试的难度特别是出现问题时难以找到问题所在。 2. 使用接口实现装饰器模式 思想通过定义一个接口所有的具体组件和装饰类都实现该接口装饰类包含一个接口类型的对象并在调用其方法前后进行增强。 实现方式 // 抽象组件接口 interface Component {void operation(); }// 具体组件 class ConcreteComponent implements Component {public void operation() {System.out.println(ConcreteComponent operation);} }// 抽象装饰类 abstract class Decorator implements Component {protected Component component;public Decorator(Component component) {this.component component;}public void operation() {component.operation();} }// 具体装饰类A class ConcreteDecoratorA extends Decorator {public ConcreteDecoratorA(Component component) {super(component);}public void operation() {super.operation();addedBehavior();}public void addedBehavior() {System.out.println(ConcreteDecoratorA added behavior);} }// 具体装饰类B class ConcreteDecoratorB extends Decorator {public ConcreteDecoratorB(Component component) {super(component);}public void operation() {super.operation();addedBehavior();}public void addedBehavior() {System.out.println(ConcreteDecoratorB added behavior);} }// 客户端代码 public class InterfaceDecoratorPattern {public static void main(String[] args) {Component component new ConcreteComponent();Component decoratorA new ConcreteDecoratorA(component);Component decoratorB new ConcreteDecoratorB(decoratorA);decoratorB.operation();} }优点 接口使得装饰类和具体组件更加解耦符合依赖倒置原则。接口可以更容易地进行单元测试和模拟对象。 缺点 同样会产生许多小对象增加系统复杂性。多层装饰时仍然会增加调试的难度。 总结 实现方式优点缺点传统实现方式动态添加和删除职责符合开闭原则行为组合多样化产生许多小对象系统复杂性增加多层装饰调试难度大使用接口实现装饰器模式解耦装饰类和具体组件符合依赖倒置原则易于单元测试和模拟对象产生许多小对象系统复杂性增加多层装饰调试难度大 选择哪种实现方式应根据具体的需求和系统的复杂度来决定。如果希望组件和装饰类之间更加解耦且易于测试可以选择使用接口实现装饰器模式。如果更关注具体类的扩展性和灵活性可以选择传统的实现方式。
http://www.hkea.cn/news/14348203/

相关文章:

  • 西安做网站湖南企业网络推广平台
  • 做服装的外贸网站手机门户网站建设
  • 网站响应式和非响应式wordpress修改邮箱文字
  • 建筑类企业网站模板成都网站优化多少钱
  • 长沙市建设厅官方网站定制网站建设需要多少钱
  • 做企业英语网站要注意哪些南宁小程序建设
  • 抚州做网站价格多少一个人看片免费高清
  • 网站现在怎么做排名互联网公司排名完整
  • 合肥建站网站模板引擎搜索器
  • 哪个软件做网站最简单虚拟主机发布网站吗
  • 哪些网站可以做邀请函茶叶网站建设网页设计制作
  • 网站建设公司专业网站费用报价中国商标网官网免费查询入口
  • 注册一个网站要多少钱珠海响应式网站建设价格
  • 网站开发人员 怎么保存深圳市市场监督管理局官网
  • 做网站推广代理适合女孩子的职校专业
  • 网站建设三种方法网站禁止ping
  • 用宝塔给远程网站做备份榆中县城乡建设局网站
  • 网站建设在阿里云做婚礼设计在哪个网站下载素材
  • 外贸推广免费网站创意灵感的网站
  • 制作网站公司图片濮阳网页设计
  • 怎样制作一个网站步骤学历提升机构
  • 做网站推广复杂吗Wordpress 微信 openid
  • 手机网站设计只找亿企邦成都设计公司地址
  • 做网站用小图标在什么网下载wordpress代码编辑插件
  • 网站策划的内容包含了什么?沭阳网站建设托管
  • 安徽网站建设价格企业网站建设需要注意什么
  • 周口微网站制作贵阳做网站的大公司
  • 精品网站欣赏WordPress已安装主题
  • 做网站都用什么工具方案案例网站
  • 万能建站网站asp网站发送邮件