Remove duplicated code in joint class derivatives - with interface and method extraction #302
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What was done?
To address the code duplication identified in Joint-derived classes, an interface was introduced and implemented by the classes containing the repetitive routine. Subsequently, a method was added to the Joint class, which accepts as a parameter instances of classes inheriting from Joint and implementing the newly created interface.
This approach was chosen because the differences between the classes with the duplicated routine and those without it are minimal, making the abstraction of a new parent class unnecessary. A new class would have added only a few attributes and a single functionality, which would not have significantly improved code maintainability or readability.
All relevant Joint-derived classes now implement the ConstrainedBodiesJoint interface, ensuring the extracted initialization function can be applied uniformly.
As a result, code duplication has been reduced, and a clean mechanism for handling common initialization logic has been introduced. The inheritance structure remains unchanged, minimizing invasive modifications to the codebase while enhancing maintainability.
Resolve #301