Do you look for GRASP Patterns?
30/07/2019 10:14 AM by
GRASP stands for General Responsibility Assignment Software Patterns and describes guidelines for working out what objects are responsible for what areas of the application.
The fundamentals of GRASP are the building blocks of Object-Oriented design. It is important that responsibilities in your application are assigned predictably and sensibly to achieve maximum extensibility and maintainability.
GRASP consists of a set of patterns and principles that describe different ways of constructing relationships between classes and objects.
||A specific class is responsible for creating instances of specific other classes (e.g. a Factory Pattern)|
||Responsibilities are delegated to the class that holds the information required to handle that responsibility|
||System events are handled by a single "controller" class that delegates to other objects the work that needs to be done|
||Classes should have a low dependency on each other, have low impact if changed, and have high potential for reuse|
||Objects should be created for a single set of focused responsibilities|
||The variation in behaviour of a type of object is the responsibility of that type's implementation|
||Any class that does not represent a concept in the problem domain|
||The responsibility of mediation between two classes is handled by an intermediate object (e.g. a Controller in the MVC pattern)|
||Variations in the behaviour of other objects is abstracted away from the dependent object by means of an interface and polymorphism|
Tip: Visual Studio's Architecture tools can help you visualise your dependencies. A good structure will show calls flowing in one direction.
Figure: Bad Example - Calls are going in both directions which hints at a poor architecture
Figure: Good Example - Calls are flowing in one direction hinting at a more sensible arrangement of responsibilities
Do you feel this rule needs an update?