Presentation is loading. Please wait.

Presentation is loading. Please wait.

Class Diagram Classes are the most important building block of any object-oriented system. A class is a description of a set of objects that share the.

Similar presentations


Presentation on theme: "Class Diagram Classes are the most important building block of any object-oriented system. A class is a description of a set of objects that share the."— Presentation transcript:

1 Class Diagram Classes are the most important building block of any object-oriented system. A class is a description of a set of objects that share the same attributes, operations, relationships, and semantics. A class implements one or more interfaces. Class diagrams are the most common diagram found in modeling object- oriented systems. A class diagram shows a set of classes, interfaces, and collaborations and their relationships. A class is not an individual object, but rather represents a whole set of objects. Thus, you may conceptually think of "wall" as a class of objects with certain common properties, such as height, length, thickness. The UML provides a graphical representation of class. Graphically a class is rendered as a rectangle.

2 Class Diagram contd… A class is rendered as a rectangle, distributed in three compartments. The first compartment holds the Class name, second holds Attributes and third holds Operations. Names A class name must be unique within its enclosing package. Every class must have a name that distinguishes it from other classes. A name is a textual string. That name alone is known as a simple name; a path name is the class name prefixed by the name of the package in which that class lives.

3

4

5 Attributes An attribute is a named property of a class that describes a range of values that instances of the property may hold. A class may have any number of attributes or no attributes at all. An attribute represents some property of the thing you are modeling that is shared by all objects of that class. For example, every wall has a height, width, and thickness; you might model your customers in such a way that each has a name, address, phone number, and date of birth.

6 Names An attribute name may be text, just like a class name. In practice, an attribute name is a short noun or noun phrase that represents some property of its enclosing class. Typically, you capitalize the first letter of every word in an attribute name except the first letter, as in name or loadBearing. You can further specify an attribute by stating its class and possibly a default initial value,

7 Attribute Containment types It describes how an attribute store within a class. By value Attribute stores within in the class. By reference Attribute stores outside the class. Unspecified Containment is not yet specified. by default Rose assume by value. Static A static attribute has only one instance of a class. A $ sign is used to show it. Derived Attribute A derived attribute is created from one or more other attributes. area = width * height. A / sign is used to show a derived attribute.

8 Operations An operation is the implementation of a service that can be requested from any object of the class to affect behavior. In other words, an operation is an abstraction of something you can do to an object and that is shared by all Objects of that class. A class may have any number of operations or no operations at all. Names An operation name may be text, just like a class name. In practice, an operation Name is a short verb or verb phrase that represents some behavior of its enclosing class. Typically, you capitalize the first letter of every word in an operation name except the first letter, as in move or isEmpty.

9 You can specify an operation by stating its signature, covering the name, type, and default value of all parameters and a return type.

10 Organizing Attributes and Operations When drawing a class, you don't have to show every attribute and every operation at once. To better organize long lists of attributes and operations, you can also prefix each group with a descriptive category by using stereotypes.

11 Types of Operations Implementor Operations implements some business functionality. They can be found by examining Interaction diagram. Manager Operations Manage the creation and destruction of objects. Access Operations Set and get operation in a class to access private attributes. Helper Operations Help other operation of the class, but cant be access directly. Private operation of a class.

12 Responsibilities A responsibility is a contract or an obligation of a class. When you create a class, you are making a statement that all objects of that class have the same kind of state and the same kind of behavior. At a more abstract level, these corresponding attributes and operations are just the features by which the class's responsibilities are carried out.

13 Responsibilities Responsibilities can be drawn in a separate compartment at the bottom of the class. A class can have more then one responsibilities, every well structured class has at least one responsibility. Shape origin... move() resize() display()... Responsibilities... shows that there are more operation or attributes in this class

14

15 Stereotypes The UML provides a language for structural things, behavioral things, grouping things, and notational things. These four basic kinds of things address the overwhelming majority of the systems you'll need to model. However, sometimes you'll want to introduce new things that speak the vocabulary of your domain and look like primitive building blocks. A stereotype is an extension of the vocabulary of the UML, allowing you to create new kinds of building blocks similar to existing ones but specific to your problem. Graphically, a stereotype is rendered as a name enclosed by > and placed above the name of another element. Stereo typing is a way to categorize some thing in your diagram. Stereotype are the core extension mechanism of UML

16 Class stereotypes in UML There are three class stereotypes in UML Boundary Classes Control Classes Entity Classes

17 Boundary Classes Are those classes which lies between your system and real world, such as form, reports and hardware interfaces printers and scanners. To find boundary classes check the use cases, you will find at a minimum one boundary class for every actor interacting with the system. Two actors can have same one boundary class. Entity Classes These classes saves the information in persistent storage. You can create tables in your database for each entity class. Control Classes The control class is responsible for coordinating the efforts of other classes. Typically there is only one control class per use case. Control class delegates responsibility to other classes. There may be other control classes that share between several use cases. e.g. Security manager for controlling security. Transaction manager class for Database transaction. Minimize the impact of changes on system

18 Visibility One of the most important details you can specify for a classifier's attributes and operations is its visibility. The visibility of a feature specifies whether it can be used by other classifiers. In the UML, you can specify any of three levels of visibility. public Any outside classifier with visibility to the given classifier can use the feature; specified by prepending the symbol + protected Any descendant of the classifier can use the feature; specified by prepending the symbol # private Only the classifier itself can use the feature; specified by prepending the symbol – No sign represents a package visibility.

19 Multiplicity Whenever you use a class, it's reasonable to assume that there may be any number of instances of that class (unless, of course, it is an abstract class and so it may not have any direct instances, although there may be any number of instances of its concrete children). Sometimes, though, you'll want to restrict the number of instances a class may have. Most often, you'll want to specify zero instances (in which case, the class is a utility class that exposes only class scoped attributes and operations), one instance (a singleton class), a specific number of instances, or many instances (the default case). The number of instances a class may have is called its multiplicity. Is an indication of how many objects may participate in a given relationship.

20 Setting Class multiplicity – n (default) many – 0..0 Zero – 0..1 Zero or One – 0..n Zero or many – 1..1 Only One – 1..n One or many – Exactly –.. Between and –..n or more –, or –,.. Exactly or between and..,.. Between and or between and

21 Setting Class Persistence Persistent The information in objects of the class will be saved to a database or some other form of persistent storage. Transient The information in objects will not be saved to persistent storage

22 Relationships When you build abstractions, you'll discover that very few of your classes stand alone. Instead, most of them collaborate with others in a number of ways. Therefore, when you model a system, not only must you identify the things that form the vocabulary of your system, you must also model how these things stand in relation to one another. A relationship is a connection among things. Three types of relationships : 1. Association 2.Dependency 3.Generalization Association represent structural relationships among objects. Dependency represent using relationships. Generalization represent link between generalized classes to their specializations.

23 Association An association is a structural relationship that specifies that object of one thing are connected to objects of another. You can navigate from an object of one class to an object of the another class. Objects of one class can link to other objects of same class. An association that connects exactly two classes is called a binary association. An association that connects more than two classes is called n-ary association. An association is rendered as a solid line connecting the same or different classes. Associations are represented by attributes in a class.

24 Association properties Name An association can have a name. That describe the nature of the relationship. Role A role is just the face the class at the near end of the association present to the class at the other end of the association. Multiplicity It represent that how many objects of one class may connect to the objects of another class. Navigation It represent the direction of association from one object to another object. Unless specified the navigation is bi-directional. You can limit the navigation to just one direction.

25 Works for Name PersonCompany employee PersonCompany employer Role name employee PersonCompany employer 1..* * Person Parent Child * 2

26 Aggregation Aggregation is a relationship between a whole and its part. Aggregation is a type of association. In aggregation one class represent a larger thing (the whole) which consist of smaller thing (the parts). Aggregation represent a “has a” relationship. Company Department Whole Part 1 *

27 Composition Composition is a variation of aggregation. In composition one class represent a larger thing (the whole) which consist of smaller thing (the parts). Parts may be created after the whole, but once created they live and die with the whole. Window Frame Whole Part 1 * It is represented by a Filled diamond.

28 Dependency An dependency is a using relationship, states that a change in the specification of one thing may affect another thing that uses it. A dependency can have a name. Dependency is rendered as a dashed directed line, directed to the thing being dependent on. Dependency cannot be represented by a class attribute. It can be represented by global class, or instantiated as a local variable inside an operation or passed as a parameter to some operation.

29 Generalization An generalization is a relationship between general thing (called the super or parent) and a more special kind of that thing (called the subclass or child). Generalization represents “is-a” or “is-a-kind-of “ relationship. A child inherits the properties of its parents, especially their attributes and operations. An operation of a child that has the same signature as an operation in a parent overrides the operation of the parent, this is known as polymorphism. A class can have zero, one or more parents. A class that has no parents and one or more children is called a root or base class. A class that has one parent is said to use single inheritance, with more then one parents is said to use multiple inheritance. Generalization is rendered as a solid directed line with a large open arrow head.

30

31

32 Company Department ContractInformation Headquarters PersonnelRecord Office name Person name employeeID title getName getID getContractInformation getPersonnelRecords taxID emplomentHistory salary address phone address 1..* 0..1 1..*1 manager member 1 * Location ** dependency role generalization aggregation multiplicity attributes operations class

33 Student name studentID School -name -address -phone +addStudent() +removeStudent() +getStudent() +getAllStudent() +addDepartment() +getDepartment() +getAllDepartment() Department -name +addIntructor() +removeInstructor() +getInstructor() +getAllInstructor() Course name courseID Instructor name Has AssignedTo Member Attends Teaches 0..1 1..* 0..1 1..* 1 * * * * role:chairperson

34

35

36

37

38

39

40


Download ppt "Class Diagram Classes are the most important building block of any object-oriented system. A class is a description of a set of objects that share the."

Similar presentations


Ads by Google