GRASP Overview
GRASP, General Responsibility assignment software Patterns, translated as "Common responsibility allocation software principles", including the following principles and patterns
Controllers (Controller)
The controller mode is used to receive and handle system events, and should generally be assigned to a system that represents the whole or a single use case scenario
- A use case controller should be used to handle all system events of a use case
- The first object defined by the Controller object as a UI presentation layer is responsible for receiving and coordinating system operations
- The controller itself should not contain too much logic and functionality
- In N-layer multi-tier architecture applications, controllers are typically located between the application and service tiers
- See also: MVC pattern
Created by (Creator)
Object creation is a very common behavior in an object-oriented system, and in general, the following conditions are created by B, and the creator of A is a:
- B is the aggregation of a
- B is the container of a.
- B Records An example of a
- b Examples of frequent and close use of a
- b holds information on initialization a
High cohesion (high Cohesion)
Highly encapsulated to support the manageability, readability, and reusability of objects, function-related responsibilities in a class, together with limited functionality
- Cohesion is commonly used to support low-coupling
- Can be managed
- Can understand
- can be reused
- A single, easy-to-expand function
Indirect (indirection)
Indirect mode supports loose coupling (no direct dependencies) by assigning a mediator object to the middle of two elements, such as "C" in MVC
Information Specialist (Information expert)
Information experts (also called expert mode) are used to decide where to delegate responsibilities, which include methods, calculation fields, and so on
- A class has all the information it needs to complete a job, and that responsibility should be assigned to this class to implement
- Expert mode is used to assign duties and to query and store information based on a given responsibility
Loose coupling (Low coupling)
Loosely coupled as a principle of evaluation system design, the responsibility lies in:
- Reduce dependencies between classes and classes
- Change the impact of a class to other classes to minimize
- Higher reusability
Polymorphic (polymorphism)
In an inherited system, a different invocation is produced at run time using the same design-time definition
Protected changes (Protected variations)
This pattern is designed to prevent changes to the elements that contain elements by preventing external systems (objects, systems, subsystems) from modifying them.
- Packaging unstable and variable elements using interfaces
- Create different instances of the interface to implement Polymorphic
- If the future changes, the expansion interface new implementation, do not need to modify the original implementation
- Basically equivalent to OCP (open and close principle)
Purely fictitious (pure fabrication)
Using pure fiction to coordinate cohesion and coupling, to some extent, solves the dependency between system object interaction
Cliché-object-oriented design principles--grasp design principles