<<< Problems to solve     Index     Encapsulation >>>

3. Structured programming

  • Create functions for each individual case:

    
    void print_Lazer( Printer* pr /*etc.*/ );
    
    void print_InkjetPrinter( Printer* pr /*etc.*/ );
    
    void print_FaxMachine( Printer* pr /*etc.*/ );
    
    void print( Printer* pr )
    {
        if ( pr->type == 'L' ) {
            print_Lazer( Printer* pr /*etc.*/ );
    
        } else if ( pr->type == 'I' ) {
            print_InkjetPrinter( Printer* pr /*etc.*/ );
    
        } else if ( pr->type == 'F' ) {
            print_FaxMachine( Printer* pr /*etc.*/ );
        }
    }
    
    
  • Problems yet to be solved:

    • if-else still remains a complexity!

    • boolean flag variables still haunt programmers!

    • functions still have too many input parameters!

<<< Problems to solve     Index     Encapsulation >>>