Top Banner
Class Modeling
27

Class Modeling. Basic Class Modeling Concepts Object Class Link Association Generalization Inheritance.

Jan 03, 2016

Download

Documents

Barnaby Griffin
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Class Modeling. Basic Class Modeling Concepts Object Class Link Association Generalization Inheritance.

Class Modeling

Page 2: Class Modeling. Basic Class Modeling Concepts Object Class Link Association Generalization Inheritance.

Basic Class Modeling Concepts

ObjectClassLinkAssociationGeneralizationInheritance

Page 3: Class Modeling. Basic Class Modeling Concepts Object Class Link Association Generalization Inheritance.

Objects

The purpose of class modeling is to describe objects

An object is a concept, abstraction, or thing with identity that has meaning for an application.

Objects often appear as proper nouns or specific references in problem description and discussions with users.

Page 4: Class Modeling. Basic Class Modeling Concepts Object Class Link Association Generalization Inheritance.

Objects (cont.)

Some objects have real-world counterparts, others are conceptual entities

And others are introduced for implementation reasons and have no correspondence to physical reality

The choice of objects depends on judgment and the nature of a problem; there can be many correct representations.

Page 5: Class Modeling. Basic Class Modeling Concepts Object Class Link Association Generalization Inheritance.

Objects (cont.)

All objects have identity and are distinguishable

The identity means that objects are distinguished by their inherent existence and by descriptive properties that may have.

Page 6: Class Modeling. Basic Class Modeling Concepts Object Class Link Association Generalization Inheritance.

Classes

An object is an instance-or occurrence- of a class

A class describes a group of objects with the same properties (attributes), behavior (operations), kinds of relationships, and semantics

Classes often appear as common nouns and noun phrases in problem descriptions and discussions with users.

Page 7: Class Modeling. Basic Class Modeling Concepts Object Class Link Association Generalization Inheritance.

Class Diagrams

Class diagram is a means for expressing models that is coherent, precise, and easy to formulate

Page 8: Class Modeling. Basic Class Modeling Concepts Object Class Link Association Generalization Inheritance.

Class diagrams (cont.)

(1) class diagrams: Graphic notation for

modeling classes and their relationships.

Class diagrams corresponds to an infinite set of object diagrams

(2) object diagrams: Shows individual

objects and their relationships.

Object diagrams are helpful for documenting test cases and discussing examples.

There are two kinds of models of structure:

Page 9: Class Modeling. Basic Class Modeling Concepts Object Class Link Association Generalization Inheritance.

UML Notation of class diagram

The UML symbol for an object is a box with an object name followed a colon and the class name.

The object names and the class name are both underlined.

The object name and class name in boldface by convention

Singular nouns used for the names of classes

JoeSmith:Person

MarySharp:Person

:Person

Page 10: Class Modeling. Basic Class Modeling Concepts Object Class Link Association Generalization Inheritance.

Values and Attributes

A value is piece of data that lacks identity An attribute is an named property of a class that

describes a value held by each object of the class Name, birthdate, and weight are attributes of Person

objects Each attribute has a value for each object. For example:

attribute birthdate has value 21 Octorber 1983 Each attribute name is unique within a class Object is to class as value is to attribute An attribute should describe values NOT objects

Page 11: Class Modeling. Basic Class Modeling Concepts Object Class Link Association Generalization Inheritance.

Values and Attributes (UML notation)

The UML notation lists attributes in the second compartment of the class box.

Optional details, such as type and default value, may follow each attribute.

A colon precedes the type. And equal sign precedes

the default value

Person

Name: stringBirthdate: date

JoeSmith:Person

Name: JoeSmithBirthdate=21 October 1983

Page 12: Class Modeling. Basic Class Modeling Concepts Object Class Link Association Generalization Inheritance.

Operations and Methods

An operation is a function or procedure that may be applied to or by objects in a class.

The same operation may apply to many different classes. Such an operation is polymorphic; that is, the same operation takes on different forms in different classes.

A method is the implementation of an operation for a class. When an operation has methods on several classes, it is

important that the methods all have the same signature- the number and types of arguments and the type of result value.

Feature is a generic word for either an attribute or operation.

Page 13: Class Modeling. Basic Class Modeling Concepts Object Class Link Association Generalization Inheritance.

Operations and Methods (UML notation)

The UML notation is to list operations in the third compartment of the class box. parentheses enclose

argument list, commas separate the

arguments, a colon precedes the result

type, parentheses enclose

argument list that is empty therefore no arguments

PersonName

BirthdatechangeJob

changeAddress

GeometricObjectColor

PositionMove(delta : Vector)

Select(p: Point) : BooleanRotate (in angle: float=0.0)

Test(p:Point,v:Vector)

Page 14: Class Modeling. Basic Class Modeling Concepts Object Class Link Association Generalization Inheritance.

Summary of Notation for classes

Each argument may have a direction, name, type and default value. The direction indicates whether an argument is an input (in) , output (out), or an input

argument that can be modified (inout). A colon precedes the type. An equal sign precedes the default value, which is used if no argument is supplied for the

argument. Direction argumentName : type = defaultValue The attribute and operation compartments of class boxes are optional, and you may or may

not show them.

ClassName

attributeName1: dataType1=defaultValue1attributeName2:dataType2=defaultValue2

operationName1 (argumentList1): resultType1operationName2(argumentList2):resultType2

Page 15: Class Modeling. Basic Class Modeling Concepts Object Class Link Association Generalization Inheritance.

Link and Association Concepts

Links and Associations Multiplicity Association End Names Association Classes Qualified Associations

Page 16: Class Modeling. Basic Class Modeling Concepts Object Class Link Association Generalization Inheritance.

Links and Associations

A link is a physical or conceptual connection among objects.

Most links relate two objects, but some links relate three or more objects.

A link is an instance of an association. A association is a description of a group of links

with common structure and common semantics. Links and associations often appear as verbs in

problem statements

Page 17: Class Modeling. Basic Class Modeling Concepts Object Class Link Association Generalization Inheritance.

Many-to-many association

Many-to-many association: An association describes a set of potential links in the same way that a class describes a set of potential objects

The asterisk is a multiplicity symbol Multiplicity specifies the number of instances of one class

that may relate to a single instance of another class The UML notation for a link is a line between objects; a line

may consist of several line segments. If the link has a name, it is underlined. An association connects related classes and is also denoted

by a line.

Page 18: Class Modeling. Basic Class Modeling Concepts Object Class Link Association Generalization Inheritance.

.

Personname

John:Personname=“John"

Mary:Personname= “Mary"

GE:Companyname=“GE"

Companyname* *

UML notation of Many-to-many association

Sue:Personname= “Sue"

Alice:Personname= “Alice"

Jeff:Personname= “Jeff"

IBM:Companyname=“IBM"

Page 19: Class Modeling. Basic Class Modeling Concepts Object Class Link Association Generalization Inheritance.

The association name is optional, if the model is unambiguous.

Ambiguity arises when a model has multiple associations among the same classes

When there are multiple associations, you must use association names or association end names to resolve ambiguity.

Developers often implement associations in programming languages as references from one object to another.

A reference is an attribute in one object refers to another object.

Page 20: Class Modeling. Basic Class Modeling Concepts Object Class Link Association Generalization Inheritance.

Multiplicity

Multiplicity: the number of instances of one class that may relate to a single instance of an associated class/ constraint on the size of a collection

“1” (exactly one) “1..*” (one or more)“3..5” (three to five, inclusive)“*” equals “many” (zero or more)

Page 21: Class Modeling. Basic Class Modeling Concepts Object Class Link Association Generalization Inheritance.

.

Countryname

Canada:Countryname=“Canada"

France:Countryname= “France"

Ottawa:CapitalCityname=“Ottawa"

CapitalCityname1 1

One to one association

Sengal:Personname= “Sengal"

Dakar:CapitalCityname=“Dakar"

Paris:CapitalCitlyname=“Paris"

HasCapital

HasCapital

HasCapital

HasCapital

Page 22: Class Modeling. Basic Class Modeling Concepts Object Class Link Association Generalization Inheritance.

Zero-or-one multiplicity

Workstation Windowconsole

1 0..1

Page 23: Class Modeling. Basic Class Modeling Concepts Object Class Link Association Generalization Inheritance.

Multiplicity (continued)

Cardinality: is the count of elements that are actually in a collectionUnderestimating multiplicity(“one”)…can

restrict the flexibility of an applicationOverestimating multiplicity(“many”)…imposes

overhead and requires the application to supply additional information to distinguish among the members of a “many” set

Page 24: Class Modeling. Basic Class Modeling Concepts Object Class Link Association Generalization Inheritance.

Association vs. link

BA anA:A aB:B* *

anAssociation

A B**

anAssociation

anotherAssociation

Class Diagram

aLink

anA:A aB:BaLink

anotherLink

Object Diagram

Page 25: Class Modeling. Basic Class Modeling Concepts Object Class Link Association Generalization Inheritance.

Association End Names

Association end names: often appear as nouns Convenient for traversing associations (treat like a

pseudo attribute)

CompanyPerson*employee employer

WorksFor 0…1

Page 26: Class Modeling. Basic Class Modeling Concepts Object Class Link Association Generalization Inheritance.

Association Classes

Association Class: an association that is also a class

Like the links of an association, the instances of an association class derive identity from instances of the constituent classes

Like a class, an association class can have attributes and operations and participate in associations

Page 27: Class Modeling. Basic Class Modeling Concepts Object Class Link Association Generalization Inheritance.

UML notation of an association class

Association Classes (continued) UML notation for an association class is a box (class

box) attached to the association by a dashed line.

AccessibleByaccessPermission

File User* *