+ All Categories
Home > Documents > Class Diagram Classes are the most important building block of any object-oriented system. A class...

Class Diagram Classes are the most important building block of any object-oriented system. A class...

Date post: 14-Jan-2016
Category:
Upload: vivian-wilcox
View: 212 times
Download: 0 times
Share this document with a friend
Popular Tags:
40
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.
Transcript
Page 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.

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.

Page 2: 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.

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.

Page 3: 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.
Page 4: 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.
Page 5: 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.

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.

Page 6: 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.

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,

Page 7: 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.

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.

Page 8: 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.

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.

Page 9: 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.

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

Page 10: 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.

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.

Page 11: 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.

Types of Operations

• Implementor Operationsimplements some business functionality. They can be found by examining Interaction diagram.

• Manager OperationsManage the creation and destruction of objects.

• Access OperationsSet and get operation in a class to access private attributes. • Helper OperationsHelp other operation of the class, but cant be access directly. Private operation of a class.

Page 12: 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.

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.

Page 13: 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.

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

. . . showsthat there aremore operationor attributes in this class

Page 14: 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.
Page 15: 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.

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

Page 16: 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.

Class stereotypes in UML

• There are three class stereotypes in UML

• Boundary Classes

• Control Classes

• Entity Classes

Page 17: 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.

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

Page 18: 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.

VisibilityOne 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 +

protectedAny descendant of the classifier can use the feature;

specified by prepending the symbol #

privateOnly the classifier itself can use the feature;

specified by prepending the symbol –

• No sign represents a package visibility.

Page 19: 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.

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.

Page 20: 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.

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– <number> Exactly <number>– <number1>..<number2> Between <number1>and <number2>– <number>..n <number> or more– <number1>,<number2> <number1>or<number2>– <number1>,<number2>..<number3>

Exactly <number1>or between <number2> and <number3>

<number1>..<number2>,<number3>..<number4>

Between <number1> and <number2>

or between <number3> and <number4>

Page 21: 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.

Setting Class Persistence

Persistent The information in objects of the class will be saved to a database or some other form of persistent storage.

TransientThe information in objects will not be saved to persistent storage

Page 22: 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.

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.

Page 23: 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.

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.

Page 24: 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.

Association properties

NameAn association can have a name. That describe the nature of the relationship. RoleA 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. MultiplicityIt represent that how many objects of one class may connect to the objects of another class.

NavigationIt 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.

Page 25: 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.

Works for

Name

Person Company

employeePerson Companyemployer

Role nameemployeePerson Company

employer1..*

*

Person Parent

Child *

2

Page 26: 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.

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

*

Page 27: 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.

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.

Page 28: 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.

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.

Page 29: 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.

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.

Page 30: 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.
Page 31: 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.
Page 32: 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.

Company

Department

ContractInformation

Headquarters

PersonnelRecord

Office

name

Person

nameemployeeIDtitle

getNamegetIDgetContractInformationgetPersonnelRecords

taxIDemplomentHistorysalary

addressphone

address

1..* 1..*

0..1

1..* 1 manager

member

1

*

Location

* *

dependency

role generalization

aggregation

multiplicityattributes

operations

class

Page 33: 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.

Student

namestudentID

School

-name-address-phone

+addStudent()+removeStudent()+getStudent()+getAllStudent()+addDepartment()+getDepartment()+getAllDepartment()

Department

-name

+addIntructor()+removeInstructor()+getInstructor()+getAllInstructor()

Course

namecourseID

Instructor

name

Has

AssignedTo

Member

Attends

Teaches

0..1

1..*

0..11..*1..*

1..*1

1..*

*

** * 1..*

role:chairperson

Page 34: 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.
Page 35: 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.
Page 36: 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.
Page 37: 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.
Page 38: 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.
Page 39: 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.
Page 40: 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.

Recommended