Use more Java features (OOP / enum), split Rotor class, rename 'ringSettings' #8
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.
Firstly, I'd like to thank you for your videos and I was delighted to see you abord the infamous Enigma topic. Great topic!
I've tried to improve your code by using some OOP features of Java, as well as enums, while remaining "readable" for a non-Java user and keeping your code style intact.
Enums
are great to represent different static configurations, so I "extracted" them when I could:RotorType
andReflector
for example.RotorState
represents the state of the (3) rotors theEnigma
is using: thetype
(created from I to VIII), theringOffset
(created from0
to25
), and the mutable fieldrotorPosition
(mutating from0
to25
during the object lifecycle).Plugboard
class to compute both thewiring
andunpluggedCharacters
field at onceprivate
/public
andfinal
keywords as much as I could to be explicit about variable visibility and mutability (it personnaly helps me a lot when reading a new code)