Vous êtes sur la page 1sur 16

Class Diagram Associations

Class Diagrams, Class Stereotypes, Class Associations


Dr. Neal CIS 480

Class Diagram

Provides definition of system components Contains important structural information for the new system

Provides details describing database and object-oriented program


Consists of problem domain classes and implementation classes Provides a static view of the system

UML Class Representation


Rational

Class Stereotypes and Views


Label representation
<<entity>> DataEntity <<control>> Control <<Interface>> MessageI <<boundary>> SystemBoundry <<Actor>> Actor
<<Table>> CustomerT

Message1 DataEntity1 Control1 SystemBoundry1 Actor1

Same class different view


CustomerT

Icon representation

Bank Account Class Associations

Navigable association

Inheritance association

Unidirectional and Navigable Associations


Unidirectional Customer knows about Order, but Order doesnt know of customer

Bidirectional or Navigable Customer knows about Order and Order knows about Customer

Class to Class Messages


public class Customer { // some attributes protected String name; protected Order[] OrderList; public class Order { // some attributes protected String customerName; protected Customer CustomerOwner; // some methods public setCustomerName(String name) { customerName = name; } } Call or message to Order object

Array of Order objects

// some methods private void doName() { OrderList = new Order[2]; OrderList[0] = new Order(); OrderList[0].setCustomerName(name); } }

A Generalization/Specialization Hierarchy for Motor Vehicles

Class Specialization
public class Customer { // some attributes protected String name;

Superclass

// some methods private void doName() { // do something } }

Colon key word for subclass

Subclasses

public class Commercial : Customer { // some attributes // some methods } public class Consumer : Customer { // some attributes // some methods }

Aggregation or Whole-Part Relationships

Class Aggregation
Car 1 1 1 Wheel 1..n Engine

Aggregate class

public class Car { // some attributes protected Wheel[] WheelList; protected Engine ClassEngineOject; // some methods }

Parts classes

public class Wheel { // some attributes // some methods } public class Engine { // some attributes // some methods }

Object collection for wheels and single id for engine

Enrollment Class Diagram with Association Class

Association Class
Association class
public class Shipment { // some attributes public Vendor VendorObject; public Product ProductObject // some methods } public class Vendor { // some attributes protected Product[] ProductList; // some methods } public class Product { // some attributes protected Vendor[] VendorList; // some methods }

Other classes

Multiple Inheritance by Interfaces

Sometimes a class needs to provide behavior matching more than one class If the class is already of subclass of another base class then inheritance cant be used so how is this additional behavior guarantee We need a relationship that establishes a contract for one class to implement another's behavior The behavior can be defined with an Interface The Realizes relationship forces the interface to be implemented by the class In this way a class may Realize the behavior of multiple classes

Multiple Inheritance the Realizes Relationship


Base class

Multiple Inheritance using an Interface

Sub class

public class Window { // some attributes // some methods } public class ListBoxControl : Window, MessageInterface { // some attributes // some methods Boolean receiveMessage(String msg) { // do something } } public interface MessageInterface { // some method signatures Boolean receiveMessage(String msg); }

ListBoxControl has a contract to implement methods

Contract or Interface class

Partial Domain (static) Class Diagram for RMO

Vous aimerez peut-être aussi