Your SlideShare is downloading. ×
GRASP Principles
GRASP Principles
GRASP Principles
GRASP Principles
GRASP Principles
GRASP Principles
GRASP Principles
GRASP Principles
GRASP Principles
GRASP Principles
GRASP Principles
GRASP Principles
GRASP Principles
GRASP Principles
GRASP Principles
GRASP Principles
GRASP Principles
GRASP Principles
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

GRASP Principles

8,053

Published on

A presentation about GRASP Principles and Object Oriented Design

A presentation about GRASP Principles and Object Oriented Design

0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
8,053
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
141
Comments
0
Likes
3
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. GRASP (Object Oriented Design)
  • 2. GRASP
    • G eneral
    • R esponsibility
    • A ssignment
    • S oftware
    • P rinciples / P atterns
  • 3.  
  • 4. GRASP
    • Responsibility
    • A contract / obligation that a class / module / component must accomplish
      • Knowledge
        • Private state
        • Computed state
    •  
    •  
      • Behavior
        • Send messages itself and modify its private state
        • Instantiate another objects
        • Send messages to another objects
  • 5. GRASP
    • GRASP Principles
    •  
      • Expert 
      • Creator
      • Low Coupling
      • High Cohesion
      • Controller
      • Polymorphism
      • Pure Fabrication
      • Indirection
      • Controlled Variation
  • 6. GRASP - Expert
    • Given a resposibility, what class must accomplish it?
    • "Assign the resposibility to the class that knows the necessary information"
    • Examples:
      •     Invoice's total amount
      •     Invoice itemss' amount
  • 7. GRASP - Creator
    • Who must instantiate A objects ?
    • Class B must have that resposibility if:
      • B is composed by A (composition)
      • B knows the necesary information in order to instantiate A objets
      • B depends heavily on A
    •                                                                                        
    • Design Patterns
      • Factory
      • AbstractFactory
  • 8. GRASP - Low Coupling
    • How to minimize dependencies between classes ?
    •  
    • Coupling
    • "When a class knows or depends on another class."
    • If a class change the dependant class will be affected.
    • Examples
      • Inheritance
      • Composition / agreggation / association
      • A send messages to B
  • 9. GRASP - Low Coupling
    • How to reduce design change impacts ?
    • Assign resposibilitys taking care of not to increasing  coupling.
    • Zero coupling is "impossible"
    •  
    • Cyclic coupling it's the worst case
  • 10. GRASP - High Cohesion
    • How to design cohesive classes?
    • Cohession
    • "How strongly related and focused the resposiblites of a class / module / package are."
    • Assing resposibilities related to each other.
    • Low Cohesion implies:
      • Hard to reuse
      • Hard to maintain
      • Constantly changing
  • 11. GRASP - Controller
    • Given an event layer (UI) and a bussines layer, who has the responsibility of receive the requests from the UI layer?
      • A class that represents the whole system.
        • Facade Controler Pattern
      • A  class that represents use case.
        • Use Case Controller Pattern
  • 12. GRASP - Polymorphism
    • How to act different depending on object's class?
    • How to design pluggable components ?
    • Use polymorphism to assing responsibilities on classes when the behavior changes.
    • Don't ask about object's class
    •  
    • "Different types respond to compatible messages (same method name, same parameter set, same method signature). Each message represents a specific behavior."
    •  
    • Inheritance, interfaces, duck typing
  • 13. GRASP - Pure Fabrication
    • How to assign responsibilities if applying the Expert principle decreases cohesion and increases coupling .
    • eg: Invoice printing, CSV export
    • Assign the resposibility to an artificial class that doesn't belongs to the domain model.
    • Design Patterns:
      • Active Record
      • EntityManager
  • 14. GRASP - Indirection
    • How to assign responsibilities in order to remove coupling between two components ?
    •  
    • Assign the responsibility to a component placed bewteen both sides
    • Interface that hides changes produced on an external API
  • 15. GRASP - Controlled Variation
    • How to design in such a way that changes on classes, modules and systems doesn't affect dependent components ?
    • Create stable interfaces upon inestable components.
    • Variations:
      • data
      • behaviour
      • external systems
      • os
      • ...
  • 16. GRASP - Controlled Variation
    • Structure variations
    •     E e = x.getA().getB().getC().getD().getE();
    • It's really fragile because a change on a link affects the sturcture
    • Inside a method send messages to:
      • this, self
      • objects received as parameters
      • self attributes
      • self components
      • instantiated objects on the current method call
  • 17. GRASP - Controlled Variation
    • Avoiding variations
      • Encapsulation
      • Polymorphism
      • Interfaces
      • Reflection, introspection, metadata
      • Uniform access (access methods)
      • Service lookups
      • Dependency injection, IoC
      • Virtual Machines (jvm, pvm, clr)
  • 18. EOF

×