Extract Class :
Class Spider has multiple responsibilities making it less cohesive. To improve the cohesive factor, separated scheduler related code to a new class called SpiderScheduler. This will help in separation of concerns and increase code maintainability.
Push Down method:
Method smartcontent was not a supported operation for Class PlainText but its implementation was forced through hierarchy and hence it threw UnsupportedOperationException. smartcontent method is only used in HtmlNode class and so pulled it from Selectable class so that every class implementing Selectable class does not have to implement this method if the operation is unsupported
Replace conditional using polymorphism:
In class BasicTypeFormatter, multiple conditions were used to determine the type of Basic class. Replaced this conditional by introducing BasicClassDetector interface that is implemented by all the types of Basic class. This will help in increasing code maintainability for extension in Basic class types. Hence, the BasicTypeFormatter now follows Open Closed Principle.
Refactored code using the following methods :
Extract Class : Class Spider has multiple responsibilities making it less cohesive. To improve the cohesive factor, separated scheduler related code to a new class called SpiderScheduler. This will help in separation of concerns and increase code maintainability.
Push Down method: Method smartcontent was not a supported operation for Class PlainText but its implementation was forced through hierarchy and hence it threw UnsupportedOperationException. smartcontent method is only used in HtmlNode class and so pulled it from Selectable class so that every class implementing Selectable class does not have to implement this method if the operation is unsupported
Replace conditional using polymorphism: In class BasicTypeFormatter, multiple conditions were used to determine the type of Basic class. Replaced this conditional by introducing BasicClassDetector interface that is implemented by all the types of Basic class. This will help in increasing code maintainability for extension in Basic class types. Hence, the BasicTypeFormatter now follows Open Closed Principle.