剑花 烟雨

   江南  好 风景旧曾谙 日出江花红胜火 春来江水绿如蓝 能不忆东北

理想中的建筑师应该是一个诗人、数学家、精通历史、精通心理学、熟悉音乐、了解医学、还要具备天文学和计算的基本知识。
                                                                                                                         ------------------公元前25年,罗马建筑学家Vitruvius
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

The Decorator Pattern

Posted on 2007-04-19 15:16  落花人独立  阅读(357)  评论(4编辑  收藏  举报

The Open-Closed Principle
      Calsses should be open for extension,but closed for modification.
      Our goal is to allow classes to be easily extended to incorperate new behavior without modifying exsiting code.Following the Open-Closed Principle usually introduces new levels of abstraction,which adds complexity to our code.You want to concentrate on those areas that are most likely to change in your designs and apply the principles there.Experience in designing OO systems and a matter of knowing the  domain is helpful to you.

  • Decorators have the same supertype as the objects they decorate.
  • You can use one or more decorators to wrap and object.
  • Given that the decorator has the same supertype as the ojbect it decorates,we can pass around a decorated ojbect in place of the original (wrapped) object.
  • The decorator adds its own behavior either before and/or after delgating to the object it decorates to do the rest of the job.
  • Objects can be decorated  at any time ,so we can decorate objects dynamically at runtime with as many decorators as we like.

The Decorator Pattern attaches addtional responsibility to an object dynamically.Decorators provide a fexible alternative to subclassing for extending functionally.


count hit
欢迎您到紫阁阳光坐客