aspose file tools*
The moose likes Beginning Java and the fly likes Coupling and Cohesion in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Coupling and Cohesion in java" Watch "Coupling and Cohesion in java" New topic
Author

Coupling and Cohesion in java

Shahid Pathan
Greenhorn

Joined: Dec 28, 2010
Posts: 23
How do we implement coupling and cohesion in java? And simple example based on real life scenario?
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4241
    
    7

You don't really "implement" coupling and cohesion. It's a characteristic of anything you implement.

So coupling is the extent to which different classes are dependent on each other, and so the extent to which changes to one class affect others. And cohesion is the extent to which a class has a specific purpose.
Shahid Pathan
Greenhorn

Joined: Dec 28, 2010
Posts: 23
Thanks Matthew Brown ,
I know that this is default characteristic but we have to take care of it when we design the classes,
so that our application should be more flexible more independent on other module.
I need a basic and simple example on real life (daily life activity) and design the classes to demonstrate coupling and cohesion.
Thanks
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36514
    
  16
You want a basic example to avoid coupling and demonstrate cohesion.Now you see the Bank class has direct access to the Account class' inner workings. Not only does that mean the security and integrity of the Account class may be breached, but also any changes to the Account class will "break" the Bank class too.

That is an example of tight coupling. It is also poor cohesion, because the Account class does not work out how much money it contains. The account now contains 123.45, irrespective of what it contained before. Using deposit and withdraw methods is far better. Oddly enough, I wrote a withdraw method earlier today: here. All the calculations are done inside the withdraw method there.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Coupling and Cohesion in java
 
Similar Threads
looking for good resources on OO
Has-A relationship
coupling cohesion in java
OOPs terms
How to design OO systems...