Skip to content

Refactoring moments_form_helper.rb to adhere to Single Responsibility Principle #2350

@mirjharr2

Description

@mirjharr2

The class app/helpers/moments_form_helper.rb currently handles multiple responsibilities including constructing the form input properties and handling business logic. Currently, this violates Single Responsibility Principle, which states that a class must only have one responsibility and only have one reason to change.

The introduction of a new class that would encapsulate the logic for input properties, thus separating the responsibilities between two classes, would fix this violation. Attached is an idea of what this would look like if the change is made. Additionally, tests that relate to this class will need to be updated to reflect this change as well as adding more tests to test the new class.

Refactored Code.pdf

This would be a stepping stone in ensuring that this codebase adheres to the SOLID principles, which would improve the overall architecture of this codebase. In the long run, this change as small as it may seem, allows these classes to be easier to maintain and test as these two responsibilities can be tested individually.

Please comment with any feedback!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions