Refactored Code to Improve Maintainability and Modularity #1160
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.
This pull request introduces six refactoring improvements to address implementation and design smells identified in the codebase. The goal is to enhance readability, modularity, and maintainability without altering core functionality. Below is a summary of the changes:
Set 1: Implementation Smell Fixes
Decomposed Conditional (EmailValidator - isValidDomain)
Smell: Complex conditional logic made it difficult to read and maintain.
Solution: Extracted conditions into separate methods, making the logic clearer and improving readability.
Extracted Method (BaseJsonValidator - registerAndMergeDiscriminator)
Smell: Large method (registerAndMergeDiscriminator) contained multiple responsibilities.
Solution: Extracted helper methods to improve readability and single responsibility.
Renamed Long Identifier (AbsoluteIris - unicodeToASCII)
Smell: Variable IDN_TOASCII_PRESERVES_TRAILING_DOTS was too long.
Solution: Shortened it to IDN_KEEPS_TRAILING_DOTS while preserving its context.
Set 2: Design Smell Fixes
Moved Method (BaseJsonValidator - checkDiscriminatorMatch, registerAndMergeDiscriminator)
Smell: Core validation logic was mixed with discriminator handling, making BaseJsonValidator too large (400 lines).
Solution: Moved discriminator-specific methods to DiscriminatorContext, reducing complexity.
Replaced Conditional with Polymorphism (BaseJsonValidator - atRoot)
Smell: The atRoot method used an if-else chain based on PathType.
Solution: Introduced a PathStrategy interface with multiple implementations (LegacyPathStrategy, JsonPointerPathStrategy, JsonPathStrategy, DefaultPathStrategy).
Pushed Down Method (ContainsValidator - validate)
Smell: ContainsValidator mixed validation logic with annotation collection.
Solution: Moved annotation-specific logic to a new subclass, AnnotatedContainsValidator.