![]() |
Development Lifecycle »
Design and Architecture »
General
Intermediate
Design loosely coupled modules - object oriented systemsBy Milind ShingadeThis articles explains coupling, explains classification of coupling and gives simple way to reduce each type of coupling. |
Architect, Dev, Design
|
||||||||
|
Advanced Search |
|
|
|
||||||||||||||||
Title: Design loosely coupled modules - object oriented systems Author: Milind Shingade Email: "mailto:milindshingade@yahoo.comMember%20ID">milindshingade@yahoo.com Member: 18133 Language: C++ Platform: Generic none Technology: None Level: Beginner Description: This articles explains coupling, explains classification of coupling and gives simple way to reduce each type of coupling. Section: Application design SubSection: General
This article explains the coupling between the classes. It also explains the consequences of high coupling. The article then classifies coupling and explains each type of coupling along with the ways to eliminate the coupling.
Coupling is the factor of dependency of one class on another class. The factor of coupling varies between low and high. Systems having high coupling are unstable and requires more effort to modify. In a system with high coupling factor modification in one class forces a ripple of changes in other classes and thus increases the effort required for modification. High efforts require more cost. High coupling also decreases the reusability of a class because the dependant class must be included. Classes with high coupling are difficult to understand in isolation. System having low coupling are stable and when a change is made in one class will not require change in the implementation of other classes.
Coupling is classified as follows,
Content coupling exists between two classes when one class relies on the internal working of another class i.e. one class is using the variables of another class. When a class holding content is modified to contain another format of the content then other class using the content should be modified. The coupling factor for content coupling is high. This form of coupling is undesirable because any class can modify the internal data of another class. To reduce use private access control for the contents in the class and provide accessing methods such as getVal and setVal.
Common coupling exists when classes in the system share a global data. Changing the format of the shared resource requires modifications in all the classes using the global data. To reduce common coupling create a class to contain global data and add public methods in the class to obtain or modify the global data. One should use critical sections in the class.
External coupling is dependency of the class on third party classes like MFC, QT etc. or share an externally imposed data format, communication protocol or device interface. External coupling can be reduced by using fa�ade pattern.
Control coupling is one class controls the logic of another class, by passing it information on what to do example, by passing flag or command thus, controlling the sequence of execution. To reduce use polymorphic operations or use a look up table that will map a command to a method.
Stamp coupling is a form of coupling in which two classes modify or access data in the same object. To reduce add methods to access or modify all data within the object.
Data coupling is the form of coupling in which one class passes simple data to another as an argument. Coupling is due to interpretation of data i.e. meaning of data that passed as argument to the member function of another class. If the meaning of the data that is passed as argument is changed then other class has to modify to accommodate the change. To reduce developers should not pass unnecessary arguments and should pass few arguments, each containing more abstract information.
Message coupling is the lowest possible coupling. Classes are not dependent on each other instead they use a public interface to exchange parameter-less messages (or events).
Routine call coupling is a form of coupling in which one routine calls another. To reduce the total number of routines that a particular class calls must be reduced. If there is a sequence of two or more routines to compute something and this sequence is using in more than one place then to reduce routine call coupling a single routine must be written that encapsulates the sequence.
Inclusion coupling is a form of coupling in which one component includes source code of another component. If the included component changes something on which includer depends or adds something that raises the conflict with something in the includer then the includer must change. To reduce do not include component those are not required.
version 1 : Intial article without examples.
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 28 Jul 2007 Editor: |
Copyright 2007 by Milind Shingade Everything else Copyright © CodeProject, 1999-2009 Web16 | Advertise on the Code Project |