Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 3,Class Diagram.

Similar presentations


Presentation on theme: "Chapter 3,Class Diagram."— Presentation transcript:

1 Chapter 3,Class Diagram

2 Outline of this Class Activity diagrams Class 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

3 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. Table zone2price Enumeration getZones() Price getPrice(Zone) TarifSchedule * Trip zone:Zone Price: Price

4 Classes Type Name Signature Attributes Operations
Table zone2price Enumeration getZones() Price getPrice(Zone) TarifSchedule zone2price getZones() getPrice() TarifSchedule Name Attributes Operations Signature TarifSchedule 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

5 Instances An instance represents a phenomenon.
zone2price = { {‘1’, 0.20}, {‘2’, 0.40}, {‘3’, 0.60}} tarif2006:TarifSchedule zone2price = { {‘1’, 0.20}, {‘2’, 0.40}, {‘3’, 0.60}} :TarifSchedule 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).

6 Actor vs Class vs Object
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”).

7 Associations * Associations denote relationships between classes.
Price Zone Enumeration getZones() Price getPrice(Zone) TarifSchedule TripLeg * Associations denote relationships between classes. The multiplicity of an association end denotes how many objects the instance of a class can legitimately reference.

8 1-to-1 and 1-to-many Associations
Country name:String City 1 1-to-1 association Polygon draw() Point x: Integer y: Integer * 1-to-many association

9 Many-to-Many Associations
Company * * StockExchange tickerSymbol

10 Aggregation 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. Exhaust system Muffler diameter Tailpipe 1 0..2 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”). TicketMachine ZoneButton 3

11 Difference of Aggregation and Composition
Bir örnek Arabadır. Araba Parçalarından oluşur. Bu parçalara sahiptir. Eğer bir Parça yoksa araba bozuktur. Araba Parçalarıyla Composition oluşturur. Ayrıca Arabanın Yolcuları vardır. Yolcular Arabanın Parçası değildir. Eğer bir Yolcu yoksa Araba bozuk değildir. Araba Yolcularına sahip değildir. Arabada değillerse başka bir yerdedirler. İlişki geçicidir. Yolcular gelir ve gider. Araba ve Yolcular arasında Aggregation ilişkisi vardır. Her iki ilişki aslında Composition’dır. Arabanın hem Parçaları hem de Yolcuları vardır. Farklılık süresindedir. Parçalarla olan ilişki daimidir, Yolcularla olan ilişki geçicidir.

12 Without qualification
Qualifiers Directory File filename Without qualification 1 * With qualification Directory File 1 filename 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.

13 Qualification: Another Example
Company * Lists * StockExchange tickerSymbol * StockExchange Company Lists 1 tickerSymbol

14 Inheritance Button ZoneButton CancelButton Inheritance is 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.

15 Packages Account Bank Customer
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. Account Bank Customer

16 Object Modeling in Practice
Foo Amount CustomerId Deposit() Withdraw() GetBalance() Class Identification: Name of Class, Attributes and Methods Is Foo the right name?

17 Object Modeling in Practice: Brainstorming
“Dada” Amount CustomerId Deposit() Withdraw() GetBalance() Foo Amount CustomerId Deposit() Withdraw() GetBalance() Account Amount CustomerId Deposit() Withdraw() GetBalance() Naming is important! Is Foo the right name?

18 Object Modeling in Practice: More classes
Account Amount Deposit() Withdraw() GetBalance() Customer Name Bank Name CustomerId AccountId CustomerId 1) Find New Classes 2) Review Names, Attributes and Methods

19 Object Modeling in Practice: Associations
Account Amount Deposit() Withdraw() GetBalance() Customer Name CustomerId AccountId Bank ? * * owns has 2 1) Find New Classes İçi dolu baklava: Composition. “Contains-a” ilişkisi. İçi boş baklava: Aggregation “has-a” ilişkisi. 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

20 Practice Object Modeling: Find Taxonomies
Account Amount Deposit() Withdraw() GetBalance() CustomerId AccountId Bank Name * Customer Name CustomerId() Has * Savings Account Withdraw() Checking Account Withdraw() Mortgage Account Withdraw() İçi dolu baklava: Composition. “Contains-a” ilişkisi. İçi boş baklava: Aggregation “has-a” ilişkisi. Taxonomy: Hiyerarşi yaratıp, sınıflandırma yapmak. Üçgenler: Inheritance. “Kind-of” ilişkisi.

21 Practice Object Modeling: Simplify, Organize
Account Amount Deposit() Withdraw() GetBalance() CustomerId AccountId Show Taxonomies separately Savings Account Checking Account Mortgage Account İçi dolu baklava: Composition. “Contains-a” ilişkisi. İçi boş baklava: Aggregation “has-a” ilişkisi. Taxonomy: Hiyerarşi yaratıp, sınıflandırma yapmak. Üçgenler: Inheritance. “Kind-of” ilişkisi. Withdraw() Withdraw() Withdraw()

22 Practice Object Modeling: Simplify, Organize
Customer Name CustomerId() Account Amount Deposit() Withdraw() GetBalance() CustomerId AccountId Bank Has * Use the 7+-2 heuristics or better 5+-2! İçi dolu baklava: Composition. “Contains-a” ilişkisi. İçi boş baklava: Aggregation “has-a” ilişkisi. Taxonomy: Hiyerarşi yaratıp, sınıflandırma yapmak. Üçgenler: Inheritance. “Kind-of” ilişkisi.

23 Practical Tips - 1 Simplicity Diagram layout Names References
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

24 Practical Tips - 2 Generalization Association end names
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

25 Review of Class Diagrams
Multiplicity Inheritance Association End Name (Role) Class Aggregation Class diagrams represent the structure of the system

26 Class Diagram Examples - 1
- Çift taraflı bir bağıntı örneği -

27 Class Diagram Examples - 2

28 Class Diagram Examples - 3

29 Class Diagram Examples - 4

30 Class Diagram Examples - 5

31 Another view on UML Diagrams


Download ppt "Chapter 3,Class Diagram."

Similar presentations


Ads by Google