You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
1. What is the basic function (功能) of strategy pattern?
Define a family of algorithms, encapsulate each one, and make them interchangeable. The interchangeable algorithms are left for the user to choose and configure. The strategy design pattern can reduce the number of classes, when one class consists of different strategies.
6. Please explain why Template method could be combined with Strategy.
For the algorithm skeleton of template method, when there are many different implementations for each algorithm step, there will be a dramatic increase in the number of implementation classes.
To resolve this issue, a strategy can be intoduced for each algorithm step, and let the client user to configure the different steps of the algorithm.
7. Please give a typical UML class diagram of template method combined with strategy.
Proxy
8. What is the basic function (功能) of proxy pattern?
Provide a surrogate or placeholder for another object to control access to it.
Before and after providing access to the object, different tasks can be added for different purposes.
10. Please list typical applications of proxy pattern.
Remote proxy (远程代理): Control access to a remote object, which provides a local representative for an object in a different address space.
Virtual proxy: Control access to an expensive object (expensive in terms of memory or runtime).
Protect (or Access) proxy: Control access to an object based on access rights.
Smart reference: a replacement for a bare pointer (替换普通指针) that performs additional actions when an object is accessed, such as reference counting, etc.
11. Please give a typical UML class diagram of proxy pattern.
12. What are the similarity and differences between proxy and adapter?
Similarity: provide and control access to objects.
Difference
Proxy wraps one object to control it’s access; Adapter wraps one or more objects to adapt their interface to the user program.
Proxy does not change interface; Adapter may change interface.
Proxy often changes functionality; Adapter does not change functionality.
13. Please give the complete source code of matrix filler in the slides.
14. What is the basic function (功能) of command pattern?
Encapsulates a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations (支持撤消操作).
Using Command Pattern, we encapsulate method invocation (方法调用), so that the invoker (调用者) does not need to know implementation details.
15. How to implement Undo and Redo in command pattern?
Store the commands sequentially (顺序地) in a list.
Undo: Skip the last command in the list, and execute the remaining commands.
Redo: execute the latest command once again, and add it to the end of command list.