What is the difference between loose coupling and tight coupling in the object oriented paradigm?

前端 未结 16 1960
粉色の甜心
粉色の甜心 2020-11-22 08:03

Can any one describe the exact difference between loose coupling and tight coupling in Object oriented paradigm?

16条回答
  •  一整个雨季
    2020-11-22 08:49

    There are certain tools that provide dependency injection through their library, for example in .net we have ninject Library .

    If you are going further in java then spring provides this capabilities.

    Loosly coupled objects can be made by introducing Interfaces in your code, thats what these sources do.

    Say in your code you are writing

    Myclass m = new Myclass();
    

    now this statement in your method says that you are dependent on myclass this is called a tightly coupled. Now you provide some constructor injection , or property injection and instantiating object then it will become loosly coupled.

提交回复
热议问题