unified modeling language (uml) - gujarat · session 3 - exception-handling java programming 2 tcs...

87
Session 3 - Exception-Handling Java Programming 1 1 TCS Confidential Unified Modeling Language (UML)

Upload: buinhu

Post on 02-Apr-2018

222 views

Category:

Documents


2 download

TRANSCRIPT

Session 3 - Exception-Handling Java Programming

11TCS Confidential

Unified Modeling Language (UML)

Session 3 - Exception-Handling Java Programming

22TCS Confidential

UML - BriefUnified Modeling LanguageInvented by

Grady BoochJim RumbaughIvar Jacobson

Useful in OOADCurrent version is UML 2.0 (June-2003 )

Session 3 - Exception-Handling Java Programming

33TCS Confidential

Ways of Using UMLUML as sketch

Gives Rough overall idea of a systemCan be done with pen and paper

UML as blueprint Gives complete idea of a systemTools are available in market like Rational Suite Tools

UML as programming languageUML diagram to code generation. ( Helps in speed up the development )Code to UML diagram(Help in understanding the system)

Session 3 - Exception-Handling Java Programming

44TCS Confidential

Ways of Using UML

Software perspectiveThe elements of UML map directly

to elements in a software systemConceptual perspective

Helps in understanding the functionality of system

Session 3 - Exception-Handling Java Programming

55TCS Confidential

UML DiagramsUse case DiagramActivity DiagramClass DiagramSequence DiagramState DiagramComponent DiagramDeployment Diagram

Session 3 - Exception-Handling Java Programming

66TCS Confidential

System Views

Users’ View

Structural View

Behavioral View

Implementation View

Environmental View

Session 3 - Exception-Handling Java Programming

77TCS Confidential

System Views

Users’ View

Structural View

Behavioral View

Implementation View

Environmental View

Defines the functionalities made available by system

to users

Session 3 - Exception-Handling Java Programming

88TCS Confidential

System Views

Users’ View

Structural View

Behavioral View

Implementation View

Environmental View

Defines entities along with

relationships to understand working

of system

Session 3 - Exception-Handling Java Programming

99TCS Confidential

System Views

Users’ View

Structural View

Behavioral View

Implementation View

Environmental View

Captures objects interaction to realize

the system behaviour

Session 3 - Exception-Handling Java Programming

1010TCS Confidential

System Views

Users’ View

Structural View

Behavioral View

Implementation View

Environmental View

Captures important components and

their dependencies

Session 3 - Exception-Handling Java Programming

1111TCS Confidential

System Views

Users’ View

Structural View

Behavioral View

Implementation View

Environmental View

Models different components

implementation on hardware

Session 3 - Exception-Handling Java Programming

1212TCS Confidential

UML – Users’ View

Use Case Diagram

Session 3 - Exception-Handling Java Programming

1313TCS Confidential

Use CaseUse case is chunk of functionalitye.g. Customer registration, money transfer, purchase itemUseful for capturing functional and non-functional requirementsDescribes interactions between users and system

Session 3 - Exception-Handling Java Programming

1414TCS Confidential

Use Case - ComponentsProcess : Functionality that system should provide

Actor : Someone that is external to the system. But that is going to interact with the system

Session 3 - Exception-Handling Java Programming

1515TCS Confidential

Use Case - Relationships

GeneralizationIncludeExtends

Session 3 - Exception-Handling Java Programming

1616TCS Confidential

GeneralizationChild use case(s) inherit the behavior and meaning of parent use case

Pay fee

through credit card

through cheque

Session 3 - Exception-Handling Java Programming

1717TCS Confidential

Product purchase use case compulsorily and automatically includes behavior of the customer authentication use case

Customer authentication

Product Purchase

<< Include >>

Include

Session 3 - Exception-Handling Java Programming

1818TCS Confidential

Use to show optional system behavior only under certain conditions

For international student, security check is required while enrolling

Extends

Perform security check

Enroll in university

Student

<< extends>>

International Student

Session 3 - Exception-Handling Java Programming

1919TCS Confidential

Use Case Diagram – Example

Customer

Buy a Product

Browse catalog and select

items

<<include>>

Session 3 - Exception-Handling Java Programming

2020TCS Confidential

Use Case Document templateIntroduction (Brief about functionality)Actors detailPre-conditionMain pathAlternative pathException / Error situationPost-conditionDetails of non-functional requirements like security/availability/performance etc

Session 3 - Exception-Handling Java Programming

2121TCS Confidential

Use Case Packaging

Query balance

Print Balance sheet

Receive grant

Make payment

Accounts

Enroll student

Compute CGPA

Enter grade

Academics

Print grade card

Modify grade

Session 3 - Exception-Handling Java Programming

2222TCS Confidential

UML – Structure View

Class Diagram

Session 3 - Exception-Handling Java Programming

2323TCS Confidential

Class DiagramDescribes how the system is structured rather than how it behaves.

Describes various objects in the system and the relationships among them

Session 3 - Exception-Handling Java Programming

2424TCS Confidential

ClassCore element of Class diagramUsed to represent entities in system, often relate to real-world object

-name: String-contactPerson: Client-employees: Client[]

Company

+getName: String

Name

Attribute

Operation

Session 3 - Exception-Handling Java Programming

2525TCS Confidential

Class – Attribute & OperationAttribute is property of Class

E.g. address, city

Operation is function that class can perform

E.g. getAddress(), getCity()

Session 3 - Exception-Handling Java Programming

2626TCS Confidential

Attribute & Operation ScopeAttribute / Operation of class has four scopes- Private+ Public# Protected~ default (within package)

Session 3 - Exception-Handling Java Programming

2727TCS Confidential

Class Diagrams - RelationshipsAssociationCompositionAggregationGeneralizationRealizationDependency

Session 3 - Exception-Handling Java Programming

2828TCS Confidential

Association

Describes connection between classes

Neither of the classes have ownership.

Library Member BookBorrowed by

1 *

Session 3 - Exception-Handling Java Programming

2929TCS Confidential

Direct AssociationDescribes connection between class where in one class will have ownership.

Order OrderLine1 *

Item

1

1

Session 3 - Exception-Handling Java Programming

3030TCS Confidential

CompositionRepresents whole-part relationships where the lifetime of the aggregated class is bound by the lifetime of this association's class.

Order is compose of OrderLine. On deletion of Order associated OrderLines will be deleted.

1Order OrderLine

*

Session 3 - Exception-Handling Java Programming

3131TCS Confidential

AggregationRepresents whole-part relationships where lifetime of the aggregated class is independent of the lifetime of this association's class.

OrderLine is an aggregate of Item. Deletion of OrderLine will not delete Item associated to it.

1OrderLine Item

1

Session 3 - Exception-Handling Java Programming

3232TCS Confidential

GeneralizationRelationship between a more specific element and a less specific element.Defines the inheritance structure in the model.Generalization relationships can be created between two Java classes or two Java interfaces .

Session 3 - Exception-Handling Java Programming

3333TCS Confidential

Generalization

NamePhone NumberEmail Address

Person

SalaryStudent NumberAverage Mark

Student Professor

Is Eligible To EnrollGet seminars taken

Purchase Parking Pass

Session 3 - Exception-Handling Java Programming

3434TCS Confidential

RealizationSpecify where a (concrete) modeled Java class is used to implement a modeled Java interfaceThis is generated as an implements keyword in the implementing Java class

Session 3 - Exception-Handling Java Programming

3535TCS Confidential

RealizationA class that implements an interface can provide an implementation for some or all the abstract operations of the interface. If an interface's operations are only partially implemented by a class, that class is then defined as abstract

Session 3 - Exception-Handling Java Programming

3636TCS Confidential

Realization

+sort():voidSortable

-id: int-products: Product[]

-name: String-contactPerson: Client-employees: Client[]

Company ProductGroup

+sort(): void+sort():void

Session 3 - Exception-Handling Java Programming

3737TCS Confidential

Dependency

Shows that a change to independent class requires changes in dependent class.

e.g. Class invoke method of other class

Dependent Class

Independent Class

Session 3 - Exception-Handling Java Programming

3838TCS Confidential

A Simple Class Diagram

Product

Order Linequantity: Integerprice: Money

OrderdateRec: Date [0..1]isPrePaid: Bool [1]Number: String [1]price: Money

dispatchclose

Customername [1]address [0..1]

getCreditRating(): String

Corporate Customer

contactNamecreditRatingcreditLimit

Personal Customer

creditCardNumber

Employee

*

*

*

*

1

1

1

0..1salesRep

{getCreditRating() == “poor”}

{if Order.customer.getCreditRating

is poor then Order,isPrePaidmust

be true}

lineItems

Session 3 - Exception-Handling Java Programming

3939TCS Confidential

UML – Behavioral View

Sequence DiagramCollaboration DiagramActivity DiagramState-Chart Diagram

Session 3 - Exception-Handling Java Programming

4040TCS Confidential

Sequence DiagramShow object interaction arranged in a time sequenceHelp us in determining the responsibility of the different classes e.g. What method should be supported by each class

Session 3 - Exception-Handling Java Programming

4141TCS Confidential

Sequence Diagram

Obj2Obj1Object

participating in the

interactionObjects’life line

Message Time for which object is active

Return Message

Session 3 - Exception-Handling Java Programming

4242TCS Confidential

Sequence Diagram – ScenarioWe want to calculate price of an OrderOrder contains more then one line itemsEach line item has product informationBased on the product price & required quantity base price is calculatedOrder then needs to compute overall discount (based on rules tied to customer)

Session 3 - Exception-Handling Java Programming

4343TCS Confidential

Sequence Diagram – An Example

Session 3 - Exception-Handling Java Programming

4444TCS Confidential

Sequence Diagram: Creating & Deleting ParticipantsaHandler

aQueryCommand

query db

new

new

results

resultsextract results

execute

aDatabaseStatement

Session 3 - Exception-Handling Java Programming

4545TCS Confidential

Sequence Diagram: Loops & Conditionalsprocedure

foreach (lineitem)if (product.value > Rs.10k)

careful.dispatchelse

regular.dispatchend if

end forif (needsConfirmation)

messenger.confirmend procedure

Session 3 - Exception-Handling Java Programming

4646TCS Confidential

Sequence Diagram: Loops & Conditionals:Order regular:

Distributor:Messengercareful:

Distributordispatch

altloop

opt

[for each line item]

[value > Rs.10000]

[else]

dispatch

dispatch

confirm[needsConfirmation]

Session 3 - Exception-Handling Java Programming

4747TCS Confidential

Collaboration diagramShows both structural and behavioral aspects

Structural aspect: Objects and links between them

Behavioral aspect: message exchange between objects

Session 3 - Exception-Handling Java Programming

4848TCS Confidential

Collaboration diagram

anOrder

anOrderLine aProduct

aCustomer

1: calcPrice

1.1: getProduct()1.2: getQuantity()

1.3: getPricingDetails

1.4: calcBasePrice()1.5: calcDiscount() 1.5.1: getDiscountInfo()

Session 3 - Exception-Handling Java Programming

4949TCS Confidential

Activity DiagramNormally used to explain complex processesRepresent different activities and transition between themAn Activity is a state with an internal action and one or more outgoing transitionIt may or may not correspond with methods of classes

18

Slide 49

18 If an activity has more than one outgoing transaction then these must be indentified through condition.152481, 11/15/2006

Session 3 - Exception-Handling Java Programming

5050TCS Confidential

Activity Diagram ComponentsStart: Where the flow of control starts

Activity : Action state

Transition : Movement between activities

End: Where the flow of control ends

Session 3 - Exception-Handling Java Programming

5151TCS Confidential

Fork: A single flow of control split into two or more concurrent flows of control

Allow parallel threads of activitiesOne input, 2 or more output

Activity Diagram Components

Session 3 - Exception-Handling Java Programming

5252TCS Confidential

Activity Diagram (Fork)

Received Order

Verify ordered product are in

stock

Verify customer has available

credit

Session 3 - Exception-Handling Java Programming

5353TCS Confidential

Join has two or more input transition and a single output transition.

Concurrent flow wait until all the incoming flow have reached to join2 or more input, One output

Activity Diagram Components

Session 3 - Exception-Handling Java Programming

5454TCS Confidential

Activity Diagram (Join)

Accept Order

Verify ordered product are in

stock

Verify customer has available

credit

Session 3 - Exception-Handling Java Programming

5555TCS Confidential

Activity Diagram - Registration Process

[Registration time period expired]

Create Curriculum

Close Registration

Open Registration

Mail catalog to Students

Place catalog in Bookstore

Select courses to teach

Create catalog

Session 3 - Exception-Handling Java Programming

5656TCS Confidential

Activity DiagramSwim lane enables you to

group activities based on who is performing themEmphasize on who is going to

perform what

Session 3 - Exception-Handling Java Programming

5757TCS Confidential

Registrar ProfessorCreate Curriculum

Close Registration

Open Registration

Mail catalog to Students

Place catalog in Bookstore

Select courses to teach

Create catalog

Session 3 - Exception-Handling Java Programming

5858TCS Confidential

State Chart DiagramShows how the state of an object changes in its lifetime.Normally used for objects having lots of dynamic behaviore.g. Object like button having ON and OFF state doesn’t required State chart diagram.

Session 3 - Exception-Handling Java Programming

5959TCS Confidential

State Chart Diagram ComponentsInitial state: represented as filled circleState : represented by a

rectangle with rounded cornerTransition :event [guard]/actionGuard : is a Boolean logical conditionFinal state: represented by a filled circle inside a larger circle.

[ ]

[guard] event

Session 3 - Exception-Handling Java Programming

6060TCS Confidential

Unprocessed order

Accept order

Fulfilled order

Reject Order

Pending order

[reject] checked [accept] checked

[some items not available] processed

[all items available]processed/deliver

[all itemsavailable]new supply

State Chart Diagram

Session 3 - Exception-Handling Java Programming

6161TCS Confidential

UML – Implementation View

Component Diagram

Session 3 - Exception-Handling Java Programming

6262TCS Confidential

Component DiagramDescribes high-level reusable parts of a system that helps

Developer / Analyst in understanding the systemServes as input to deployment

diagram

Session 3 - Exception-Handling Java Programming

6363TCS Confidential

Component DiagramIn a class diagram the implementation of the classes is source code. Component diagrams representsexecutable code

Session 3 - Exception-Handling Java Programming

6464TCS Confidential

Component Diagram ComponentsProvided Interfaces : (lollipop notation )Required Interfaces : (Socket notation )Ports : Distinct interaction point

Session 3 - Exception-Handling Java Programming65TCS Confidential

Component Diagram

Provided Interface

Required Interface

Session 3 - Exception-Handling Java Programming

6666TCS Confidential

UML - Environmental View

Deployment Diagram

Session 3 - Exception-Handling Java Programming

6767TCS Confidential

Deployment DiagramHelps in visualizing which components are running on which processors

Session 3 - Exception-Handling Java Programming

6868TCS Confidential

Deployment Diagram

Session 3 - Exception-Handling Java Programming

6969TCS Confidential

Fitting the UML into SDLCRequirements Analysis (what users want the system to do)

Use Case (‘interaction between processes and external entities’)Class [Conceptual] (‘identification of the domain entities’)Activity (‘explanation of process flow’)

110

Slide 69

110 Activity Daigram:Optional, For Coplex Business process it is used to get clear idea with graphical represantation along with the owner of the processes.152481, 11/15/2006

Session 3 - Exception-Handling Java Programming

7070TCS Confidential

Fitting the UML into SDLCDesign (How system implements requirements)

Class [Software] (‘how classes interrelate’)Sequence (‘how objects

interacts)Component (‘grouping of related

components’)

Session 3 - Exception-Handling Java Programming

7171TCS Confidential

Fitting the UML into SDLCState (for objects with complex

life cycle)e.g. Order states like unprocessed, accepted, pending, rejected, fulfilled.Deployment (‘physical layout of

the software’)

Session 3 - Exception-Handling Java Programming

7272TCS Confidential

Fitting the UML into SDLC

DocumentationTo illustrate UML diagrams,

write additional documentatione.g. (“screen flow diagram”“decision table”)

Session 3 - Exception-Handling Java Programming

7373TCS Confidential

Decision tableHelps us in putting complex if-else conditions in simple tabular mannerTwo types of decision table

Binary ValuedMulti Valued

Session 3 - Exception-Handling Java Programming

7474TCS Confidential

Rules for electricity billing Graphical RepresentationIf the meter reading is "OK", calculate on consumption basis (i.e. meter reading)If the meter reading appears "LOW", then check if the house is occupied.

Session 3 - Exception-Handling Java Programming

7575TCS Confidential

Rules for electricity billing If the house is occupied, calculate on seasonal consumption basis otherwise calculate on consumption basis.If the meter is damaged, calculate based on maximum possible electricity usage

Session 3 - Exception-Handling Java Programming

7676TCS Confidential

DECISION TABLE(BINARY-VALUED )

Y N N N Double special rate

N Y N N Double minimum rate

N N Y N Special rate

N N N Y Minimum rate

N Y N Y Consumption < 300 units per month

N N Y Y Domestic Customer

Session 3 - Exception-Handling Java Programming

7777TCS Confidential

DECISION TABLE(MULTI-VALUED )

2S2MSMRate≥ 300< 300 ≥ 300< 300 Consumption

NNDDCustomer

• D: Domestic• N: Non–Domestic• M: Minimum

• S: Special• 2M: Twice Minimum• 2S: Twice Special

Session 3 - Exception-Handling Java Programming

7878TCS Confidential

Rules for electricity billing binary-value decision tables can grow large if the number of rules increase Multi-valued decision tables have an edge In the above example, if we add a new class of customers, called Academic, with the rules

Session 3 - Exception-Handling Java Programming

7979TCS Confidential

BINARY-VALUED DECISION TABLEThree rows and two columns are added to deal with the extra class of customers

Session 3 - Exception-Handling Java Programming

8080TCS Confidential

DECISION TABLE(BINARY-VALUED )

NNNNYNN

YN

NNNYNNY

NN

YNNNTwice concessional rateNYNNConcessional rate NNYNTwice special rate NNNNTwice minimum rate NYNNSpecial rate NNNYMinimum rate NYNY

Consumption < 300 units per month

NNNYDomestic Customer YYNNAcademic

Session 3 - Exception-Handling Java Programming

8181TCS Confidential

MULTI-VALUED DECISION TABLEOnly two columns are added to deal with the extra class of customers

Session 3 - Exception-Handling Java Programming

8282TCS Confidential

DECISION TABLE(MULTI-VALUED )

TS≥ 300

M<300

CTCTMSRate<300≥ 300 <300≥ 300 Consumption

Academic Non-domesticDomesticCustomer

S : SpecialM : MinimumTS : Twice SpecialTM : Twice MinimumTC : Twice ConcessionalC : Concessional

Session 3 - Exception-Handling Java Programming

8383TCS Confidential

UML - ToolsRational SuitArgoUMLPoseidon for UMLEclipse with UML plug-inNetBeans Enterprise Pack

Session 3 - Exception-Handling Java Programming

8484TCS Confidential

Thank You!

Session 3 - Exception-Handling Java Programming

8585TCS Confidential

Question & Answer