Question about class cohesion and readability v2

I have the same question about cohesion as posted here Question about class cohesion and readability

I don’t feel it was answered there. Is changing those methods from public to private what removes the low cohesion in his example? That doesn’t make sense because the functions still have the warning issue Sam mentioned (at 7:12 into his lecture) of being able to individually split each function into their own classes.

1 Like

The solution of the thread you linked solves only 50% of the challenge, it does make the classes loosely coupled, but the low cohesion stays there.

People might get confused by this because you should make your methods handle a single thing but that doesn’t mean animation, audio, stats, and so on, it means handling a single action, and actions are comprised of several tinier actions.

We don’t say:

I saw you moving your left leg and foot forward and then your right leg and foot forward alternately down the street the other day.

We say:

I saw you walking down the street the other day.

The second one is far easier to understand than the first, and the first is pretty much the solution of the thread you linked.

Thanks Yee. The idea that the solution in the other thread does not fix the low cohesion makes much more sense. Thank you for the extra example of why putting those three things into a single method doesn’t violate the single responsibility method! That would have been my next question.

1 Like

It does depend on your use case. Assuming you wrapped it all up into a single class/component. If you find that you’re needing to use moving your left leg and/or moving your foot forward individually, then you would be violating the single responsibility method as you’d be diving into the walk class when you want to move a foot.

If all you do is execute walk and none of the smaller parts, then you’d be fine.

2 Likes

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms