[Design Pattern] Substitute Interface】的更多相关文章

[Design Pattern] Substitute Interface 目的 将对象的成员建立为替身接口的成员,用来解耦对象之间的循环相依. 情景 假设开发人员接手一个系统,在系统里有订单对象.送货物件,其中订单对象使用送货物件所提供的送货方法. 当系统继续设计下去,会发现送货方法需要订单对象的相关信息才能决定如何送货.例如说:送货方法需要商品数量,来决定要派卡车送货还是要派机车送货:送货方法需要商品价格来决定要用盒子包还是要用纸袋包.当送货方法的逻辑越来越复杂的时候,最终就会发现送货方法需…
Bridge Pattern, Composite Pattern, Decorator Pattern, Facade Pattern, COR Pattern, Proxy Pattern, template Pattern, MVC. Updated with the explanation of Composite pattern, Decorator Pattern and Template Pattern. Design Pattern Interview Question - Pa…
Interpeter , Iterator , Mediator , Memento and Observer design patterns. (I) what is Interpreter pattern? (B) Can you explain iterator pattern? (A) Can you explain mediator pattern? (I) Can you explain memento pattern? (B) Can you explain observer pa…
State, Stratergy, Visitor Adapter and fly weight design pattern from interview perspective. (I) Can you explain state pattern? (I) Can you explain strategy pattern? (A) Can you explain visitor pattern? (A) What the difference between visitor and stra…
Factory, Abstract factory, prototype pattern (B) What are design patterns? (A) Can you explain factory pattern? (I) Can you explain abstract factory pattern? (I)Can you explain builder pattern? (I) Can you explain prototype pattern? (A) Can you expla…
为什么要提倡“Design Pattern呢?根本原因是为了代码复用,增加可维护性. 那么怎么才能实现代码复用呢?面向对象有几个原则:开闭原则(Open Closed Principle,OCP).里氏代换原则(Liskov Substitution Principle,LSP).依赖倒转原则(Dependency Inversion Principle,DIP).接口隔离原则(Interface Segregation Principle,ISP).合成/聚合复用原则(Composite/Ag…
什么是设计模式? design pattern是一个通用的,可以被重用的关于一个常见的问题的解决方案. 为什么要用设计模式? 引入设计模式的理论基础非常简单.我们每天都会碰到问题.我们可能碰到决定使用何种算法的问题,什么是最合适的design,使用什么技术,什么模块等等...同样种类的问题很有可能已经被我们的前辈所碰到,如果其他人已经碰到过我们的问题,那么他们已经有效解决了该问题是很有可能的.这样的话,我们最好直接借鉴别人已经成熟的解决方案,而不是从头来过. 然而,每一个问题都是唯一的,这样每一…
Asp.Net Design Pattern Studynotes -- Part1 let's start with an exampleto entry amazing OO world ! let's saynow we need to implement a small feature which need : an entityclass: Product businesslogic : List<Product>GetProductBy(Function<Product,bo…
Service Locator Pattern,即服务定位模式,用于定位不同的服务.考虑到 InitialContext::lookup 的成本比较高,提供了 Cache 类缓存以定位到的服务. 代码实现 Service 接口 public interface Service { public String getName(); public void execute(); } Service1, Service2 实现 Service 接口,提供具体服务 public class Servic…
Factory Pattern , 即工厂模式,用于创建对象的场景,属于创建类的设计模式 . 下面是一个工厂模式案例. Shape 作为接口, Circle, Square, Rectangle 作为具体类实现了 Shape 接口. ShapeFactory 封装了创建各个 Shape 的方式,隐藏了 new 命令.FactoryPatternDemo 用于演示工厂模式. 具体代码: Shape 接口定义 public interface Shape { public void draw();…