Class Diagrams

UML is the common language of all software engineers. There are 10 types of UML diagrams. The most important type is the class diagram. In the requirements phase class diagrams are used to model application data. In the design phase class diagrams are used to model the application's internal structure.

You must become proficient at performing following translations:

Note that the implementation and reverse engineering translations can be performed by most CASE tools. This doesn't mean you don't need to know how to do the translations yourself, nor should you rely on these code generators (and certainly NEVER submit machine generated code for your homework). Rather it just emphasizes the fact that the translations are routine and mechanical and therefore should be easy to master.

Basics

Problem 1

Draw a single UML class diagram that models the following sentences:

1)    A implements B.

2)    B extends C.

3)    A extends D.

4)    A depends on E.

5)    Every instance of A uses 3 instances of F. Every instance of F is used by 2 instances of A.

Problem 2

Translate each sentence into a UML class diagram. Each diagram should be placed in a separate package. The name of the package should be the name of the domain.

1)    Person X is the parent of Person Y.

2)    A cat is a mamal. A canary is a bird. Birds and mamals are animals. Cats eat birds.

3)    A triangle has three vertices.

Reverse Engineering

Problem 3

Translate the following Java class declaration into a UML class diagram:

class Adult extends Person {
   private Adult spouse;
   private Set<Person> children;
   protected double income;
   public Phone[] phoneNumbers = new Phone[3];
   private boolean male;
   private String fname, lname;
   private Date birthDay;
   public int getAge(String units) {
      // computes age in units = years, months, or days
      return 0; // for now
   }
}
  

Problem 4

A UML class icon allows us to show details such as attributes (primitive typed fields) and operations (methods without their implementations). In addition, we can show the scope of an attribute or operation (public, protected, package, or private). We can also indicate if an attribute or operation is static and if an operation is abstract. We can show the type and initial value of an attribute and the parameters and return type of an operation.

Translate the following Java declaration into a class diagram:

abstract class GUIComponent {
   protected int xc = 10, yc = 10; // position of bounding box
   protected int width = 10, height = 10; // size of bounding box
   static long NEXT_OID = 500;
   private long oid = NEXT_OID++;  // unique object ID
   private static final int OID = 500;
   public boolean move(int x, int y) {
      xc = x;
      yc = y;
      return paint();
   }
   public void grow(int dw, int dh) {
      width += dw;
      height += dh;
      paint(); // no return
   }
   // returns true if successful:
   abstract public boolean paint();
}

Problem 5

Translate the following class declarations into class diagrams.

Dungeon.java

Window.java

Media.java

GraphViewer.java

DanubeBooks3.java

Measurer (all .java files)

Implementation: Mapping Designs to Code

Translate the following class diagrams into Java class declarations without using a code generator. Add needed administrative methods such as constructors, getters, and setters. Your implementation should compile and run, even though it may do nothing. In particular, don't add unspecified business logic.

Hint: use arrays or collections for unbounded multiplicities. Be sure to provide administrative methods for adding, accessing, counting, and removing members of the array/collection.

Problem 6: A Project Management System

Domain Modeling

Recall that an analysis model consists of three types of objects:

Entity objects represent entities in the application domain such as events, actions, roles, actors, and things.

For each of the following applications draw a class diagram showing the important classes of entities and their relationships.

Problem 7: Paint

Paint programs allow artists to create paintings using computers. In a paint program a virtual studio contains a palette, tools, and a canvas. A canvas contains shapes. Polygons and lines are shapes. Brushes, pens, and erasers are some types of tools. A palette contains colors.

Problem 8: Social Network

Social networking applications like LinkdIn and Facebook allow people to join networks of other users. An online social network has many participants. Each participant has a blog, a feed, a profile, and many friends (who are also participants). A blog consists of many entries. An entry has a date, text, a teaser, and may have a photo. A teaser consists of the entry's first line and the photo, if there is one. A feed is a list of teasers from the blogs of the owner's friends.

Problem 9: HR Management

An HR management system views a company as a collection of employees. Employees are persons with name, date of birth, and gender attributes. An employee may have one or more dependents (spouse, children). Dependents may or may not be employees. Each employee has a benefits package which includes a medical plan and a retirement plan. There are two types of medical plans: HMOs and PPOs. There are two types of retirement plans: IRAs and SEPPs.

Problem 10: Ultimate Warrior

Problem 11: CASE

A CASE tool allows users to create UML use case diagrams such as this one: