Reading Head First Design Pattern note.
来源:互联网 发布:悦游网络加速器官方 编辑:程序博客网 时间:2024/05/15 05:17
*********************
The Open-Closed Principle
Design Principle
Classes should be open
for extension, but closed for
modification.
you’ll see a good example of using the
Decorator pattern to follow the Open-
Closed principle.
Decorators have the same supertype as the objects they decorate.
You can use one or more decorators to wrap an object.
Given that the decorator has the same supertype as the object it decorates, we can pass
around a decorated object in place of the original (wrapped) object.
The decorator adds its own behavior either before and/or after delegating 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 additional
responsibilities to an object dynamically.
Decorators provide a flexible alternative to
subclassing for extending functionality.
(1) Each decorator HAS-A
(wraps) a component, which
means the decorator has an
instance variable that holds
a reference to a component.
(2)Decorators implement the
same interface or abstract
class as the component they
are going to decorate.
OO Principles
Encapsulate what varies.
Favor composition over inheritance.
Program to interfaces, not
implementations.
Strive for loosely coupled designs
between objects that interact.
Classes should be open for
extension but closed for
modification.
All factory patterns encapsulate object creation. The Factory Method Pattern encapsulates
object creation by letting subclasses decide what objects to create.Let's check out these
class diagrams to see who the players are in this pattern.
***The Factory Method Pattern*** defines an interface for creating an object,
but lets subclasses decide which
class to instantiate.Factory Method lets a class defer instantiation to subclasses.
***The Dependency Inversion Principle***
Design Principle
Depend upon abstractions.Do not depend upon concrete classes.
At first,this principle sounds a lot like "Program to an interface,not an implementation," right?
It is similar;however,the Dependency Inversion Principle makes an even stronger statement
about abstraction.It suggests that our high-level components should not depend on our low-level
components;rather, they should both depend on abstractions.
Abstract Factory Pattern :provides an interface for creating families of related or dependent objects
without specifying their concrete classes.
The Singleton Pattern :ensures a class has only one instance,and provides a global point of access to it.
- Reading Head First Design Pattern note.
- head first - design pattern
- Head First Design Pattern读后感
- head first-----decorate design pattern
- head first---------facade design pattern
- head first---------composite design pattern
- Head First Design pattern Observer
- Book Review about Head First Design Pattern
- C++版的Head First Design Pattern
- head first design pattern 学习笔记
- 《Head First Design Pattern 》--设计模式 读书笔记
- Head First Design Pattern - 学习笔记
- 《Head First Design Pattern》读后感-----设计模式
- head first design pattern笔记整理
- Head First Design Pattern读书笔记一 Strategy Pattern
- Head First Design Pattern读书笔记二 Observer Pattern
- Head First Design Pattern读书笔记之三 Decorator Pattern
- Adapter Pattern——Head First Design Pattern
- Google员工总数增至1.6万人 人人持有股份
- PSP实况足球WE2008操作技术和按键说明
- 三个月打通你的听力和口语
- Java调用存储过程
- 什么是ISAPI
- Reading Head First Design Pattern note.
- C# 中的类型转换
- ASP.NET AJAX Extensions 学习笔记之下载安装
- 谁将主宰手机操作系统市场?
- 网站设计中43个你应当避免的错误
- Memory Hacking Software 4.0.0.14 by L. Spiro
- 婚礼一站式服务 与 虚拟婚礼
- ASP文件上传原理分析及实现实例
- McAfee防火墙导致Jmail发邮件失败的解决方法