This
page is for students enrolled in the Fall 2006 Object
Technologies Raytheon PEP course.
|
|
Goals:
To learn about Object Orientation
(OO); Object Oriented Analysis (OOA), Object Oriented Design (OOD), and Object
Oriented Programming Languages (OOPL).
The class is loosely based upon one of the same name as taught at the
Loyola Marymount University Computer Science graduate
school by Ray Toal, Ph.D.
Class Schedule:
Twelve meetings, Wednesdays at noon
starting 21 April. Building B1, Room S827. (Computer training
room on North side of the building).
Text:
Core Java
Volume I - Fundamentals. Horstmann
and Cornell, Prentice Hall. ISBN 0-13-089468-0. This
book provides an introduction to the Java programming language.
Expect to use the Web as a learning
resource. I have included some good links below.
Recommended books:
Object-Oriented Analysis and
Design with Applications.
Grady Booch. ISBN 0805353402
This is
still the best book to learn the classical OO approach, in my opinion. It is
considered something of a classic. It's the basis for the first several
sessions of the class, and I have shamelessly included Grady's OO cartoons in
my slides. (this is called "fair use", it's
not a copyright violation ;-) The book predates the UML, so the notation used
is somewhat dated.
The Unified
Modeling Language User Guide. Grady Booch,
et al. ISBN 0-201-57168-4.
UML is de
rigeur nowadays for OO designs. The melding of
three major OO notational schemes, it has become the official OO notational
scheme for the Object Management Group (OMG), an International consortium of
companies and individuals interested in OO. UML is used to model and document
the static and dynamic properties of an OO system. Software job requisitions on
Raysearch now commonly require knowledge of the UML.
Design Patterns, Elements of
Reusable Object-Oriented Software.
Erich Gamma, et al. ISBN 0201633612
This text
on design patterns, the "Gang of Four" design patterns book, is
considered a classic. It is in its 24th printing, and is unrevised
from its initial 1994 release! The text is not a tutorial on object
technologies: rather, it's a catalog of re-usable object oriented software, as
its title states.
Instructor:
Robert G. (Bob) Hayes, Senior
Principal Software Engineer, Raytheon Vision Systems (RVS).
805.562.2336 (W)
hayes"at"raytheon.com
http://home.earthlink.net/~object_technologies
None, though the class will be
primarily oriented towards software developers. A willingness/ability to
"free your mind" from being bound by legacy, non-OO programming
languages and systems is required to truly benefit from the class.
It's necessary to program in some
object-oriented language to truly learn the concepts. We're going to use Java
in class, though you may wish to use some other language. A note: Visual Basic
is not an object-oriented language, though you can certainly
implement object-based designs with it.
A particularly appropriate Java
environment for learning OO is the BlueJ IDE
(Integrated Development Environment) offered for free from www.bluej.org. Developed by European academics, BlueJ runs on top of the Java JDK (Java Developer's Kit)
which can be obtained, again for free, from Sun's Java website http://java.sun.com. BlueJ allows the
student to quickly start creating classes and running programs, in a more
benign environment than that offered by the Java JDK. BlueJ
uses a UML (Unified Modeling Language) class diagram to create class
hierarchies, and can do some other very cool things, such as:
This is a very
cool tool, especially when you consider that it's free.
I've posted up a BlueJ
project Shapes.jar that you can download. See the link at the top of the page and the
discussion below.
Eclipse:
If you think you're ready to
graduate from BlueJ, you might want to take a look at
a more sophisticated, yet still free Java IDE, called Eclipse.
Originally developed by a consortium of "anybody but
Microsoft" companies, this is a sophisticated tool. You might like it better than NetBeans, Sun's freeware Java IDE.
Java
at Raytheon:
What is likely the largest software
development underway at Raytheon?
Raytheon is systems integrator for the new DDG 1000 destroyer - and
they're using Java! The Real Time
Specification for Java
(RTSJ), to be exact. Read about it here.
Here's an article about Java's
movement into the embedded domain,
including military systems such as those we design and create at Raytheon.
Links:
Here are some useful links. There is an immense amount of useful information on Object Technologies available on the web. In particular, I recommend reading through the OO Frequently Asked Question (FAQ) at the second link.
http://www.cetus-links.org/ About 20,000 links to all
things OO.
http://www.cyberdyne-object-sys.com/oofaq2/ Official OO FAQ list.
http://www.toa.com/pub/oobasics/oobasics.htm
http://www.microsoft.com/com/default.asp Learn all about COM.
http://www.eiffel.com/ Home
of Bertrand Meyer and our neighbors across the street in
http://www.rational.com/ Home
of the "Three Amigos" and the Rational Unified Method.
http://www.togethersoft.com/ Now owned by Borland. Offers pro quality OO
development IDE.
http://www.industriallogic.com/papers/learning.html#NAVIGATION
http://www.gentleware.com/ Offers pro-quality OO IDE.
http://gamemaker.nl For those who don't want
to do Java. They teach
children OO with this.
http://www.bluej.org/ A really
cool development environment for learning OO using Java.
http://www.eclipse.org/ A
popular free Java IDE
![]()
I've created a BlueJ
project to demonstrate a simple OO system that includes a class hierarchy and
polymorphism. The project is saved in
the Java archive format ("jar" format). I've setup the class structure completed
several of the classes. See if you can
implement the subclasses of the abstract class Triangle.
![]()
Here is an
outline for the course. Take it with a grain of salt: we almost certainly won't
cover all of these topics, and the ordering may get re-arranged to some extent.
This course is attempting to cover in 12 one-hour informal sessions what is
usually a graduate-level Computer Science course with prerequisites, 45 hours
of class meetings, homework, and exams.
![]()
See
how many of these you can define.
|
Class |
Object |
|
Polymorphism |
Inheritance |
|
Abstraction |
Interface |
|
Instance |
Type |
|
Scope |
Extent |
|
Persistence |
Extention |
|
Visibility |
Use Case |
|
Stereotype |
Constraint |
|
Aggregation |
Composition |
|
Association |
Scenario |
|
Framework |
Component |
|
Encapsulation |
Message |
|
Method |
Member |
|
Class Variable |
Modularity |
|
Generalization |
Specialization |
|
Refinement |
Superclass |
|
Subclass |
Field |
|
Constructor |
Destructor |
|
Garbage Collection |
Identity |
|
State |
Behavior |
|
Pattern |
Virtual Machine |
|
Package |
Abstract Class |
|
Abstract Data Type |
Collaboration |
|
Concurrency |
Monitor |
|
Thread of control |
Process |
|
Late (dynamic) binding |
Strongly typed |
|
Weakly typed |
Protected |
|
Public |
Private |
|
Static binding |
Static Parametric Polymorphism |
|
Instance Variable |
Concrete Class |
|
Friend |
Implementation |
|
Information Hiding |
Instantiation |
|
Metaclass |
Class Diagram |
|
Interaction Diagram |
Object Diagram |
|
Signature |
Virtual Function |
|
Finalization |
Class method |
|
Overloading |
Coupling |
|
Delegation |
Member Function |
|
Operation |
Overriding |
|
Toolkit |
Deployment Diagram |
|
Primitive Type |
Sequence Diagram |
|
View |
Mutual Exclusion |
|
Parent Class |
Base Class |
![]()
How
many of these can you answer?
1. The main elements of the Object
Model are
2. UML stands for
3. COM stands for
4. C is an Object-Oriented
programming language. T F
5. Every Java program is Object
Oriented. T F
6. It’s possible to write top down,
structured programs using C++. T F
7. Objects are created in an OO
programming language using a constructor. T F
8. An object is an instance of a
class. T F
9. In Java, Interfaces can have a hierarchical
relationship to other interfaces. T F
10. COM supports inheritance. T F
11. COM promotes binary reuse. T F
12. Abstraction is one of the
fundamental ways humans cope with complexity. T F
13. Bob Hayes is a great instructor
and the funniest and most intelligent person I have ever met. T F
14.
15. Java and C# incorporate support
for concurrency. T F
16. C++ incorporates support for
concurrency. T F
17. Every object is a monitor in C#. T F
18. Every object is a monitor in
Java T F
19. A method is a function defined
by a class. T F
20. The concept of OO class is
closely related to that of type. T F
21. Visual Basic is an
object-oriented programming language. T F
22. Java allows multiple
inheritance. T F
23.
24. In Java, Object is
a class, and Class is an object. T F
25. CORBA stands for
26. Protected, Private,
and Public are each visibility modifiers in Java. T F
27. Adapter and Observer
are structural design patterns. T F
28. An object’s members
are its fields and methods. T F
29. A constructor is invoked just
like any other method. T F
30. A method differs from a
traditional function in that there is an implicit parameter that is a reference
to the object. T F
31. The most powerful aspects of OO
are generally considered to be:
32. The three characteristic
features of an object oriented programming language are:
33. An object can exhibit behavior
that’s not defined by its class. T F.
34. A programming language that
doesn’t implement inheritance can be considered object-oriented. T F.
35. The terms method and member
function are synonymous. T F.
36. Java supports the use of
pointers for referencing methods. T F.
37. In Java, the type of a method is
part of its signature. T F.
38. In C++, all functions must be
defined as part of some class. T F.
39. In Java, all methods must be
defined as part of some class. T F.
40. C++ supports multiple
programming paradigms. T F.
41. Java and C++ are both block
structured programming languages. T F.
![]()
An abstract class Shape with
two abstract methods, area() and circumference(). The classes Circle,
Rectangle, and Square are subclasses of Shape. Each of the
subclasses provides a concrete method for area() and circumference().
public and protected are visibility modifiers and
are used with both data (i.e. instance variable) and methods.
public abstract class Shape {
// The
existence of even one abstract method makes the class itself abstract: you
// cannot instantiate a Shape object: however, it is a true class. For example,
you
// can declare an array of type Shape.
public
abstract double area(); // abstract method
public
abstract double circumference(); // abstract method
}
class Circle extends Shape {
protected
double r; // instance variable (field)
protected
static final double PI = 3.14159265358979323846;
public
Circle() { r = 1.0; } // constructor
public
Circle (double r) {this.r = r;} // constructor
public
double area() { return PI * r * r; } // concrete method
public
double circumference() { return 2*PI*r; } // concrete method
public
double getRadius() { return r; } // accessor method
}
class Rectangle extends Shape {
protected
double w, h; // instance variables
public
Rectangle() { w=0.0, h=0.0; } // constructor
public
Rectangle(double w, double h) {this.w = w; this.h = h;} // constructor
public
double area() { return w * h; } // concrete method
public
double circumference() { return 2 * (w + h); } // concrete method
public
double getWidth() { return w; } // accessor method
public
double getHeight() { return h; } // accessor method
}
class Square extends Shape {
protected
double s;
public
Square () { s = 0.0; }
public
Square (double s) { this.s = s; }
public
double area () { return s * s; }
public
double circumference () { return 4 * s; }
public
double getSide() { return s; }
}
We could write the following code to
use the classes defined above. We declare an array of type "array of Shape
objects" and fill it using constructors for the various shapes. We then
see dynamic polymorphism as the array is iterated with each object
having its area() method invoked to sum the areas of the shapes in the
array. The Java runtime (i.e. the Java Virtual Machine, or JVM) dynamically
binds the shapes[i].area() method invocation
to the proper method for the object involved.
Shape[] shapes = new Shape[3]; //
create an array to hold the shapes
shapes[0] = new Circle (2.0); //
fill the array …
shapes[1] = new Rectangle (1.0,
3.0);
shapes[2] = new Square (4.0);
double total_area
= 0.0;
for (int i = 0; i < shapes.lenth;
i++)
total_area += shapes[i].area();
// compute the total area of the shapes in the array
![]()
A C
Equivalent
// C program that is roughly
equivalent to the Java Shape code above.
// We get some encapsulation with
the shapeStruct structure, but no inheritance,
// limited abstraction, little modularity, limited heirarchy,
no dynamic binding,
// limited data hiding, relatively weak typing, explicit memory management,
// no polymorphism, and lots of pointer use.
// Consider the following code in
the scenario where you want to add another shape
// type, for example a triangle. What has to change?
// macros
#include <ansi_c.h>
#define PI 3.141592653
// typedefs
enum shapes {Circle, Square, Rectangle};
typedef struct {
int shapeType;
double param1;
double param2;
double (*getArea)();
double (*getCircumference)();
} shapeStruct;
// prototypes
double (*functionPointer)
(shapeStruct *);
double circleCircumference (shapeStruct
*);
double circleArea (shapeStruct
*);
double squareArea (shapeStruct
*);
double squareCircumference (shapeStruct
*);
double rectangleArea (shapeStruct
*);
double rectangleCircumference (shapeStruct
*);
shapeStruct * newShape (int shapeType, double param1,
double param2);
void destroyShape (shapeStruct
* shape);
// functions
int main (int argc, char *argv[]) {
char
charBuffer[128];
double totalArea
= 0;
double totalCircumference
= 0;
int i;
int shapeCount = 0;
shapeStruct
* shapeArray[100];
//
Make some shapes
shapeArray[0] = newShape (Circle,
1, 0);
shapeCount++;
shapeArray[1]
= newShape (Square, 3, 0);
shapeCount++;
shapeArray[2]
= newShape (Rectangle, 2, 4);
shapeCount++;
//
Calculate the total circumference
for
(i = 0; i < shapeCount; i++) {
functionPointer = shapeArray[i]->getCircumference;
totalCircumference
+= (*functionPointer) (shapeArray[i]);
}
//
Calculate the total area
for (i = 0; i < shapeCou