classes & objects introduction

33

Click here to load reader

Upload: kumar

Post on 09-Jul-2015

108 views

Category:

Software


6 download

DESCRIPTION

classes & objects introduction

TRANSCRIPT

Page 1: classes & objects introduction

Object Oriented Analysis and Design By P. K. Deka @ CIT Dept, UPES

Object & Class Diagram

Page 2: classes & objects introduction

Object Oriented Analysis and Design By P. K. Deka @ CIT Dept, UPES

• Objects:– a concept, abstraction, or thing with identity that has meaning for an

application.– often appear as proper nouns or specific references in problem

descriptions– All objects have identity and are distinguishable– the choice of objects depends on judgment and the nature of problem

• Classes:– Describes a group of objects with the same properties (attributes),

behavior (operations), kinds of relationships and semantics.– Often appear as common nouns and noun phrases in problem

description.– Objects in a class have the same attributes and forms of behavior

• Difference in attribute values and specific relationship to other objects

– The choice of classes depends on the nature and scope of an application and is matter of judgment

– The interpretation of semantics depends on the purpose of each application and is a matter of judgment.

Page 3: classes & objects introduction

Object Oriented Analysis and Design By P. K. Deka @ CIT Dept, UPES

Class Diagram• The class model captures the static view of an

system – by characterizing the objects in the system– the relationship between the objects– and the attributes and operations for each class of objects

• Class diagram is not only used for visualizing, describing and documenting different aspects of a system but also for constructing executable system through forward and reverse engineering.

Page 4: classes & objects introduction

Object Oriented Analysis and Design By P. K. Deka @ CIT Dept, UPES

Class Diagram

• The class diagram is the main building block of object oriented modeling.

• used for – general conceptual modeling of the systematics of the

application– detailed modeling translating the models into

programming code.

• Class diagrams can also be used for data modeling

Page 5: classes & objects introduction

Object Oriented Analysis and Design By P. K. Deka @ CIT Dept, UPES

Class Diagram• describes the attributes and operations of a class

and also the constraints imposed on the system. • widely used in the modeling of object oriented

systems – can be mapped directly with object oriented

languages – widely used at the time of construction.

Page 6: classes & objects introduction

Object Oriented Analysis and Design By P. K. Deka @ CIT Dept, UPES

Class Diagram

• The class diagram shows a collection of classes, interfaces, associations, collaborations and constraints. It is also known as a structural diagram.

Page 7: classes & objects introduction

Object Oriented Analysis and Design By P. K. Deka @ CIT Dept, UPES

Object Diagram

JoeSmith:Person MaySharp:Person :Person

ObjectsAn object diagram shows individual objects and their relationships•Helpful for documenting test casesA class diagram corresponds to an infinite set of object diagrams.

Page 8: classes & objects introduction

Object Oriented Analysis and Design By P. K. Deka @ CIT Dept, UPES

Class and Objects

JoeSmith:Person MaySharp:Person :Person

Objects

Person

Class

Fig: Objects and Classes are the focus of class modeling

Page 9: classes & objects introduction

Object Oriented Analysis and Design By P. K. Deka @ CIT Dept, UPES

Class Diagram

Class Name

Attributes

Operations

Page 10: classes & objects introduction

Object Oriented Analysis and Design By P. K. Deka @ CIT Dept, UPES

Class and Object

• First, there is the division of class and object.– A class is an abstraction;– an object is one concrete manifestation of that

abstraction.

• In the UML, you can model classes as well as objects, as shown in following Figures

Page 11: classes & objects introduction

Object Oriented Analysis and Design By P. K. Deka @ CIT Dept, UPES

Class and Object

Page 12: classes & objects introduction

Object Oriented Analysis and Design By P. K. Deka @ CIT Dept, UPES

Class Diagram

Page 13: classes & objects introduction

Object Oriented Analysis and Design By P. K. Deka @ CIT Dept, UPES

Purpose of Class Diagram

Page 14: classes & objects introduction

Object Oriented Analysis and Design By P. K. Deka @ CIT Dept, UPES

Purpose of Class Diagram

• The purpose of the class diagram can be summarized as:To describe objects.Analysis and design of the static view of an

application.Describe responsibilities of a system.Base for component and deployment diagrams.Forward and reverse engineering

Page 15: classes & objects introduction

Object Oriented Analysis and Design By P. K. Deka @ CIT Dept, UPES

Visibility in UMLTo specify the visibility of a class member (i.e., any

attribute or method) these are the following notations that must be placed before the member's name:

"+" Public

"-" Private

"#" Protected

"/" Derived (can be combined with one of the

others)

“~" Static

Page 16: classes & objects introduction

Object Oriented Analysis and Design By P. K. Deka @ CIT Dept, UPES

How to draw Class Diagram

???

Page 17: classes & objects introduction

Object Oriented Analysis and Design By P. K. Deka @ CIT Dept, UPES

How to draw Class Diagram???

• Class diagram is basically a graphical representation of the static view of the system and represents different aspects of the application. So a collection of classes represent the whole system.

Page 18: classes & objects introduction

Object Oriented Analysis and Design By P. K. Deka @ CIT Dept, UPES

The following points should be remembered while drawing a class diagram:

• The name of the class diagram should be meaningful to describe the aspect of the system.

• Each element and their relationships should be identified in advance.

• Responsibility (attributes and methods) of each class should be clearly identified.

• For each class minimum number of properties should be specified. Because unnecessary properties will make the diagram complicated.

Page 19: classes & objects introduction

Object Oriented Analysis and Design By P. K. Deka @ CIT Dept, UPES

Contd.. :

• Use notes when ever required to describe some aspect of the diagram.

• at the end of the drawing it should be understandable to the developer/coder.

• Finally, before making the final version, the diagram should be drawn on plain paper and rework as many times as possible to make it correct.

Page 20: classes & objects introduction

Object Oriented Analysis and Design By P. K. Deka @ CIT Dept, UPES

“Order System”

• First of all Order and Customer are identified as the two elements of the system and they have a one to many relationship because a customer can have multiple orders.

• We would keep Order class is an abstract class and it has two concrete classes (inheritance relationship) SpecialOrder and NormalOrder.

• The two inherited classes have all the properties as the Order class. In addition they have additional functions like dispatch () and receive ().

Page 21: classes & objects introduction

Object Oriented Analysis and Design By P. K. Deka @ CIT Dept, UPES

Class Diagram for Order System

Page 22: classes & objects introduction

Object Oriented Analysis and Design By P. K. Deka @ CIT Dept, UPES

Page 23: classes & objects introduction

Object Oriented Analysis and Design By P. K. Deka @ CIT Dept, UPES

Relationships among Classes

• Links– the basic relationship among objects– a tuple i.e. the list of objects– an instance of an association

• Association– represents a family of links with common structure and semantics.– Links of an association connect objects from same classes.– Describes a set of potential links – Binary associations (with two ends) are normally represented as a line.

Fig: Class diagram example of association between two classes

Page 24: classes & objects introduction

Object Oriented Analysis and Design By P. K. Deka @ CIT Dept, UPES

Notation

• Link – line between objects– If the link has name, it is underlined

• Association– Line between related classes– Association name is optional, if unambiguous

• Ambiguity arise when a model has multiple associations among the same classes

– Bidirectional• Can be traversed in either direction and equally meaningful

Page 25: classes & objects introduction

Object Oriented Analysis and Design By P. K. Deka @ CIT Dept, UPES

Class Diagram with All Relationships

Page 26: classes & objects introduction

Object Oriented Analysis and Design By P. K. Deka @ CIT Dept, UPES

Class Diagram: Generalization

Page 27: classes & objects introduction

Object Oriented Analysis and Design By P. K. Deka @ CIT Dept, UPES

Class Diagram: Association Names

Page 28: classes & objects introduction

Object Oriented Analysis and Design By P. K. Deka @ CIT Dept, UPES

Class Diagram: Roles

Page 29: classes & objects introduction

Object Oriented Analysis and Design By P. K. Deka @ CIT Dept, UPES

Class Diagram: Aggregation

Page 30: classes & objects introduction

Object Oriented Analysis and Design By P. K. Deka @ CIT Dept, UPES

Relationships among Classes

• Multiplicity– Multiplicity specifies the number of instances of

one class that may relate to a single instance of an associated class.

– Multiplicity constrains the number of related objects.

– a subset of nonnegative integers.

Page 31: classes & objects introduction

Object Oriented Analysis and Design By P. K. Deka @ CIT Dept, UPES

Multiplicity

• UML specifies multiplicity with an interval, such as..

0..1 No instances, or one instance (optional, may)

1 Exactly one instance

0..* or * Zero or more instances

1..* One or more instances (at least one)

Page 32: classes & objects introduction

Object Oriented Analysis and Design By P. K. Deka @ CIT Dept, UPES

Class Diagram: Multiplicity

Page 33: classes & objects introduction

Object Oriented Analysis and Design By P. K. Deka @ CIT Dept, UPES

Association Types• Aggregation– a variant of the "has a" association relationship;– aggregation is more specific than association– It is an association that represents a part-whole or

part-of relationship.– can occur when a class is a collection or container of

other classes, but where the contained classes do not have a strong life cycle dependency on the container

– if the container is destroyed, its contents are not.