How is loose coupling achieved using interfaces in Java when an implementation class is mandatory and bound to interface contract?

前端 未结 4 1578
囚心锁ツ
囚心锁ツ 2020-12-16 18:51

How is loose coupling associated with interfaces when we are bound to create an implementation class regardless? The implementation class is forced to implement all those me

4条回答
  •  一向
    一向 (楼主)
    2020-12-16 19:22

    the client code is coupled to the interface. it is not coupled to the implementation. you can change t he implementation without compiling the client code or the interface.

    see http://en.wikipedia.org/wiki/Dependency_inversion_principle and http://en.wikipedia.org/wiki/Open/closed_principle

提交回复
热议问题