/
dot-dot
dot

Title:TThier/Languages/uml/demo10
Author: Dan Bikle


This page contains some notes about Object Oriented Design,
Object Oriented Analysis, and UML.

A simplistic discussion about Object Oriented jargon is linked below:

ooConcepts.txt

I downloaded a UML modeling tool named Poseidon from 
http://gentleware.com.

Here is a UML Class diagram for a Car:

Car.png

Here is some corresponding Java code:

Car.java

Here is a UML Class diagram demonstrating the concept of Inheritance ('is a' Relationship) where:
A VW Bug 'is a' car.
A Chevy Nova 'is a' car.
A Ford Pinto 'is a' car.
The above three car types are classes which inherit from the more general Car class.
This perspective of inheritance is called specialization.

inheritanceDiagram.png

Here is some corresponding Java code:

VWbug.java.html
FordPinto.java.html
ChevyNova.java.html


Here is a UML Class diagram demonstrating the concept of 'has a' Relationship (Aggregation).
A car 'has a' motor.  This is an example of a 'has a' Relationship.

A diagram:

hasaDiagram.png

Here is some corresponding Java code:

Car.java
Motor.java

Here is a UML Class diagram demonstrating the concept of 'has a' Relationship (Composition).
Think of a package-deal-trip to Hawaii which has objects which disappear if the trip is cancelled:

TripComposition.png

Here is some corresponding Java code:

Trip.java

FlightReservaton.java
CarReservation.java
HotelReservation.java

When Poseidon generated the above code, I noticed that the tool did not establish a difference
between Aggregation and Compostion.  The difference is evident in the diagrams however.
Notice the Aggregation relationship is signified by a white diamond and the Composition
relationship is signified by a black diamond.

Here is a UML Class diagram demonstrating the concept of a 'uses' Relationship:

TruckUsesGas.png

Here is some corresponding Java code which demonstrates the concept of
a 'uses' Relationship.  Unfortunately, Poseidon did not place the Java code into
Truck.java for me; I had to do that by hand. 

Truck.java
TankOfGas.java

Here is a UML Class diagram demonstrating the concept of Polymorphism coupled with 
Inheritance:

DocumentPoly.png

Here is some corresponding Java code:

Document.java
SpreadSheet.java
WebPage.java

Here is a UML Class diagram demonstrating the concept of Encapsulation.  One phrase
which describes Encapsulation is 'data-hiding'.  The UML and Java below show a class
which has some 'private' data which is accessible via a public method:

TimeStamp.png
TimeStamp.java

Listed below is a UML Class diagram (and some Java) demonstrating the concept of
Collection.  

ParkingLot.png
ParkingLot.java
Vehicle.java

Poseidon did not seem to do it the way I wanted so I
doctored it up by hand.  Both the code and the model are the same as
what is shown in the 'has a' Relationship (Aggregation) except that
the vehicle object is implemented as an array.  Java has some nice 
collection classes which I could have used instead of the array:
http://java.sun.com/j2se/1.4.2/docs/guide/collections/reference.html

The Java Collection Class which might model a parking lot well would be a 'HashMap':
http://java.sun.com/j2se/1.4.2/docs/api/java/util/HashMap.html

An ordinary array, though, would do an acceptable job of modelling a
parking lot.  The lot has a set number of spaces; each space could
have a unique number.  Each space could either be empty or contain a
vehicle.  An object of type java.utl.Vector would work well also.

Next is a diagram and some Java code to demonstrate the concept of a Package:

BirthdayCake.png
BirthdayCake.java
com/bikle/recipes/BirthdayCake.java

Notice that BirthdayCake.java is in a different directory than 
com/bikle/recipes/BirthdayCake.java
This is a good design; it allows me to keep the two classes separated.
Even though they have the same name, they are different classes; I need to keep 
them separated.  Another obvious point is that any class you write should
be placed in an appropriate package from the start.  Avoid writing classes which
are packageless.  This is like putting all of your files, spreadsheets, and e-mail
in one directory; you eventually encounter problems finding things and also
run the risk of creating two very different files which happen to be named
the same thing (and one of the files gets overwritten by the other).


Google

google.com bikle.net bikle.com