Java with GRASP 

General Responsabilty Assignment Software Patterns

1. Information Expert

2. Creator 

3. Controller

4. Low Coupling

5. High Cohesion

6. Indirection

7. Polymorphism

8. Pure Fabrication

9. Protected Variations

Set of rules regarding object-oriented programming :

Information Expert

  • Principle used to determine where to delegate the responsabilities
public class Firm {
		
	private ArrayList<Employee> ListEmpl=new ArrayList<Employee>(); 
			
	public String toString() {
    	String DisplayList="";
		for (int i = 0; i < ListEmpl.size(); i++) {
			int j=i+1;
			DisplayList=DisplayList +j+". "+ListEmpl.get(i)+"\n";
		}
		return DisplayList;
	}
	
}

Creator

  • The creator defines who instanties what object:

 

  • The class B is reponsible for the creation of an instance for the class A if :

B contains A, B uses most of A's features, B can initialize A

Controller

  • This is the first object beyond the User Interface to be used. It receives and coordinates the operations

Low Coupling

  • Coupling : this is how a element is related to another

 

  • The principle is to reduce the impact of change, so to have a low dependency between objects. It also increase reuse.

High Cohesion

  • As a side effect of Low Coupling, we want our objects to keep working correctly together.

 

  • Must be easy to manage with clear properties and objectives 

Indirection

  • This is the creation of an intermediate object with responsabilities between two or more objects  to avoid direct coupling.

Polymorphism

  • This principle take into account the differents behaviors and variations by type
class Shape {

    public void draw(){
    }
    
    class Square extends Shape{
    	public void draw(){
        //code to draw a square
        }
    }
    
    class Circle extends Shape{
    	public void Draw(){
        //code to draw a Circle
        }
    }
}

Pure Fabrication

  • When do not know where to place the responsability 

 

  • This is a class that not represents a solution to a problem. This allow high cohesion and low coupling 

Protected Variations

  • This principle means to predict the variations of elements (objects, systems and subsystems) in order to protect the others elements from these instabilities.
Made with Slides.com