其实Interface,顾名思义,就是2个事物的"界面",interface衔接了2个事物,这两个事物,每每一方比较"多变",而另外一方咱们又不太但愿它相对"不变"。 blog
正是经过引入一个interface中间层,多了一层间接,使得双方能够解耦,使得善变的一方不会"波及"指望稳定另外一方。 接口
好比下图中, Command模式中,Command接口就把善变的一方,好比Light,TV 等等,同指望稳定的Remote遥控器隔离开了。 ip
最后记住这么一句话: ci
"All problems in computer science can be solved by another level of indirection, except of course for the problem of too many indirections." – David Wheelerget