420 likes | 849 Views
Chapter 3 , Class Diagram. Outline of this Class. Activity diagrams Describe the dynamic behavior of a system, in particular the workflow. Class diagrams Describe the static structure of the system: Objects, attributes, associations Use case diagrams
E N D
Outline of this Class • Activity diagrams • Describe the dynamic behavior of a system, in particular the workflow. • Class diagrams • Describe the static structure of the system: Objects, attributes, associations • Use case diagrams • Describe the functional behavior of the system as seen by the user • Sequence diagrams • Describe the dynamic behavior between objects of the system • Statechart diagrams • Describe the dynamic behavior of an individual object
zone:Zone Price: Price TarifSchedule Trip Table zone2price Enumeration getZones() Price getPrice(Zone) * * Class Diagrams • Class diagrams represent the structure of the system • Used • during requirements analysis to model application domain concepts • during system design to model subsystems • during object design to specify the detailed behavior and attributes of classes.
Name TarifSchedule TarifSchedule TarifSchedule Attributes Table zone2price Enumeration getZones() Price getPrice(Zone) zone2price getZones() getPrice() Operations Classes Type Signature • A class represents 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
zone2price = { {‘1’, 0.20},{‘2’, 0.40}, {‘3’, 0.60}} zone2price = { {‘1’, 0.20},{‘2’, 0.40}, {‘3’, 0.60}} tarif2006:TarifSchedule :TarifSchedule Instances • An instance represents a phenomenon. • The attributes are represented with their values. • The name of an instance is underlined. • The name can contain only the class name (TarifSchedule) of the instance (anonymous instance).
Actor vs Class vs Object • Actor • An entity outside the system to be modeled, interacting with the system (“Passenger”) • Class • An abstraction modeling an entity in the application or solution domain • The class is part of the system model (“User”, “Ticket distributor”, “Server”) • Object • A specific instance of a class (“Joe, the passenger who is purchasing a ticket from the ticket distributor”).
Enumeration getZones() Price getPrice(Zone) TarifSchedule TripLeg PriceZone * * Associations Associations denote relationships between classes. The multiplicity of an association end denotes how many objects the instance of a class can legitimately reference.
City Country 1 1 name:String name:String Point Polygon * x: Integer y: Integer draw() 1-to-1 and 1-to-many Associations 1-to-1 association 1-to-many association
Many-to-Many Associations Company * * StockExchange tickerSymbol
Exhaust system TicketMachine ZoneButton 0..2 1 Muffler Tailpipe diameter diameter 3 Aggregation A solid diamond denotes composition(“contains-a”): A strong form of aggregation where the life time of the component instances is controlled by the aggregate. That is, the parts don’t exist on their won (“the whole controls/destroys the parts”). • An aggregation is a special case of association denoting a “consists-of / part-of / has-a” hierarchy. • The aggregate is the parent class, the components are the children classes.
Difference of Aggregation and Composition • BirörnekArabadır. ArabaParçalarındanoluşur. Bu parçalarasahiptir. EğerbirParçayoksaarababozuktur. ArabaParçalarıylaCompositionoluşturur. • AyrıcaArabanınYolcularıvardır. YolcularArabanınParçasıdeğildir. EğerbirYolcuyoksaArababozukdeğildir. ArabaYolcularınasahipdeğildir. Arabadadeğillersebaşkabiryerdedirler. İlişkigeçicidir. Yolculargelirvegider. ArabaveYolculararasındaAggregationilişkisivardır. • Her ikiilişkiaslındaComposition’dır. Arabanın hem Parçaları hem de Yolcularıvardır. Farklılıksüresindedir. Parçalarlaolanilişkidaimidir, Yolcularlaolanilişkigeçicidir.
Without qualification File Directory 1 * filename 1 Directory File filename Qualifiers With qualification 0..1 • Qualification: A technique for reducing the multiplicity of associations by replacing many-to-many or one-to-many associations qith qualified associations. • Qualified association: An association in which one end is indexed by an attribute. • Qualifiers can be used to reduce the multiplicity of an association.
* Lists * Company StockExchange Qualification: Another Example Company * * Lists StockExchange tickerSymbol 1 tickerSymbol
CancelButton ZoneButton Button Inheritance • Inheritanceis another special case of an association denoting a “kind-of” hierarchy. • Inheritance simplifies the analysis model by introducing a taxonomy. • The children classes inherit the attributes and operations of the parent class.
Account Bank Customer Packages • Packages help you to organize UML models to increase their readability. • Pretty much all UML elements can be grouped into packages. Thus, classes, objects, use cases, components, nodes, node instances etc. Can all be organized as packages. • We can use the UML package mechanism to organize classes into subsystems • Any complex system can be decomposed into subsystems, where each subsystem is modeled as a package.
Foo Amount CustomerId Deposit() Withdraw() GetBalance() Object Modeling in Practice Class Identification: Name of Class, Attributes and Methods Is Foo the right name?
Account Foo “Dada” Amount Amount Amount CustomerId CustomerId CustomerId Deposit() Deposit() Deposit() Withdraw() Withdraw() Withdraw() GetBalance() GetBalance() GetBalance() Object Modeling in Practice: Brainstorming Is Foo the right name?
Account Amount Customer Bank Name Name AccountId Deposit() Withdraw() GetBalance() Object Modeling in Practice: More classes CustomerId CustomerId 1) Find New Classes 2) Review Names, Attributes and Methods
Account Amount Bank Customer CustomerId Name Name AccountId Deposit() AccountId CustomerId Withdraw() GetBalance() Object Modeling in Practice: Associations * ? * owns has 2 1) Find New Classes 2) Review Names, Attributes and Methods 3) Find Associations between Classes 4) Label the generic assocations 5) Determine the multiplicity of the assocations 6) Review associations
Account * * Has Amount Customer Bank CustomerId AccountId Name Name Deposit() AccountId CustomerId() Withdraw() GetBalance() Savings Account Checking Account Mortgage Account Withdraw() Withdraw() Withdraw() Practice Object Modeling: Find Taxonomies
Account Amount CustomerId AccountId Deposit() AccountId Withdraw() GetBalance() Practice Object Modeling: Simplify, Organize Show Taxonomies separately Savings Account Checking Account Mortgage Account Withdraw() Withdraw() Withdraw()
Account * * Has Amount Customer Bank AccountId CustomerId Name Name Deposit() CustomerId() Withdraw() GetBalance() Practice Object Modeling: Simplify, Organize Use the 7+-2 heuristics or better 5+-2!
Practical Tips - 1 • Simplicity • To be easier to understand/takes less effort • Try to use minimal number of classes • Diagram layout • Draw diagrams in symmetric manner • Try to avoid crossing lines • Names • Descriptive, crisp, unambiguous • Singular nouns for the name of classes • References • Do not bury object references inside objects • Model these as association
Practical Tips - 2 • Generalization • Do not nest subclasses too deeply • Two or three levels deep is good • Association end names • To unify references to the same class • Be alert for multiple uses of the same class • Qualified associations • To improve the precision of an association • Challenge with a multiplicity of “many” • Review • Try to get others to review model • Clarify names, improve abstraction, add info • Documentation • Diagram cannot describe the rationale • Always document models
Review of Class Diagrams Multiplicity Inheritance Association End Name (Role) Class Aggregation Class diagrams represent the structure of the system