JAVA interview - Design Patterns

1, talk about common design patterns

1) single-case model: guaranteed to be created once, saving overhead.

2) factory pattern (simple plant, abstract factory): Decoupling code.

3) the observer pattern: defines the dependencies between the many objects, when an object is changed, all of its dependents will be notified and updated automatically.

3) Facade pattern: provides a unified interface, the interface used to access a group of subsystems, the appearance of a high-level interface that allows the subsystem easier to use.

4) Template Method: defines the skeleton of an algorithm, a delay some steps to subclasses, subclasses template method makes possible without changing the structure of the algorithm, the step of redefining the algorithm.

5) Status mode: allows the object to change its behavior when the internal state, the object appears to modify its class.

 

2, a simple factory and abstract factory What is the difference?

Simple Factory: any product used to produce the same level structure for adding new products, do nothing.

Factory method: to produce agreed hierarchical structure of fixed product, any product support increased.

Abstract Factory: used to produce different product families of all products, for adding new products, inability to; support increased product family.

 

Guess you like

Origin www.cnblogs.com/xiaomingwang/p/11586902.html