-
Notifications
You must be signed in to change notification settings - Fork 2
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
identify and address unnecessary coupling to model #40
Comments
I should also point out that the code-review checklist also has this item:
This identifies a trade-off between doupling and number of parameters in a constructor/method. |
If you're looking for a good introduction to Coupling (and how it contrasts with Cohesion), see https://www.javatpoint.com/software-engineering-coupling-and-cohesion. |
In the latest commit, I fixed some cases in which |
I don't know if 4 is the magic number, but that sounds reasonable for this sim. I inspected the remaining occurrences of
this.mass = mass;
this.modelViewTransform = modelViewTransform;
this.model = model;
this.spring = spring;
this.modelViewTransform = modelViewTransform;
this.model = model;
this.model
this.modelViewTransform |
Makes sense, those didn't need to be added as attributes as they could be used directly on the constructor. |
Made the discussed changes in the previous commits. |
Right. But |
I removed the design:interviews label from this issue. I added it by mistake when the issue was created. That label is typically used for things that need to be tested with users. |
Understood! It's something to remember. |
Went through all the files looking for fields that were not used or that could be replaced for const. In the latest commit I probably fixed all of them. |
I think this can already be closed. What do you think, @pixelzoom? |
Looks great @Hyodar! Closing. |
Related to #2 (code review):
Unnecessary coupling is when a class knows about (or has access to) things that are not related to its responsibilities. And it's one of the biggest factors in writing maintainable code.
In this sim, there are many constructors that take a
model
parameter. This is a red flag that there is unnecessary coupling. Generally, only a couple of things in the model are needed by a class, not the entire model.For example
SpringNode
is passed the entire OneDimensionModel instance:But it uses only
model.springsVisibilityProperty
. So a better API design would decouple SpringNode from OneDimensionModel like this:Based on this use of
model
parameter, the following constructor should be revisited, to evaluate whether they need the entire model or just a few of its Properties:The text was updated successfully, but these errors were encountered: