CSC/ECE 517 Fall 2010/ch7 7b JB: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 8: Line 8:
==GRASP==
==GRASP==


In object-oriented design, the overall problems of assigning responsibility are dealt with by GRASP[http://en.wikipedia.org/wiki/GRASP_%28object-oriented_design%29 1], or General Responsibility Assignment Software Patterns (or Principles). GRASP has nine principles, of which Information Expert is one. The others are:
In object-oriented design, the overall problems of assigning responsibility are dealt with by [http://en.wikipedia.org/wiki/GRASP_%28object-oriented_design%29 GRASP 1], or General Responsibility Assignment Software Patterns (or Principles). GRASP has nine principles:
#Creator [http://en.wikipedia.org/wiki/GRASP_%28object-oriented_design%29#Creator 2]
# Information Expert
#Low Coupling [http://en.wikipedia.org/wiki/GRASP_%28object-oriented_design%29#Low_Coupling 3]
# Creator
#High Cohesion [http://en.wikipedia.org/wiki/GRASP_%28object-oriented_design%29#High_Cohesion 4]
# Low Coupling
#Controller [http://en.wikipedia.org/wiki/GRASP_%28object-oriented_design%29#Controller 5]
# High Cohesion
#Polymorphysm [http://en.wikipedia.org/wiki/GRASP_%28object-oriented_design%29#Polymorphism 6]
# Controller
#Pure Fabrication [http://en.wikipedia.org/wiki/GRASP_%28object-oriented_design%29#Pure_Fabrication 7]
# Polymorphysm
#Indirection [http://en.wikipedia.org/wiki/GRASP_%28object-oriented_design%29#Indirection 8]
# Pure Fabrication
#Protected Variations [http://en.wikipedia.org/wiki/GRASP_%28object-oriented_design%29#Protected_Variations 9]
# Indirection
# Protected Variations
 
There are often situations in programming object-oriented designs when data needed by an object is spread out across several other objects.  Rather than access each object individually and sequentially to get the details one at a time, the Information Expert pattern can be used to keep the program organized and straightforward. This will help to enable later extension of the program to enable new functionality without adding a lot of complexity.


==Process==
==Process==
Line 24: Line 27:
# Locate where that information is stored
# Locate where that information is stored
# Identify which class contains the largest subset of the required data
# Identify which class contains the largest subset of the required data
# Assign responsibility to that class
# Assign responsibility to that class to gather the remaining data
# Assign the responsible class to recursively apply the Information Expert Pattern for acquiring any data still missing.
 
In some circumstances, this method could be used in a tree structure to have a small number of experts who are responsible for specific types of data.  Each contacts a subset of the group of objects containing the needed data and may do some simple processing or combination of the data before passing it back to the original caller.


An example of when this might be retrieval of a database record.  The record may be comprised of data from many different databases.  One object would be the assigned as the caller.  It would be responsible for fetching the necessary data and building the final record.  It would contact each database controller, which may each be asked to retrieve records from one or more tables.  They would return the requested records (possibly after some minor editing of them).  The caller would then extract the fields it needed and build the new record from them.  This new record would be returned.


==References==
==References==
# [http://en.wikipedia.org/wiki/GRASP_%28object-oriented_design%29 Wikipedia's GRASP article 10]
# [http://en.wikipedia.org/wiki/GRASP_%28object-oriented_design%29 Wikipedia's GRASP article 1]
# [http://cs.armstrong.edu/hsu/Course/CSCI3321/PracticalSoftwareEngineering/html/ch10s04.html Information Expert Pattern overview with diagrams 11]
# [http://cs.armstrong.edu/hsu/Course/CSCI3321/PracticalSoftwareEngineering/html/ch10s04.html Information Expert Pattern overview with diagrams 2]
# [http://programmersnotes.info/2009/03/28/creator-and-information-expert-grasp-design-pattern-series/#expert Creator and Information Expert Principles with sample code 12]
# [http://programmersnotes.info/2009/03/28/creator-and-information-expert-grasp-design-pattern-series/#expert Creator and Information Expert Principles with sample code 3]

Latest revision as of 04:40, 11 December 2010

Information Expert Pattern

Introduction

Information Expert Pattern is a principle for assigning responsibility in object-oriented design. The fundamental idea is to identify the class with the most information (expertise) and assign responsibility to it.


GRASP

In object-oriented design, the overall problems of assigning responsibility are dealt with by GRASP 1, or General Responsibility Assignment Software Patterns (or Principles). GRASP has nine principles:

  1. Information Expert
  2. Creator
  3. Low Coupling
  4. High Cohesion
  5. Controller
  6. Polymorphysm
  7. Pure Fabrication
  8. Indirection
  9. Protected Variations

There are often situations in programming object-oriented designs when data needed by an object is spread out across several other objects. Rather than access each object individually and sequentially to get the details one at a time, the Information Expert pattern can be used to keep the program organized and straightforward. This will help to enable later extension of the program to enable new functionality without adding a lot of complexity.

Process

Using this approach, the programmer would:

  1. Identify a responsibility
  2. Determine what information is needed to fulfill it,
  3. Locate where that information is stored
  4. Identify which class contains the largest subset of the required data
  5. Assign responsibility to that class to gather the remaining data

In some circumstances, this method could be used in a tree structure to have a small number of experts who are responsible for specific types of data. Each contacts a subset of the group of objects containing the needed data and may do some simple processing or combination of the data before passing it back to the original caller.

An example of when this might be retrieval of a database record. The record may be comprised of data from many different databases. One object would be the assigned as the caller. It would be responsible for fetching the necessary data and building the final record. It would contact each database controller, which may each be asked to retrieve records from one or more tables. They would return the requested records (possibly after some minor editing of them). The caller would then extract the fields it needed and build the new record from them. This new record would be returned.

References

  1. Wikipedia's GRASP article 1
  2. Information Expert Pattern overview with diagrams 2
  3. Creator and Information Expert Principles with sample code 3