What does 'low in coupling and high in cohesion' mean

前端 未结 14 543
粉色の甜心
粉色の甜心 2020-11-30 16:18

I have problems understanding the statement low in coupling and high in cohesion. I have googled and read a lot about this, but still finding it hard to underst

相关标签:
14条回答
  • 2020-11-30 17:00

    Low Coupling:-- Will keep it very simple. If you change your module how does it impact other modules.

    Example:- If your service API is exposed as JAR, any change to method signature will break calling API (High/Tight coupling).

    If your module and other module communicate via async messages. As long as you get messages, your method change signature will be local to your module (Low coupling).

    Off-course if there is change in message format, calling client will need to make some change.

    0 讨论(0)
  • 2020-11-30 17:03

    Low coupling is in the context of two or many modules. If a change in one module results in many changes in other module then they are said to be highly coupled. This is where interface based programming helps. Any change within the module will not impact the other module as the interface (the mean of interaction ) between them has not changed.

    High cohesion- Put the similar things together. So a class should have method or behaviors to do related job. Just to give an exaggerated bad example: An implementation of List interface should not have operation related to String. String class should have methods, fields which is relevant for String and similarly, the implementation of List should have corresponding things.

    Hope that helps.

    0 讨论(0)
提交回复
热议问题