Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to main a high cohension

 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 cohension.........


Thanks in advance
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cohesion has to do with the responsibilities of a given class.

Encapsulation has to do with data hiding and making sure references do not leak from your class. Immutability is a related topic of interest
 
Minhaj Mehmood
Ranch Hand
Posts: 400
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.


hope this helps

Minhaj.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic