SDSU CS535 Object-Oriented Programming & Design
Fall Semester, 1996
Doc 31, Some OO Problems/Issues

[To Lecture Notes Index]
San Diego State University -- This page last updated Dec 5, 1996
----------

Contents of Doc 31, Some OO Problems/Issues

  1. References
  2. Some OO Problems/Issues
    1. Yoyo Problem1
    2. Variables Limit Reusability2
    3. Memory Management
    4. Code Management
  3. Documentation
    1. Diagrams

Doc 31, Some OO Problems/Issues Slide # 1

References


Budd, An Introduction to Object-Oriented Programming,, 1991

Cockburn, The Interaction of Social Issues and Software Architecture, Communications of the ACM, vol. 39, No 10 pp 40-46, October 1996

Taenzer, Ganti, and Podar, Object-Oriented Software Reuse: The Yoyo Problem, Journal of Object-Oriented Programming, 2(3): pp 30-35, 1989

Allen Wirfs-Brock and Brian Wilkerson, Variables Limit Reusability, Journal of Object-Oriented Programming, 2(1): pp 34-40, 1989



Doc 31, Some OO Problems/Issues Slide # 2

Some OO Problems/Issues



Yoyo problem


Variables limit reuse


Memory management


Code management


Documentation


Doc 31, Some OO Problems/Issues Slide # 3

Yoyo Problem[1]

abstract class One  {
   public void A() { print( "A, 1" );   B();   C();  }
   public void C() { print( "C, 1" );    }

   abstract public void B();
   abstract public void D();

   public void print( String message ) {
      System.out.println( message );
   }
}

class Two extends One {

   public void B() { print( "B, 2" );    D();}
   public void D() { print( "D, 2" );    }
}

class Three extends Two {

   public void A() { print( "A, 3" );   super.A(); }
   public void B() { print( "B, 3" );   super.B(); }
}

class Four extends Three {

   public void A() { print( "A, 4" );   super.A(); }
   public void C() { print( "C, 4" );   super.C(); }
}

class Five extends Four {

   public void D() { print( "D, 5" );   super.D(); }
}


Doc 31, Some OO Problems/Issues Slide # 4
Yoyo Problem


What is the result of the following program?
   public  static  void  main( String  args[] ){

      Five   yoyo = new Five();
      yoyo.A();
   }

Control Flow Trace for Function A in Class Five

Output of Program
                    A, 4                                          D, 5                      
                    A, 3                                          D, 2                      
                    A, 1                                          C, 4                      
                    B, 3                                          C, 1                      
                    B, 2                                                                    



Doc 31, Some OO Problems/Issues Slide # 5

Variables Limit Reusability[2]



Direct access to fields of a class limits the ability to modify a class

Example:
class test
   {
   public void foo()
      {
      value[20] = value[10] + 5;
      }

   public void bar()  { stuff not shown };

   private float value[] = new float[ 100 ];
}


If one changes "value" to a linked list, then all methods accessing "value" must be modified

All subclasses also must be changed



Doc 31, Some OO Problems/Issues Slide # 6

Variables Limit Reusability

Solution: Use accessor methods
class test
   {
   public void foo()
      {
      setValue(20, getValue(10) + 5);
      }

   public void bar()  { stuff not shown };

   protected float getValue(int location)
      {   return value[location];    }

   float test::setValue(int location, float newValue)
      {   value[location] = newValue;   };

   private float value[] = new float[ 100 ];
   }


Some argue that all methods in class test should use accessor methods to access fields of test

Some argue that methods in class test can access fields of test (value) directly, but all subclasses of test must use accessor methods to access fields of test


Doc 31, Some OO Problems/Issues Slide # 7
Complication: Complex fields!

If a field is a complex object with multiple operations, then how many operations do we need to access the field?

If Course has 20 methods does GraderProgram need 20 accessor methods to access activeCourse?
class GraderProgram
   {
   Course activeCourse = new Course();

   // Accessor methods for activeCourse 

   protected  void  addStudent( String name, String ID )
      {
      activeCourse.addStudent( name, ID );
      }

   protected  void  someMethodInGraderProgram()
      {
      lots of stuff here

      addStudent( name, ID );
      }

Doc 31, Some OO Problems/Issues Slide # 8
Design Principle[3]Variation Behind Interface

Intent
Protect the system integrity across changes


Force
Things change


Principle
Create an interface around predicted points of variation


Counterforce
Too many interfaces means complex, slow software

Doc 31, Some OO Problems/Issues Slide # 9

Memory Management



Object-Oriented programs tend to make heavy use of dynamic memory allocation
class A { ... };
A myVariable = new A();
myVariable = new A();

Memory leaks
C++ programs suffer from memory leaks
Use destructors to release memory from objects
Provide programmers with memory leak detectors
Stresses memory manager
Program performance can suffer


Doc 31, Some OO Problems/Issues Slide # 10

Code Management



Operations
Average size of an operation in OO program is smaller than in a procedural language
OO programs contain more operations than procedural programs



Files
C++ utilizes two files per class
Java utilizes one file per class
Inherited information is spread across multiple files


Doc 31, Some OO Problems/Issues Slide # 11

Documentation

Things needing documentation
VariablesClasses
StatementsClass relationships
Operationsinheritance
Statecollaborations
Public interfaceObjects
Private operations and stateObject relations
ContractsSubsystems
Programs
Views

Inside verses outside

Static verses dynamic

Analysis, design, code

Doc 31, Some OO Problems/Issues Slide # 12
Documentation

Variables
Statements
Methods
State
Require same type of documentation as in functional programming


Classes: three views
User of class
Subclass
Designer/implementor/maintainer


Public interface of a class or subsystem
Need to know services rendered, not implementation

Private operations and state
Documentation is for implementor and maintainer



Doc 31, Some OO Problems/Issues Slide # 13

Template for Documenting a Class

Name:                                         identifier                                    
Documentation:                                text description                              
Visibility:                                   exported/private/imported                     
Cardinality:                                  0/1/n                                         
Hierarchy                                                                                   
Superclasses:                                 list of class names                           
Subclasses:                                   list of class names                           
Generic parameters:                           for template classes                          
Public Members                                                                              
Uses:                                         list of classes used by me                    
Data members:                                 list of data members & text description       
Function members:                             list of function declarations                 
Protected members                                                                           
Data members:                                 (see above)                                   
Function members:                             (see above)                                   
Private Members                                                                             
Data members:                                 (see above)                                   
Function members:                             (see above)                                   
Subclass must implement                                                                     
Function members:                             (see above)                                   
Hierarchy graph:                              location of graph                             
State machine graph:                          graph(s)                                      
Complexity                                                                                  
Space:                                        text description                              
Time:                                         text description                              
Persistence:                                  persistent/transitory                         
Concurrency:                                  sequential/concurrent                         



Doc 31, Some OO Problems/Issues Slide # 14

Template for Documenting an Operation

Name:                                         identifier                                    
Documentation:                                text description                              
Category:                                     modifier/selector/iterator/                   
                                              constructor/destructor                        
Inheritance:                                  new/refine/override                           
Formal Parameters:                            parameter declarations                        
Return value:                                 type/class name                               
Preconditions:                                PDL                                           
Action:                                       PDL                                           
Postconditions:                               PDL                                           
Exceptions:                                   list of exceptions                            
Concurrency:                                  sequential/concurrent                         
Complexity                                                                                  
Space:                                        text description                              
Time:                                         text description                               
                                                                                            


PDL - program description language

Doc 31, Some OO Problems/Issues Slide # 15

Diagrams

Class Collaborations
               Association                              Ternary Association               


  Multiplicity of  Associations                        Link Attribute                      


Aggregation

Messages


Doc 31, Some OO Problems/Issues Slide # 16
Diagrams

Event Flow Diagram



Object Diagrams



Doc 31, Some OO Problems/Issues Slide # 17
Diagrams for Dynamic Behavior
Event Trace Diagram

State Diagram of Car Transmission


Doc 31, Some OO Problems/Issues Slide # 18
Diagrams for Dynamic BehaviorConcurrency
Petri Net



----------