Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Class Diagrams: Advanced Concepts. 2 Overview Class diagrams are the most commonly used diagrams in UML. Class diagrams are the most commonly used diagrams.

Similar presentations


Presentation on theme: "1 Class Diagrams: Advanced Concepts. 2 Overview Class diagrams are the most commonly used diagrams in UML. Class diagrams are the most commonly used diagrams."— Presentation transcript:

1 1 Class Diagrams: Advanced Concepts

2 2 Overview Class diagrams are the most commonly used diagrams in UML. Class diagrams are the most commonly used diagrams in UML. Class diagrams are for visualizing, specifying and documenting the system from a static perspective. Class diagrams are for visualizing, specifying and documenting the system from a static perspective. Class diagrams indicate which classes know about other classes and, if they do, what type of relationship exists. Class diagrams indicate which classes know about other classes and, if they do, what type of relationship exists. Class diagrams will have different levels of detail (abstraction) depending on where we are in the software development process. Class diagrams will have different levels of detail (abstraction) depending on where we are in the software development process.

3 3 Overview

4 4 Static Operations and Attributes Scope Scope Individual member data (attributes) may have either class scope or instance scope. Individual member data (attributes) may have either class scope or instance scope. Class scope - A single copy of an attribute is shared by all instances of a class. Class scope - A single copy of an attribute is shared by all instances of a class. In UML you underline the attribute to indicate class scope: productCount : int In UML you underline the attribute to indicate class scope: productCount : int In C++ and Java members with class scope would be declared as static: static int productCount In C++ and Java members with class scope would be declared as static: static int productCount Instance scope - Each instance of a class would have its own copy of the attribute. All attributes have instance scope by default. Instance scope - Each instance of a class would have its own copy of the attribute. All attributes have instance scope by default.

5 5 Static Operations and Attributes Static attributes have class scope Static features are underlined on a class diagram Italicized class name means abstract class.

6 6 Aggregate and Composition Aggregation is … Aggregation is … A relationship between two classes. A relationship between two classes. A form of association. A form of association. Used to show a ‘has-a’ or a ‘whole-part’ relationship. Used to show a ‘has-a’ or a ‘whole-part’ relationship. Graphically represented as a solid line with an open diamond on the ‘whole’ end. Graphically represented as a solid line with an open diamond on the ‘whole’ end. Aggregations and associations are implemented in exactly the same way. The difference is entirely conceptual. Aggregations and associations are implemented in exactly the same way. The difference is entirely conceptual.

7 7 Aggregate and Composition Composition is … Composition is … A relationship between two classes. A relationship between two classes. Used to show a ‘contains-a’ or a ‘whole-part’ relationship. Used to show a ‘contains-a’ or a ‘whole-part’ relationship. Graphically represented as a solid line with a solid diamond on the ‘whole’ end. Graphically represented as a solid line with a solid diamond on the ‘whole’ end. Composition relationships and associations are not implemented in exactly the same way. Composition relationships and associations are not implemented in exactly the same way. If the ‘whole’ object is destroyed, the part object will also be destroyed. If the ‘whole’ object is destroyed, the part object will also be destroyed.

8 8 Aggregate and Composition Composition is … Composition is … A relationship between two classes. A relationship between two classes. Used to show a ‘contains-a’ or a ‘whole-part’ relationship. Used to show a ‘contains-a’ or a ‘whole-part’ relationship. Graphically represented as a solid line with a solid diamond on the ‘whole’ end. Graphically represented as a solid line with a solid diamond on the ‘whole’ end. Composition relationships and associations are not implemented in exactly the same way. Composition relationships and associations are not implemented in exactly the same way. If the ‘whole’ object is destroyed, the part object will also be destroyed. If the ‘whole’ object is destroyed, the part object will also be destroyed.

9 9 Aggregate and Composition

10 10 Aggregate and Composition

11 11 Common Modeling Technique Modeling dependency, association, aggregation and composition relationships. Modeling dependency, association, aggregation and composition relationships. It is not always easy to determine which is the best relationship to use. It all has to do with your perspective of the problem domain. It is not always easy to determine which is the best relationship to use. It all has to do with your perspective of the problem domain. There is not always one best solution. There is not always one best solution. Personal experience is your most valuable modeling tool. Personal experience is your most valuable modeling tool. CRC cards are helpful. CRC cards are helpful.

12 12 Common Modeling Technique Multiple class diagrams are required to model large systems. Multiple class diagrams are required to model large systems. Each individual class diagram … Each individual class diagram … Shows a single aspect of the system. Shows a single aspect of the system. Contains only elements that are essential to understanding that aspect. Contains only elements that are essential to understanding that aspect. Provide details consistent with its level of abstraction. Provide details consistent with its level of abstraction. Uses meaningful class and member names. Uses meaningful class and member names. Pointers to other classes are modeled as associations. Pointers to other classes are modeled as associations.

13 13 Common Modeling Technique A well-defined class is loosely coupled (few entry points) and highly cohesive (all members work toward a common functionality). A well-defined class is loosely coupled (few entry points) and highly cohesive (all members work toward a common functionality). Ask yourself “Am I trying to show what the class does or how it does it”. That will tell you at what level of abstraction to model the class. Ask yourself “Am I trying to show what the class does or how it does it”. That will tell you at what level of abstraction to model the class. In the requirements and specification phase you are interested in “what”. In the design phase you are interested in “how”. In the requirements and specification phase you are interested in “what”. In the design phase you are interested in “how”. Don’t hesitate to attach notes to the class icons if further clarification is necessary. Don’t hesitate to attach notes to the class icons if further clarification is necessary.

14 14 Interfaces and Abstract Classes Abstract Class Abstract Class A abstract class cannot have any direct instances. A abstract class cannot have any direct instances. Not all OO programming languages directly support abstract classes. (In C++ abstract classes contain one or more pure virtual functions). Not all OO programming languages directly support abstract classes. (In C++ abstract classes contain one or more pure virtual functions). int myFunction(int x) = 0; int myFunction(int x) = 0; Pure virtual functions have no function body. Pure virtual functions have no function body. An abstract class is thought to be so general as to be useless by itself. An abstract class is thought to be so general as to be useless by itself. Abstract classes only occur in the context of an inheritance hierarchy. Abstract classes only occur in the context of an inheritance hierarchy. In UML you specify that a class is abstract by writing its name in italics. In UML you specify that a class is abstract by writing its name in italics.

15 15 Interfaces and Abstract Classes An interface is a class that has no implementation. All of its features are abstract Corresponds directly to interfaces in Java

16 16 Association Class An association class… An association class… is used to model an association as a class. is used to model an association as a class. is rendered by a dashed line from the association to the class rectangle. is rendered by a dashed line from the association to the class rectangle. is essentially a class attached to an association; the association itself is modeled as a class. is essentially a class attached to an association; the association itself is modeled as a class. Each link in the association is an object of the association class. Each link in the association is an object of the association class. A link is an instance of an association A link is an instance of an association a link is to an association as an object is to a class a link is to an association as an object is to a class

17 17 Association Class Things to consider: Things to consider: You can’t attach the same class to more than one association; an association class is the association. You can’t attach the same class to more than one association; an association class is the association. The name of the association is usually omitted since it is considered to be the same as that of the attached class. The name of the association is usually omitted since it is considered to be the same as that of the attached class. Distinguish between the use of an association class as a modeling technique and the implementation of the association class. There can be several ways to implement an association class. Distinguish between the use of an association class as a modeling technique and the implementation of the association class. There can be several ways to implement an association class.

18 18 Association Class

19 19 Association Class

20 20 Association Class

21 21 Visibility Visibility Visibility Class members (attributes and behaviors) may be specified as public (+), private (-), or protected (#). Class members (attributes and behaviors) may be specified as public (+), private (-), or protected (#). In UML the single character visibility indicator is placed to the left of the member. In UML the single character visibility indicator is placed to the left of the member. # myProtectedFunction( ) # myProtectedFunction( ) - myPrivateFunction( ) - myPrivateFunction( ) + myPublicFunction( ) + myPublicFunction( ) Restricting visibility is the same as restricting accessibility. By restring accessibility you are limiting the number of entry points into an object. By restricting the number of entry points you are facilitating debugging and code re- use. Restricting visibility is the same as restricting accessibility. By restring accessibility you are limiting the number of entry points into an object. By restricting the number of entry points you are facilitating debugging and code re- use.


Download ppt "1 Class Diagrams: Advanced Concepts. 2 Overview Class diagrams are the most commonly used diagrams in UML. Class diagrams are the most commonly used diagrams."

Similar presentations


Ads by Google