phil sohar wrote:I was studing the cohension...but not able to understand how to maintain it......
as there are ways for strong encapsulation like we have to make the variable as private etc..
Is there something like this by which we can have a higher cohesion.........
Thanks in advance
Take a look on following pseudo code example:
In the above design cohesion is low the class is responsible to handle printing stuff sending emails and blah blah...such design is typically much difficult to maintain. High cohesion is all about how a single class is designed; the more focused a class the higher its cohesion.
Following listed code is high cohesion version of above example.
The key benefits of High cohesion is the code is easily reusable and easier to maintain for future changes.