Refactored few implementation and design code smells. #966
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.
Implementation Smells
Extract method
Extracted ‘setupBroadcastChannel’ and ‘broadcastBeacon’ in BroadcastClient, and for better code organization and readability. This resolves the one of the implementation smell in the ‘ZBeacon’ class
Rename method/variable
Renamed handle to datagramChannel and isRunning to running for better clarity.
Decompose conditional
Decomposed the complex conditional in BroadcastServer's run method into shouldProcessMessage. Also introduced beaconData in BroadcastClient's broadcastBeacon for clarity.
Design Smells
Pull-up variable/method
Moved the code field and methods related to it (getErrorCode() and a part of toString()) from ZMQException to UncheckedZMQException. This allows any subclass of UncheckedZMQException to have an error code and the associated methods.
Push-down variable/method
The SimpleCurveAuth inner class has a dependency on ZCertStore.Fingerprinter. We can push down the fingerprinter initialization from the ZAuth constructor to SimpleCurveAuth. This makes SimpleCurveAuth more independent and encapsulates its initialization.
From ZAuth to SimplePlainAuth:
SimplePlainAuth uses properties for passwords. These properties are specific to SimplePlainAuth and can be initialized inside it, rather than being passed from ZAuth.
Replace conditional with polymorphism
ZAuth uses a map auths to handle different authentication mechanisms. This can be improved by using polymorphism. Each Auth implementation (SimpleCurveAuth, SimplePlainAuth, SimpleNullAuth) can override a method like handleAuth(ZapRequest request) to encapsulate the authentication logic.