Class Diagram Lecture 1 Class diagram A Class

  • Slides: 26
Download presentation
Class Diagram Lecture # 1

Class Diagram Lecture # 1

Class diagram • A Class Diagram is a diagram describing the structure of a

Class diagram • A Class Diagram is a diagram describing the structure of a system • shows the system's • • classes Attributes operations (or methods), Relationships among the classes.

Class. Diagram • Class diagrams represent the static elements of a system, rather than

Class. Diagram • Class diagrams represent the static elements of a system, rather than processes and describe the classes, the data and functionality they contain and the relationships between them.

Example Class. Name attributes operations A class is a description of a set of

Example Class. Name attributes operations A class is a description of a set of objects that share the same attributes, operations, relationships. Graphically, a class is rendered as a rectangle, usually including its name, attributes, and operations in separate, designated compartments

Attributes Person name : String address : Address birthdate : Date • An attribute

Attributes Person name : String address : Address birthdate : Date • An attribute is a named property of a class that describes the object being modeled. In the class diagram, attributes appear in the second compartment just below the namecompartment.

Derived Attribute Person Attributes are usually listed in the form: attribute. Name : Type

Derived Attribute Person Attributes are usually listed in the form: attribute. Name : Type name : String address : Address birthdate : Date / age : Date A derived attribute is one that can be computed from other attributes, but doesn’t actually exist. For example, a Person’s age can be computed from his birth date. A derived attribute is designated by a preceding ‘/’ as in: / age : Date 12/2/2014

Class Attributes Person + name : String # address : Address # birthdate :

Class Attributes Person + name : String # address : Address # birthdate : Date / age : Date • Attributes can be: + public # protected - private / derived

Activity Diagram Symbols Person name : String address : Address birthdate : Date eat

Activity Diagram Symbols Person name : String address : Address birthdate : Date eat sleep work play Operations describe the class behavior and appear in the third compartment.

Relationships in classes • • • Association Aggregation Composition Dependency Generalization

Relationships in classes • • • Association Aggregation Composition Dependency Generalization

Association • If two classes in a model need to communicate with each other,

Association • If two classes in a model need to communicate with each other, there must be link between them. An association denotes that link. • An association between two classes indicates that objects at one end of an association “recognize” objects at the other end and may send messages to them. Instructor instructs Here , an association is instructs Student

Association Relationships(Cont’d) We can indicate the multiplicity of an association by adding multiplicity adornments

Association Relationships(Cont’d) We can indicate the multiplicity of an association by adding multiplicity adornments to the line denoting the association. The example indicates that a Student has one or more Instructors: Student 1. . * Instructor

Associations (cont. ) • Multiplicity • the number of objects that participate in the

Associations (cont. ) • Multiplicity • the number of objects that participate in the association. • Indicates whether or not an association is mandatory. Multiplicity Indicators Exactly one Zero or more (unlimited) 1 * (0. . *) One or more 1. . * Zero or one (optional association) 0. . 1 Specified range 2. . 4

Associations (cont. ) Role name Staff. Member instructor 1. . * Multiplicity Association name

Associations (cont. ) Role name Staff. Member instructor 1. . * Multiplicity Association name instructs * Navigable (uni-directional) association Student Role * pre requisites Courses 0. . 3 Reflexive association UML Class Diagrams 13

Qualified Association A qualified association associates two objects using a qualifier to select objects

Qualified Association A qualified association associates two objects using a qualifier to select objects at the other end of the association. A qualifier is an attribute or set of attributes which has a unique value for each object in the class.

Aggregation • Aggregation is a relationship where one class is part of another class.

Aggregation • Aggregation is a relationship where one class is part of another class. • In basic aggregation, the class that forms part of the whole class can exist independently, so the life of an instance of the part class is not determined by the whole class. • Basic aggregation is represented using an empty diamond symbol next to the whole class.

Aggregation • A special form of association that models a whole-part relationship between an

Aggregation • A special form of association that models a whole-part relationship between an aggregate (the whole) and its parts. • Models a “is a part-part of” relationship. 2. . * Car Whole Door Part 1. . * House

Aggregation

Aggregation

Composition • Composition is a strong type of aggregation where the whole class contains

Composition • Composition is a strong type of aggregation where the whole class contains the instance of the part class. • The lifetime of the part class depends on the existence of the whole class. • Composition relationships are represented using a filled diamond symbol next to the whole class

Composition • A strong form of aggregation • The whole is the sole owner

Composition • A strong form of aggregation • The whole is the sole owner of its part. • The part object may belong to only one whole • Multiplicity on the whole side must be zero or one. • The life time of the part is dependent upon the whole. • The composite must manage the creation and destruction of its parts.

Generalization • A generalization connects a subclass to its superclass. It denotes an inheritance

Generalization • A generalization connects a subclass to its superclass. It denotes an inheritance of attributes and behavior from the superclass to the subclass and indicates a specialization in the subclass of the more general superclass. Person Student

Generalization Relationships (Cont’d) UML permits a class to inherit from multiple superclasses, although some

Generalization Relationships (Cont’d) UML permits a class to inherit from multiple superclasses, although some programming languages (e. g. , Java) do not permit multiple inheritance. Student Employee Teaching. Assistant

Generalization • The inheritance relationship, also known as the generalization relationship, is used to

Generalization • The inheritance relationship, also known as the generalization relationship, is used to indicate that one class is a specialization of another. {abstract} is a tagged value that indicates that the class is abstract. The name of an abstract class should be italicized An abstract class Shape Super Class Circle Sub Class {abstract} Generalization relationship

Dependency • Dependency is a weaker form of relationship which indicates that one class

Dependency • Dependency is a weaker form of relationship which indicates that one class depends on another because it uses it at some point in time. Course. Schedule Course add(c : Course) remove(c : Course)

Class diagram

Class diagram

Registration

Registration

Class Diagram

Class Diagram