Can any one describe the exact difference between loose coupling and tight coupling in Object oriented paradigm?
相关问题
- how to define constructor for Python's new Nam
- Do the Java Integer and Double objects have unnece
- Keeping track of variable instances
- Object.create() bug?
- std::vector of objects / pointers / smart pointers
相关文章
- 接口B继承接口A,但是又不添加新的方法。这样有什么意义吗?
- Poor Use Case of Object.assign() - Simple Example
- NameError: name 'self' is not defined, eve
- Where is the object browser in visual studio C# 20
- Implementation Strategies for Object Orientation
- An object reference is required for the non-static
- Check if the Type of an Object is inherited from a
- When to use Interfaces in PHP
Loose Coupling is the process of giving the dependency your class needs indirectly without providing all the information of the dependency(i.e in the from of interface) in case tight coupling you directly give in the dependency which is not good way of coding.
An extract from my blog post on coupling:
What is Tight Coupling:-
As par above definition a Tightly Coupled Object is an object that needs to know about other objects and are usually highly dependent on each other's interfaces.
When we change one object in a tightly coupled application often it requires changes to a number of other objects. There is no problem in a small application we can easily identify the change. But in the case of a large applications these inter-dependencies are not always known by every consumer or other developers or there is many chance of future changes.
Let’s take a shopping cart demo code to understand the tight coupling:
Problems with the above example
Tight Coupling creates some difficulties.
Here,
OrderTotal()
methods is give us complete amount for the current items of the carts. If we want to add the discount features in this cart system. It is very hard to do in above code because we have to make changes at every class as it is very tightly coupled.