JMU
Object-Oriented Programming
An Introduction


Prof. David Bernstein
James Madison University

Computer Science Department


Overview
The OOP Paradigm
Classes and Objects
Creating Classes
An Important Distinction
Intercommunication
Data Hiding
Encapsulation
Visibility
Instantiating Objects
Types of Relationships
Relationships: Association

Class A is said to be associated with class B if an object in class A can send a message to an object of class B or if an object in class A can create, receive or return objects of class B.

images/association-university.gif

Relationships: Dependency

Class A is said to depend on class B if method in an object of class A is passed an object of class B.

images/dependency-student.gif

Relationships: Aggregation

An object of class A is an aggregate of an object of class B if B is a part of A. It is also often called the "has a" relationship though the phrase "has a" is ambiguous (e.g., a car has a color and a car has a radiator mean very different things).

images/aggregation-university.gif

Relationships: Composition

An object of class A is composed of an object of class B if B is a part of A and A controls the life of B (e.g., if A is destroyed then B will be destroyed). Thus a component can be associated with exactly one composite (making the multiplicity implictly 1).

images/composition-university.gif

Relationships: Specialization

An object of class A "is-an" object of class B if A is/does everything that B is/does and more.

images/specialization-funds.gif

Abstract Classes
Interfaces
Polymorphism
Parameterized Classes
Utility Classes
Packaging
Packaging (cont.)
Exception Handling
Exception Handling (cont.)

          try 
          {
	       d = StringToDouble(s);
 
	       // If we get here things are OK
          } 
          catch (NumberFormatException nfe)
          {

	       // If we get here there was a problem
          }
          

Software Design Patterns
Software Design Patterns (cont.)