Member-only story
GRASP Principles in Ruby on Rails
Understanding and Implementing GRASP Principles in Ruby on Rails
The General Responsibility Assignment Software Patterns (GRASP) are a set of principles aimed at improving object-oriented design and programming. These principles provide guidelines for assigning responsibilities within software classes, making your code more maintainable, scalable, and reusable. Ruby on Rails, a popular web application framework written in Ruby, offers a perfect platform to apply these principles, given its emphasis on convention over configuration and the DRY (Don’t Repeat Yourself) principle. In this article, we’ll explore the GRASP principles with practical Ruby on Rails examples.
Information Expert (Expert)
The Information Expert principle suggests that responsibilities should be assigned to the class that has the necessary information to fulfill them. This often leads to encapsulating business logic within models in Rails.
Here, the Order
model is the "expert" in dealing with order-related information, including calculating the total price.