<<< C++ and OO design     Index     Structured programming >>>

2. Problems to solve

  • 
    void print( Printer* pr )
    {
        if ( pr->type == 'L' ) {
            // ...
        } else if ( pr->type == 'I' ) {
            // ...
        } else if ( pr->type == 'F' ) {
            // ...
        }
    }
    
    
  1. Print function becomes very complex over time.

  2. Multiple flag variables introduced to control the if-else logic.

  3. Only experienced veteran programmers understand how it works.

  4. New programmers become frustrated when assigned to make changes in print( )

  5. . . .

  • Solutions?

    • C++ OO design.

<<< C++ and OO design     Index     Structured programming >>>