CSC/ECE 517 Summer 2008/wiki3 3 cd: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
 
(18 intermediate revisions by the same user not shown)
Line 1: Line 1:
= Problem Statement =
We introduced the idea of low coupling in Lecture 20, and used the Observer pattern as an example in Lecture 23. But we've really only scratched the surface on what there is to know about achieving low coupling. Browse the Web and the ACM DL for other information, both theoretical and practical, and produce a guide to what there is to know about low coupling. Be sure to highlight those aspects that would be appropriate for inclusion in CSC/ECE 517.
= Low coupling. =  
= Low coupling. =  


Coupling in Software Design can be either High or Low. What this means is that object and classes in your code can exist indepently of other objects or classes. For example a system that has high coupling might experience the following issues:
Coupling in Software Design can be either High or Low. What this means is that object and classes in your code can exist indepently of other objects or classes. Coupling between modules/components is their degree of mutual interdependence. For example a system that has high coupling might experience the following issues:


* Change in one module forces a ripple of changes in other modules.  
* Change in one module forces a ripple of changes in other modules.  
Line 7: Line 10:
* Modules are difficult to reuse or test because dependent modules must be included.
* Modules are difficult to reuse or test because dependent modules must be included.


= The Observer pattern =
Examples of low coupling include.  
as an example in Lecture 23. But we've really only scratched the surface on what there is to know about achieving low coupling.  
* size: low number of connections between routines
 
* intimacy: minimal number of connections between routines
Browse the Web and the ACM DL for other information, both
* visibility: the prominence of the connection between routines
 
* flexibility: the ease of changing the connections between routines
= Observer Pattern Example =
 
= Java =
Here is an example that takes keyboard input and treats each input line as an event. The example is built upon the library classes <tt>java.util.Observer</tt> and <tt>java.util.Observable</tt>. When a string is supplied from System.in, the method <tt>notifyObserver</tt> is then called, in order to notify all observers of the event's occurrence, in the form of an invocation of their 'update' methods - in our example, <tt>ResponseHandler.update(...)</tt>.
 
The file myapp.java contains a main() method that might be used in order to run the code.


<source lang="java">
= Coupling in Theory =
/* File Name : EventSource.java */


package OBS;
Coupling level names are presented in order from worse to better: (high coupling is bad)
import java.util.Observable;          //Observable is here
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class EventSource extends Observable implements Runnable
* Content/Pathological Coupling : (worst) When a module uses/alters data in another
{
* Control Coupling : 2 modules communicating with a control flag (first tells second what to do via flag)  
    public void run()
* Common/Global-data Coupling : 2 modules communicating via global data
    {
* Stamp/Data-structure Coupling : Communicating via a data structure passed as a parameter. The data structure holds more information than the recipient needs.  
        try
* Data Coupling : (best) Communicating via parameter passing. The parameters passed are only those that the recipient needs.
        { 
* No data coupling : independent modules.
            final InputStreamReader isr = new InputStreamReader( System.in );
            final BufferedReader br = new BufferedReader( isr );
            while( true )
            {
                final String response = br.readLine();
                setChanged();
                notifyObservers( response );
            }
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
    }
}
</source>


<source lang="java">
= Coupling in Practice =
/* File Name: ResponseHandler.java */
http://www.leansoftwareengineering.com/wp-content/uploads/2007/08/abc.jpg
package OBS;
import java.util.Observable;
import java.util.Observer;  /* this is Event Handler */
public class ResponseHandler implements Observer
{
    private String resp;
    public void update (Observable obj, Object arg)
    {
        if (arg instanceof String)
        {
            resp = (String) arg;
            System.out.println("\nReceived Response: "+ resp );
        }
    }
</source>


<source lang="java">
Coupling is easy to measure and understand because it is mechanical in nature and requires less interpretation. Suppose there are three components A, B, and C. A's behavior depends upon B in some way (any way), A’s behavior depends upon C in some way, and the behavior of B and C do not appear to depend upon anything else.
/* Filename : myapp.java */
/* This is main program */
package OBS;
public class myapp
{
    public static void main(String args[])
    {           
        System.out.println("Enter Text >");


        // create an event source - reads from stdin
That is the coupling of the system and it is measureable.
        final EventSource evSrc = new EventSource();
        // create an observer
        final ResponseHandler respHandler = new ResponseHandler();
        // subscribe the observer to the event source
        evSrc.addObserver( respHandler );
        // starts the event thread
        Thread thread = new Thread(evSrc);
        thread.start();
    }
}
</source>


Also refer to an article in JavaWorld
= Links =
http://www.javaworld.com/javaworld/javaqa/2001-05/04-qa-0525-observer.html
[http://leansoftwareengineering.com/2007/08/08/what-is-coupling-really/ What is Coupling Really?]


= theoretical =
[http://en.wikipedia.org/wiki/Coupling_(computer_science) Coupling on Wikipedia]


= practical =
[http://c2.com/cgi/wiki?CouplingAndCohesion Coupling and Cohesion]


and produce a guide to what there is to know about low coupling. Be sure to
[http://pages.cpsc.ucalgary.ca/~eberly/Courses/CPSC333/Lectures/Design/coupling.html Coupling Theory]


= highlights =
[[CSC/ECE 517 Summer 2008/wiki3 Assignment|Back to the assignment page]]
those aspects that would be appropriate for inclusion in CSC/ECE 517.

Latest revision as of 02:44, 1 August 2008

Problem Statement

We introduced the idea of low coupling in Lecture 20, and used the Observer pattern as an example in Lecture 23. But we've really only scratched the surface on what there is to know about achieving low coupling. Browse the Web and the ACM DL for other information, both theoretical and practical, and produce a guide to what there is to know about low coupling. Be sure to highlight those aspects that would be appropriate for inclusion in CSC/ECE 517.

Low coupling.

Coupling in Software Design can be either High or Low. What this means is that object and classes in your code can exist indepently of other objects or classes. Coupling between modules/components is their degree of mutual interdependence. For example a system that has high coupling might experience the following issues:

  • Change in one module forces a ripple of changes in other modules.
  • Modules are difficult to understand in isolation.
  • Modules are difficult to reuse or test because dependent modules must be included.

Examples of low coupling include.

  • size: low number of connections between routines
  • intimacy: minimal number of connections between routines
  • visibility: the prominence of the connection between routines
  • flexibility: the ease of changing the connections between routines

Coupling in Theory

Coupling level names are presented in order from worse to better: (high coupling is bad)

  • Content/Pathological Coupling : (worst) When a module uses/alters data in another
  • Control Coupling : 2 modules communicating with a control flag (first tells second what to do via flag)
  • Common/Global-data Coupling : 2 modules communicating via global data
  • Stamp/Data-structure Coupling : Communicating via a data structure passed as a parameter. The data structure holds more information than the recipient needs.
  • Data Coupling : (best) Communicating via parameter passing. The parameters passed are only those that the recipient needs.
  • No data coupling : independent modules.

Coupling in Practice

http://www.leansoftwareengineering.com/wp-content/uploads/2007/08/abc.jpg

Coupling is easy to measure and understand because it is mechanical in nature and requires less interpretation. Suppose there are three components A, B, and C. A's behavior depends upon B in some way (any way), A’s behavior depends upon C in some way, and the behavior of B and C do not appear to depend upon anything else.

That is the coupling of the system and it is measureable.

Links

What is Coupling Really?

Coupling on Wikipedia

Coupling and Cohesion

Coupling Theory

Back to the assignment page