![](https://img-blog.csdnimg.cn/20201014180756926.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
设计模式
czjuttsw
Learning, staying up to date, and working on the latest and greatest in languages and APIs is what keeps me excited.
展开
-
JDK中的设计模式之观察者模式
今天我们来学习下JDK中实现观察者模式的接口和类. 在观察者模式中,有观察者和被观察者两种角色。(有些也称为发布者和订阅者角色等。。) 观察者可以通过注册方式加入到被观察者之内(通常用一个容器实现), 当某种变化发生时,被观察者可以通知所有加入到该容器的观察者。 GOF是这样定义观察者模式(Observer pattern): Define a one-to-many depende原创 2012-10-22 19:08:46 · 1609 阅读 · 0 评论 -
软件设计三大原则
1. 面向接口编程,而不是面向实现编程 2. 组合优先于继承 3. 将经常变化的部分从不变的部分中分离出来 1. Identify the aspects of your application that vary and separate them from what stays the same 2. favor composition over inheritance原创 2013-01-22 15:07:18 · 2873 阅读 · 1 评论 -
java设计模式之模板方法模式
模板方法就是一个方法(通常为final,不允许子类进行覆盖),该方法包含了一个算法的各个步骤(每个步骤相当于一个方法),在模版方法内调用的方法中有抽象的(待子类覆盖),也有实例的。另外在模版方法所属类中可以包含一个钩子方法(hook),该方法可以控制模版方法中的逻辑,该方法提供默认的实现。子类不是必须实现它。下面给出一个具体的例子。 Beverage.java: package o原创 2013-01-21 22:28:11 · 2442 阅读 · 2 评论