130 likes | 298 Views
Class Diagrams. TariffSchedule. Trip. Class diagrams represent the structure of the system. Class diagrams are used during requirements analysis to model problem domain concepts during system design to model subsystems and interfaces during object design to model classes.
E N D
Class Diagrams TariffSchedule Trip • Class diagrams represent the structure of the system. • Class diagrams are used • during requirements analysis to model problem domain concepts • during system design to model subsystems and interfaces • during object design to model classes. Enumeration getZones() Price getPrice(Zone) zone:Zone price:Price * *
Classes TariffSchedule Table zone2price Enumeration getZones() Price getPrice(Zone) Name TariffSchedule Attributes Signature zone2price getZones() getPrice() Operations TariffSchedule • A class represent a concept. • A class encapsulates state (attributes) and behavior (operations). • Each attribute has a type. • Each operation has a signature. • The class name is the only mandatory information.
Instances tariff_1974:TarifSchedule zone2price = { {‘1’, .20},{‘2’, .40}, {‘3’, .60}} • An instance represents a phenomenon. • An object is an instance of a class. • The name of an instance is underlined and can contain the class of the instance. • The attributes are represented with their values.
UML: Class and Instance Diagrams Inspector Class Diagram anonymous: Inspector joe: Inspector mary: Inspector Instance Diagram
Attributes and Values Inspector name:string age: integer joe:Inspector mary: Inspector name = “Joe” name = “Mary” age = 24 age = 18
TripLeg pricezone Associations TarifSchedule Enumeration getZones() Price getPrice(Zone) * * • Associations denote relationships between classes. • The multiplicity of an association end denotes how many objects the source object can legitimately reference.
Has-capital 1-to-1 and 1-to-Many Associations Country City 1 1 name:String name:String 1-to-1 association Polygon Point 1 * x:Integer y:Integer draw() 1-to-many association
Exhaust System Tailpipe Muffler Aggregation • An aggregation is a special case of association denoting a “consists of” hierarchy. • The aggregate is the class that contains the components (embedded objects) 1 0..2
Automobile serial number Engine year manufacturer horsepower volume model on color off weight drive purchase Battery Wheel amps volts Brakelight diameter Door charge discharge number of bolts open on close off Aggregation 2,4 3,4,5 *
TicketMachine ZoneButton Composition • A solid diamond denote composition, a strong form of aggregation where components cannot exist without the aggregate. • This is the “has-a” relationship in OOP 3
Button CancelButton ZoneButton Generalization • Generalization relationships denote inheritance between classes. • The children classes inherit the attributes and operations of the parent class. • Generalization simplifies the model by eliminating redundancy. • Names of abstract classes are usually italicized.
Red White Smooth Cortical Striate Inheritance • Models "kind of" hierarchy • Powerful notation for sharing similarities among classes while preserving their differences • UML Notation: An arrow with a triangle Cell BloodCell MuscleCell NerveCell Pyramidal
From Problem Statement to Code Problem Statement A stock exchange lists many companies. Each company is identified by a ticker symbol Class Diagram lists StockExchange Company * * tickerSymbol Java Code public class StockExchange { public Vector m_Company = new Vector(); }; public class Company { public int m_tickerSymbol; public Vector m_StockExchange = new Vector(); };