GRASP (object-oriented design)
From Wikipedia, the free encyclopedia
General Responsibility Assignment Software Patterns (or Principles), abbreviated GRASP, consists of guidelines for assigning responsibility to classes and objects in object-oriented design.
The different patterns and principles used in GRASP are: Information Expert, Creator, Controller, Low Coupling, High Cohesion, Polymorphism, Pure Fabrication, Indirection, Protected Variations. All these patterns answer some software problem, and in almost
every case these problems are common to almost every software development project. These techniques have not been invented to create new ways of working but to better document and standardize old, tried-and-tested programming principles in object oriented
design.
It has been said that "the critical design tool for software development is a mind well educated in design principles. It is not the UML or any other technology".[1] Thus, GRASP is really a mental toolset, a learning aid to help in the design of object oriented
software.Contents [hide]
1 Patterns
1.1 Creator
1.2 Information Expert
1.3 Controller
1.4 Low Coupling
1.5 High Cohesion
1.6 Polymorphism
1.7 Pure Fabrication
1.8 Indirection
1.9 Protected Variations
2 See also
3 References
4 Notes
[edit]
Patterns
[edit]
Creator
See also: Factory pattern
Creation of objects is one of the most common activities in an object-oriented system. Which class is responsible for creating objects is a fundamental property of the relationship between objects of particular classes. Simply "Creator pattern is responsible
for creating an object of class".
In general, a class B should be responsible for creating instances of class A if one, or preferably more, of the following apply:
Instances of B contains or compositely aggregates instances of A
Instances of B record instances of A
Instances of B closely use instances of A
Instances of B have the initializing information for instances of A and pass it on creation.
[edit]
Information Expert
See also: Information hiding
Information Expert is a principle used to determine where to delegate responsibilities. These responsibilities include methods, computed fields and so on.
Using the principle of Information Expert a general approach to assigning responsibilities is to look at a given responsibility, determine the information needed to fulfill it, and then determine where that information is stored.
Information Expert will lead to placing the responsibility on the class with the most information required to fulfill it.[2]
[edit]
Controller
See also: Model–view–controller
The Controller pattern assigns the responsibility of dealing with system events to a non-UI class that represent the overall system or a use case scenario. A Controller object is a non-user interface object responsible for receiving or handling a system event.
A use case controller should be used to deal with all system events of a use case, and may be used for more than one use case (for instance, for use cases Create User and Delete User, one can have one UserController, instead of two separate use case controllers).
It is defined as the first object beyond the UI layer that receives and coordinates ("controls") a system operation. The controller should delegate to other objects the work that needs to be done; it coordinates or controls the activity. It should not do much
work itself. The GRASP Controller can be thought of as being a part of the Application/Service layer [3] (assuming that the application has made an explicit distinction between the Application/Service layer and the Domain layer) in an object-oriented system
with common layers.
[edit]
Low Coupling
Main article: loose coupling
Low Coupling is an evaluative pattern, which dictates how to assign responsibilities to support:
low dependency between classes;
low impact in a class of changes in other classes;
high reuse potential;
[edit]
High Cohesion
Main article: cohesion (computer science)
High Cohesion is an evaluative pattern that attempts to keep objects appropriately focused, manageable and understandable. High cohesion is generally used in support of Low Coupling. High cohesion means that the responsibilities of a given element are strongly
related and highly focused. Breaking programs into classes and subsystems is an example of activities that increase the cohesive properties of a system. Alternatively, low cohesion is a situation in which a given element has too many unrelated responsibilities.
Elements with low cohesion often suffer from being hard to comprehend, hard to reuse, hard to maintain and adverse to change.[4]
[edit]
Polymorphism
Main article: polymorphism in object-oriented programming
According to Polymorphism, responsibility of defining the variation of behaviors based on type is assigned to the types for which this variation happens. This is achieved using polymorphic operations.
[edit]
Pure Fabrication
See also: service (systems architecture)
A Pure Fabrication is a class that does not represent a concept in the problem domain, specially made up to achieve low coupling, high cohesion, and the reuse potential thereof derived (when a solution presented by the Information Expert pattern does not).
This kind of class is called "Service" in Domain-driven design.
[edit]
Indirection
See also: delegation pattern
The Indirection pattern supports low coupling (and reuse potential) between two elements by assigning the responsibility of mediation between them to an intermediate object. An example of this is the introduction of a controller component for mediation between
data (model) and its representation (view) in the Model-view-controller pattern.
[edit]
Protected Variations
Main article: delegation pattern
The Protected Variations pattern protects elements from the variations on other elements (objects, systems, subsystems) by wrapping the focus of instability with an interface and using polymorphism to create various implementations of this interface.
[edit]
See also
Anemic Domain Model
Design pattern (computer science)
Design Patterns (book)
Solid (object-oriented design)
[edit]
References
Larman, Craig (2005) [2004]. Applying UML and Patterns – An Introduction to Object-Oriented Analysis and Design and Iterative Development (3rd ed.). New Jersey: Prentice Hall. ISBN 0-13-148906-2.
[edit]
Notes
^ Larman 2005, p. 272.
^ Larman 2005 chapter 17, section 11.
^ "Application Layer like business facade?". Yahoo! Groups (domaindrivendesign). Retrieved 15 July 2010.
^ Larman 2005, pp. 314–315.
分享到:
相关推荐
Applying UML and Patterns: An Introduction to Object-Oriented Analysis and Design and Iterative Development (3rd Edition) <br>by Craig Larman <br>Publisher: Prentice Hall PTR;......
Starting with a detailed analysis of object-oriented analysis and design, you will use the Python programming language to clearly grasp key concepts from the object-oriented paradigm. This book fully ...
Starting with a detailed analysis of object-oriented technique and design, you will use the Python programming language to clearly grasp key concepts from the object-oriented paradigm. This module ...
This book begins by outlining a basic process of software design using iterative, object-oriented techniques. The case study used for this text is a point-of-sale (POS) system, a helpful real-world ...
Providing an early, self-contained review of object-oriented programming and C++, this text gives students a firm grasp of key concepts and allows those experienced in another language to adjust ...
Unlocking the Secrets of Cocoa and Its Object-Oriented Frameworks Mac and iPhone developers are often overwhelmed by the breadth and sophistication of the Cocoa frameworks. Although Cocoa is indeed ...
Explore Swift’s object-oriented concepts Become familiar with built-in Swift types Dive deep into Swift objects, protocols, and generics Tour the lifecycle of an Xcode project Learn how nibs are ...
Design patterns have become a staple of object-oriented design and programming by providing elegant, easy-to-reuse, and maintainable solutions to commonly encountered programming challenges....
Move into iOS development by getting a firm grasp of its fundamentals, including the Xcode IDE, the Cocoa Touch framework, and Swift 2.0—the latest version of Apple’s acclaimed programming language....
Move into iOS development by getting a firm grasp of its fundamentals, including the Xcode IDE, the Cocoa Touch framework, and Swift 3—the latest version of Apple’s acclaimed programming language....
Explore Swift’s object-oriented concepts: variables and functions, scopes and namespaces, object types and instances Become familiar with built-in Swift types such as numbers, strings, ranges, tuples...
• Explore Swift s object-oriented concepts: variables and functions, scopes and namespaces, object types and instances • Become familiar with built-in Swift types such as numbers, strings, ranges, ...
Although Cocoa is indeed huge, once you understand the object-oriented patterns it uses, you’ll find it remarkably elegant, consistent, and simple. Cocoa Design Patterns begins with the mother of ...
You’ll learn object-oriented concepts, understand how to use Apple’s development tools, and discover how Cocoa provides the underlying functionality iOS apps need to have. Dozens of example ...
KEY POINTS Appeals both to Python novices and programmers migrating from earlier versions who want to quickly grasp the new features of Python 3 Teaches best practices for objected oriented design ...
You’ll learn object-oriented concepts, understand how to use Apple’s development tools, and discover how Cocoa provides the underlying functionality iOS apps need to have. Dozens of example ...
Understand functional programming patterns by comparing them with the traditional object-oriented design patterns Write robust, safer, and better code using the declarative programming paradigm An ...
Acquaint yourself with Java and object-oriented programming, from zero previous experience Build four cool games for your phone and tablet, from retro arcade-style games to memory and education ...