<<Design Patterns>> Gang of Four

One:Introduction:

One-1:Before  delving into the  some twenty pattern designs, it's necessary for ME(not for all readers) to get at some philosophies of OOD/OOP.

(1)Requests are  the only way to get an object to execute an operation and Operations are the only way to change an object's internal data(state).this might appears going without saying,but I think it's important to kept in mind  when programming. 

(2)Interfaces of an object are preferably suggested to interact with the object's own data. I get this sense in practice. For example, the class Image, aggregates a

class Feature. when implementing  interfaces in class Image, I'd better only deal with feature itself instead of letting Image's interfaces visit feature's data derecty.

(2)MVC使用了什么设计模式?

首先是观察者模式。其通过建立subscribe/notify机制,施加于view和model之间。当model里面的数据改变的时候,model应该通知依赖于这个model的所有views;然后每个view就更新自己。这个方法可以使“多个view依赖一个model时候,想创建一个新的依赖于此model的view“的时候使用。这样可以不重写这个model。

其次是组合模式。当一个view里面包含其他view,比如一个panel里面包含button,text等。这个nested views可以作为view的子类,可以用在任何父类被使用的地方。并作为一个整体被外部访问。

还有就是策略模式,其可以施加与view-controller之间。一个view使用一个controller的实例,每当view改变的时候(这里的改变包括很多,比如view的外观改变,行为改变(比如拒绝接受用户的输入等)等),对一个controller实例可以对其进行控制。

当然,MVC还可以使用工厂方法,装饰模式。前者可以为一个view生产指定的或默认的controller,后者可以给一个view添加scrolling。

原文地址:https://www.cnblogs.com/chaseblack/p/3173084.html