September 2017
Beginner to intermediate
384 pages
8h 4m
English
Conditional complexity code smell is about complex large conditions that tend to grow larger and more complex with time. This code smell can be refactored with the strategy design pattern. As the strategy design pattern deals with many related objects, there is scope for using the Factory method, and the null object design pattern can be used to deal with unsupported subclasses in the Factory method:
//Before refactoringvoid SomeClass::someMethod( ) { if ( ! conition1 && condition2 ) //perform some logic else if ( ! condition3 && condition4 && condition5 ) //perform some logic else //do something } //After refactoringvoid SomeClass::someMethod() { if ( privateMethod1() ) //perform some logic else if ( privateMethod2() ...