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.
Joined: Dec 28, 2010
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.
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.