2 class use case

80
UML -Class Diagram -Use case Diagram Prepared By: Minal Maniar Assistant Professor Computer Department CSPIT, CHARUSAT, Changa.

Transcript of 2 class use case

Page 1: 2 class use case

UML -Class Diagram -Use case Diagram

Prepared By: Minal Maniar

Assistant Professor

Computer Department

CSPIT,

CHARUSAT, Changa.

Page 2: 2 class use case

Class diagram

A class diagram depicts classes and their interrelationships

Used for describing structure and behavior in the use cases

Provide a conceptual model of the system in terms of

entities and their relationships– to translate the models into

programming code.

Represents the structural – static behavior of the System.

Used for requirement capture, end-user interaction

Detailed class diagrams are used for developers

Page 3: 2 class use case

Class diagram

Each class is represented by a rectangle subdivided into three compartments Name, Attributes, Operations

Page 4: 2 class use case

Class diagram

Account_Name - Customer_Name

- Balance

+addFunds( )

+withDraw( )

+transfer( )

Name

Attributes

Operations

Page 5: 2 class use case

OO Relationships

There are two kinds of Relationships Generalization (parent-child relationship)

Association (student enrolls in course)

Associations can be further classified as Aggregation

Composition

Page 6: 2 class use case

Represent relationship between instances of classes Student enrolls in a course

Courses have students

Courses have exams

Etc.

Association has two ends Role names (e.g. enrolls)

Multiplicity (e.g. One course can have many students)

Navigability (unidirectional, bidirectional)

OO Relationships: Association

Page 7: 2 class use case

Association: Multiplicity and Roles

University Person

1

0..1

*

*

Multiplicity

Symbol Meaning

1 One and only one

0..1 Zero or one

M..N From M to N (natural language)

* From zero to any positive integer

0..* From zero to any positive integer

1..* From one to any positive integer

teacher employer

Role

Role

“A given university groups many people;

some act as students, others as teachers.

A given student belongs to a single

university; a given teacher may or may not

be working for the university at a particular

time.”

student

Page 8: 2 class use case

Association: Model to Implementation

class Student {

Course enrolls[4];

}

class Course {

Student have[];

}

Student Course enrolls has

* 4

Page 9: 2 class use case
Page 10: 2 class use case

Link and Association

Examples of class and object diagrams

Person and Company

Country and CapitalCity

Workstation and Window

Page 11: 2 class use case

Associations

Association represents a group of links.

Self association:

Binary association:

N-array association:

Person

Company Worker

company

Contract

Worker

employment

Page 12: 2 class use case

Association End Names

Use of association end names is optional, but it is

often easier and less confusing to assign association

end names instead of or in addition to, association

names.

Association end names are necessary for

associations between two objects of the same class

Page 13: 2 class use case

Association Classes

An association class is used to model an association as a class. Association classes often occur in many-to-one and many-to-many associations where the association itself has attributes. It is used to break up a many-to-many association between classes.

These are similar to associative entities on an entity-relationship diagram.

Page 14: 2 class use case

Association Classes Student and Course have a many-to-many relationship, which is resolved by adding

an association class called Section between the classes of Student and Course. Figure illustrates an association class called Section, shown with a dotted line connected to the many-to-many relationship line.

Page 15: 2 class use case

Qualified Associations

It is an Association in which an attribute called qualifier disambiguates the objects for a “many” association end.

A qualifier selects among target objects, reducing the effective multiplicity from “many” to “one” and specify a precise path for finding the target object from the source object.

Page 16: 2 class use case

Qualified Associations(2)

Page 17: 2 class use case

Whole/Part relationships

Whole/part relationships are when one class represents the whole object and other classes represent parts.

The whole acts as a container for the parts.

These relationships are shown on a class diagram by a line with a diamond on one end.

A whole/part relationship may be an entity object that has distinct parts, such as a computer system that includes the computer, printer, display, and so on, or an automobile that has an engine, brake system, transmission, and so on.

Whole/part relationships have two categories: aggregation and composition.

Page 18: 2 class use case
Page 19: 2 class use case

Aggregation

Bag

Apples Milk

AGGREGATION

Container Class

Containee Classes

Example Aggregation: described as a “has a” relationship..

Aggregation provides a means of showing that the

whole object is composed of the sum of its parts

(other objects).

Aggregation is appropriate when Container and

Containees have no special access privileges to

each other.

[From Dr.David A. Workman]

In the student enrollment example, the

department has a course and the course is

for a department. This is a weaker

relationship, because a department may be

changed or removed and the course

may still exist, so independent from each

other.

Department Course

Classroom Student

Computer Printer

Page 20: 2 class use case

Whole/Part relationships

Composition, a whole/part relationship in which the whole has a responsibility for the part,

is a stronger relationship, shown with a filled-in diamond.

Keywords for composition are one class “always contains” another class.

If the whole is deleted, all parts are deleted.

An example would be an insurance policy with riders. If the policy is canceled, the

insurance riders are also canceled. In a database, the referential integrity would be set to

delete cascading child records. In a university there is a composition relationship between a

course and an assignment as well as between a course and an exam. If the course is deleted,

assignments and exams are deleted as well.

Whole Class Part Classes

The McGraw-Hill Companies, 2005 [From Dr.David A. Workman]

A number of different chess boards: Each

square belongs to only one board. If a

chess board is thrown away, all 64

squares on that board go as well.

Example

Page 21: 2 class use case

OO Relationships

Page 22: 2 class use case

Aggregation vs. Composition

Composition is really a strong form of association components have only one owner

components cannot exist independent of their owner

components live or die with their owner

e.g. Each car has an engine that can not be shared with other cars.

Aggregations may form "part of" the association, but may not be essential to it. They

may also exist independent of the aggregate. e.g. Apples may exist

independent of the bag.

Page 23: 2 class use case
Page 24: 2 class use case
Page 25: 2 class use case
Page 26: 2 class use case
Page 27: 2 class use case
Page 28: 2 class use case
Page 29: 2 class use case
Page 30: 2 class use case
Page 31: 2 class use case
Page 32: 2 class use case
Page 33: 2 class use case
Page 34: 2 class use case

Concrete Class

Instantiable – which can have direct instances.

It may have abstract subclasses – But in turn must have concrete descendants

Only concrete classes may be leaf classes in an inheritance tree.

Page 35: 2 class use case

Abstract Class

No direct instances but whose descendant classes have direct instances.

Represented by italicized text or place keyword {abstract} below or after the name

abstract class BankAccount{

String owner;

float dollars;

void deposit(float amount){….}

abstract void withdrawal(float amount);

}

Page 36: 2 class use case

Abstract Class(2)

Program Example : ABC.java

Page 37: 2 class use case

Abstract Class Example

Program Example : ABC.java

Page 38: 2 class use case
Page 39: 2 class use case
Page 40: 2 class use case
Page 41: 2 class use case
Page 42: 2 class use case

Class diagram

[from UML Distilled Third Edition]

Page 43: 2 class use case
Page 44: 2 class use case
Page 45: 2 class use case
Page 46: 2 class use case

User Scenario/ User Story Use Case

Page 47: 2 class use case
Page 48: 2 class use case
Page 49: 2 class use case
Page 50: 2 class use case
Page 51: 2 class use case
Page 52: 2 class use case
Page 53: 2 class use case
Page 54: 2 class use case
Page 55: 2 class use case

This type of details kill progress Use case should be in readable casual format

rather than multipage formal templates.

Page 56: 2 class use case

Identifying Actors

An Actor in a use case is anything with behavior who lives outside of your system, outside of your application, but has a goal they want to accomplish within.

And these are usually human beings, but not always. Now sometimes coming up with the actor is very straightforward.

Ex: If you're building a Calculator App for a mobile device or a simple one person game, you may just have one actor, someone who uses the application, the user.

Ex: if you were building, say, a backend internal Payroll Application, you might have multiple people that do very different goals within such as the payroll administrator, or a manager, or an employee, and you also need to interact with other computer systems.

Page 57: 2 class use case
Page 58: 2 class use case

External actors Internal actors

Page 59: 2 class use case
Page 60: 2 class use case
Page 61: 2 class use case
Page 62: 2 class use case
Page 63: 2 class use case
Page 64: 2 class use case
Page 65: 2 class use case

who initiated this particular use case

any one else is a secondary actor

Page 66: 2 class use case

Identifying Scenarios

When we describe a use case scenario, we're typically looking at describing a goal that an actor can accomplish in a single encounter, and we're trying to stay focused on the user's goal, on their intention.

Ex: log in to application might first sound like a use case. It has an active verb, it typically has multiple steps, multiple conditions, you could forget the password or be required to register and so on. But if we emphasize the users focus their goal, we realized that their goal with our system is not to log in, the reason they want to log in is to do something.

So what is that something in your system?

Page 67: 2 class use case
Page 68: 2 class use case
Page 69: 2 class use case
Page 70: 2 class use case
Page 71: 2 class use case
Page 72: 2 class use case
Page 73: 2 class use case
Page 74: 2 class use case

Diagramming Use Cases

It's almost always a diagram of several use cases and multiple actors at the same time. The reason it exists is so we can get an overview of these and see how they interact all in context.

Page 75: 2 class use case
Page 76: 2 class use case
Page 77: 2 class use case
Page 78: 2 class use case
Page 79: 2 class use case
Page 80: 2 class use case

References

1. www.Lynda.com 2. http://www.uml.org 3. http://www.cems.uwe.ac.uk/~jsa/UMLJavaShortCourse09/CGOu

tput/Unit9/unit9(0809)/page_03.htm 4. http://www.uml-diagrams.org/constraint.html 5. http://www.jguru.com/ 6. Systems analysis and design 8th Edition by Kendall & kendall 7. Object Oriented Modeling and Design with UML 2nd Edition by

Michael R Blaha & James Rumbaugh