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

Properties of Good Classes

Samples of Classes

Design Rules

Packages

Large Software systems may have dozens,  hundreds,  or even thousands of classes.  Simply distributing these classes over a collection of files in a single directory isn't enough to keep track of all of these individual class definitions.  What we want is some sort of heirarchical system.  In Java,  packages allow us to heirarchically structure our software components.  A package is a set of related classes. 

You can specify the package at the top of any Java source file.  The specified package name is automatically added to the front of the fully qualified name for each of the classes defined in the file.  If a package name is not specified,  then the default package is assumed.  If you want to use a class from a package,  then you can either use the fully qualified name every time you use a class from the package,  or you can import either the specific classes you need from a package or the entire package. 

        import java.util.Scanner;       // Imports the Scanner class
        import javax.swing.*;           // imports the entire swing package
Classes belonging to the same package must be compiled and all of the source files and object files saved in the same directory or the same cluster in a database.  The package name identifies either a directory in a heirarchical directdory system or a cluster in a data base system.  Please consult Packages.java for a simple example. 

Java Class Library

The Java Class Library consists has dozens of predefined classes organized into a heirarchy of packages.  A few commonly used pacages are as follows: 

PackagePurposeSample Class
java.langLangauge supportMath
java.utilUtilitiesRandom
java.ioInput and OutputPrintStream
java.awtWindows PrimitivesColor
java.appletAppletsApplet
java.netNetworkingSocket
java.sqlDatabase AccessResultSet
javax.swingSimplified WindowsJButton
javax.rmi.CORBADistributed SystemsIntHolder

Special Libraries

The Textbook and Assignments use a number of special purpose libraries as follows: 

PackagePurposeSample Class
ann.easyioTextbook: Simplified Terminal I/OKeyboard
ann.guiTextbook: Simplified GUI I/OCartesianPanel
ann.mathTextbook: Common Mathematical ObjectsMatrix
ann.math.polynomialTextbook: PolynomialsPolynomial
ann.utilTextbook: Common Software ObjectsStack
hojAssignments: Assertions and FilesAssertion

The easiest way to handle these special purpose libraries is to creaty a directory called libraries and load each of the directory hierarchies into it.  Next,  compile each of the Java files in the libraries Hierarchy.  Then,  set the Java classpath for JGRASP to include your libraries directory.  Once you have done this,  your Java program should be able to include these classes in the same way that you include classes from the Java Class Library. 




Last modified: 2007 OCT 29
bnostran@syr.edu