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

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

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

关于Interface忽然想到的

关于Interface忽然想到的

 

最后记住这么一句话:

"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

相关文章:

  • 2022-01-20
  • 2021-08-13
  • 2021-07-22
  • 2021-12-13
  • 2021-07-24
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-08-30
  • 2022-12-23
  • 2019-02-23
  • 2021-10-28
  • 2021-12-13
  • 2021-09-13
  • 2021-12-06
相关资源
相似解决方案