0% found this document useful (0 votes)
18 views8 pages

GRASP Design Principles For Better Software Design

The document discusses the GRASP (General Responsibility Assignment Software Patterns) principles, which are nine best practices aimed at improving software design through better responsibility assignment in object-oriented programming. Key principles include Creator, Information Expert, Low Coupling, High Cohesion, Controller, Polymorphism, Pure Fabrication, Indirection, and Protected Variations, each illustrated with practical examples. By applying these principles, developers can create maintainable, scalable, and reusable software systems.

Uploaded by

Umm e Aimen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views8 pages

GRASP Design Principles For Better Software Design

The document discusses the GRASP (General Responsibility Assignment Software Patterns) principles, which are nine best practices aimed at improving software design through better responsibility assignment in object-oriented programming. Key principles include Creator, Information Expert, Low Coupling, High Cohesion, Controller, Polymorphism, Pure Fabrication, Indirection, and Protected Variations, each illustrated with practical examples. By applying these principles, developers can create maintainable, scalable, and reusable software systems.

Uploaded by

Umm e Aimen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

GRASP Design Principles for Better Software

Design

Introduction
Creating maintainable, scalable, and reusable software
systems is at the core of successful software development.
To achieve these goals, understanding and applying the
right set of design principles is essential. In object-oriented
Designing (OOAD), the GRASP principles provide valuable
guidance to help you design better software systems.

GRASP, (stands for General Responsibility


Assignment Software Patterns (or Principles)), is
a collection of nine best practices that assist in assigning
responsibilities to classes and objects. By following these
principles, you can create a well-structured, modular, and
maintainable software system.

We will explore the nine core GRASP principles with


examples to help you gain a deeper understanding and
apply these principles to your software projects.
Creator
The Creator principle involves assigning the responsibility
of creating an object to a class that uses the object, has the
necessary information to create it, or aggregates the object.
This principle ensures a clear separation of concerns and
simplifies object creation.

Example: In an e-commerce application, the Order class


might be responsible for creating OrderItem objects, as it
uses and aggregates these objects. Similarly (Account
class creates Transaction objects)

Information Expert
The Information Expert principle states that
responsibilities should be assigned to the class with the
most knowledge or information required to fulfill the
responsibility. This principle promotes encapsulation and
ensures that each class is responsible for managing its data
and behavior.

Example: In a payroll system, the Employee class should


be responsible for calculating its salary, as it has all the
necessary information, such as base salary, hours worked,
and bonuses. Similarly, Account class manages
transactions, balances, and account status.

Low Coupling
Low Coupling involves minimizing dependencies between
classes to reduce the impact of changes and improve
maintainability. This principle encourages independent
and modular classes that can be easily modified without
affecting other parts of the system.

- Minimize dependencies between classes.

- Reduce impact of changes and improve maintainability.

- Encourage independent and modular classes.

Example: Instead of having a direct dependency between


the Order class and the ShippingService class, we can
introduce an interface, ShippingProvider, which
reduces coupling and allows for easier substitution of
shipping services.

- Instead of having the NotificationSender class directly


depend on the EmailService class, introduce a
NotificationService interface.
- The NotificationSender class depends on the
NotificationService interface, and the EmailService class
implements this interface.

- Food Delivery app, work with one restaurant(tight


coupling), work with many hotels(Low coupling).

High Cohesion
High Cohesion means grouping related responsibilities
together within a single class to make it easier to
understand, maintain, and reuse. This principle ensures
that each class has a single, focused purpose.

Example: In a blogging platform, the Blog class should


only be responsible for managing blog-related activities,
such as adding and removing posts, and not for handling
user authentication.

- Order class manages order-related activities.

- Separate class handles payment processing.


Controller
The Controller principle assigns the responsibility of
handling system events to a dedicated class, which
manages and coordinates the system’s behavior. This
principle helps maintain a clean separation between the
presentation and domain layers.

Example: In a web application, a UserController class


can handle user-related events, such as registering and
logging in, delegating the actual processing to other
classes.

- OrderController handles order-related events (placing,


canceling).

Polymorphism
Polymorphism involves using inheritance and interfaces to
enable different classes to implement the same behavior or
operation. This principle allows for more flexibility and
easier code maintenance by enabling the system to handle
varying implementations without modifications to the
existing code.
Example: In a graphics application, the Shape interface
defines the common behavior for different shapes, such
as Circle and Rectangle, allowing them to be rendered
in a consistent manner.

- PaymentMethod interface defines common behavior for


CreditCard, PayPal, and BankTransfer.

- Each payment method implements the PaymentMethod


interface, allowing for consistent payment processing.

Pure Fabrication
Pure Fabrication involves creating an artificial class to
fulfill a specific responsibility when no suitable class exists.
This principle aims to maintain high cohesion and low
coupling by avoiding the assignment of unrelated
responsibilities to existing classes.

Example: In a file storage application,


the FileStorage class can be created to handle file
storage operations, separating it from the core business
logic.
Indirection
Indirection introduces an intermediate class or object to
mediate between other classes, helping to maintain low
coupling and simplify interactions. This principle can be
applied through various patterns, such as the Facade or
Adapter patterns.

Example: In a notification system,


a NotificationService class can be introduced to send
notifications via different channels, like email or SMS,
without directly coupling the sender and receiver classes.

Protected Variations
Protected Variations involve encapsulating variations and
changes in the system behind stable interfaces to minimize
the impact of changes and increase the system’s
robustness. This principle can be applied by using
abstractions, such as interfaces or abstract classes, to hide
implementation details.

Example: In a payment processing system,


the PaymentGateway interface protects the system from
changes in the implementations of different payment
methods, like CreditCardPayment or PayPalPayment.

Conclusion
Understanding and applying GRASP principles is a key
aspect of designing robust, maintainable, and scalable
object-oriented software systems. By leveraging these
principles, developers can create well-structured code that
is easier to modify and reuse, ultimately leading to more
efficient software development processes and higher-
quality applications.

We’ve explored each of the nine GRASP principles and


provided examples to illustrate their use in practice. As you
continue to work on your software development projects,
keep these principles in mind and incorporate them into
your designs to ensure your systems are built on a solid
foundation.

You might also like