关于Interface忽然想到的

其实Interface,顾名思义,就是2个事物的"界面",interface衔接了2个事物,这两个事物,往往一方比较"多变",而另一方我们又不太希望它相对"不变"。

正是通过引入一个interface中间层,多了一层间接,使得双方可以解耦,使得善变的一方不会"波及"期望稳定另一方。

比如下图中, Command模式中,Command接口就把善变的一方,比如Light,TV 等等,同期望稳定的Remote遥控器隔离开了。

 

最后记住这么一句话:

"All problems in computer science can be solved by another level of indirection, except of course for the problem of too many indirections." – David Wheeler

posted on 2016-02-19 13:23  smwikipedia  阅读(267)  评论(0编辑  收藏  举报

导航