CSE 283 Introduction to Object Oriented Design

Barbara Nostrand, Ph.D.

Designing Classes and Packages

Your first course in software engineering probably emphasized structured programming.  Your programs probably consisted of collections of functions.  In Object Oriented Programming,  programs consist of collections of classes.  Instead of functions we have either static methods which are attached to classes or instance methods which are attached to individual objects specified by classesObjects are not actions they are entities.  Consequently,  Object Oriented Design begins by identifying what objects are needded and sorting them into classes

Extreme Programming

Discovering Classes

Using CRC Cards to Manage Classes

CRC stands for “classes”,  “responsibilities”,  “collaborators”.  Once you have completed a set of CRC cards for your application,  you should continue your analysis and design activity by developing class and method charts similar to those we have been using in the excercises.  UML (Unified Modeling Language) diagrams can help you keep track of class inheritance and class dependencies.  The CRC card method is intentionally informal.  The CRC card method proceeds as follows: 

Designing and Implementing Classes

Developing and Documenting Methods

While you may be tempted to immediately start writing the final code for your various methods one method at a time,  actual software practice suggests that this is a poor strategy.  Instead,  you should begin by embedding your documentation into your source file,  and then systematically fill in the executable code.  You should do each of the following activities before you become very involved in writing the final version of the executable statements in your method: 

  • You should begin to develop a method by copying the external specifications and algorithm descriptions into your source file as comments.  The various parts of your method should appear immediately after the corresponding comment that you created at this stage. 
  • Next,  create the calling sequence (access and ownership qualifiers,  return type,  method name,  parameter list,  and optional throws notification. 
  • Follow the calling sequence with a statement block containing an appropriate dummy return statement if required.  This will allow you to call the method before it is finished. 
  • Further,  you should write your Javadoc comments at this time.&nbps; These will include at a minimum a brief description of the method,  the return type,  and the calling sequence.  For example: 
        Represents Rational Numbers Q in reduced form. 
    public class Fraction {
        private int numerator, denominator; 
    /** Add a Fraction
        @return a new Fraction containing the sum of the Fraction object and the Fraction passed as
                a parameter. The new Fraction is returned in reduced form. 
        @param fraction the Fraction to be added to the contents of the local Fraction object.
        public Fraction add(Fraction fraction) {
           return new Fraction(this.numerator()*fraction.denominator()+fraction.numerator()*this.denominator(),

    Last modified: 2007 OCT 29