Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove repetitive code at Joint inherited classes with fucntion extraction #301

Open
diogomene opened this issue Nov 17, 2024 · 0 comments · May be fixed by #302
Open

Remove repetitive code at Joint inherited classes with fucntion extraction #301

diogomene opened this issue Nov 17, 2024 · 0 comments · May be fixed by #302

Comments

@diogomene
Copy link

While scanning the source code with Qodana, an issue was identified:

In 9 out of the 11 classes extending the Joint abstract class, the following instructions are repeated within the initVelocityConstraints function:

this.m_localCenterA = this.m_bodyA.m_sweep.localCenter;  
this.m_localCenterB = this.m_bodyB.m_sweep.localCenter;  
this.m_invMassA = this.m_bodyA.m_invMass;  
this.m_invMassB = this.m_bodyB.m_invMass;  
this.m_invIA = this.m_bodyA.m_invI;  
this.m_invIB = this.m_bodyB.m_invI;  

This repetition suggests a potential flaw in the method abstraction. There is an opportunity to refactor and extract these repetitive instructions into a reusable module or method. Such a change would significantly reduce code duplication, enhance maintainability, and establish a more robust structure for future growth, where similar repetitions could arise.

Two possible solutions are suggested:

  1. Introduce an additional parent class in the abstraction hierarchy (e.g., Mass2VJoint), inheriting from Joint. This class would encapsulate the necessary attributes (e.g., mass, inertia, and constraints between two bodies) and provide a method to initialize the required constraints.
  2. Add an interface that defines the required attributes, implement it in classes with the duplicated routine, and extract the initialization logic into the Joint class as a method. This method would accept objects extending Joint and implementing the interface.

Either approach would enhance the abstraction layer, simplify the code, and support future scalability.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant