O'Reilly logo

Mastering C++ Programming by Jeganathan Swaminathan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Conditional complexity

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() ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required