3100-topic5 (1)

Upload: energy0124

Post on 06-Jul-2018

224 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/17/2019 3100-topic5 (1)

    1/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 1

    Software Engineering

    Topic 5:Software Design

    Yor !a"e: #####################

    Co"pter Science $ Engineering Depart"ent

    The Chinese University of %ong &ong

  • 8/17/2019 3100-topic5 (1)

    2/127

     © Chinese University, CSE Dept. Software Engineering / 5 - '

    Prelude

    ♦ Software (esign sho)( *e *ase( on s/w engineeringprincip)es + igor an( for"a)ity

     ppropriate notations for (esign

     + Separation of concerns, o()arity, *straction %an()e (esign co"p)e0ity, "ae s/w n(erstan(a*)e an(

    re)ia*)e

     + nticipation of change, 2ncre"enta)ity 3ro(ce evo)va*)e s/w (esign

     + 4enera)ity 3ro(ct fa"i)y

  • 8/17/2019 3100-topic5 (1)

    3/127

     © Chinese University, CSE Dept. Software Engineering / 5 -

    Prelude

    ♦ Software (esign sho)( *e *ase( on s/w engineeringprincip)es + igor an( for"a)ity

     ppropriate notations for (esign

     + Separation of concerns, o()arity, *straction %an()e (esign co"p)e0ity, "ae s/w n(erstan(a*)e an(

    re)ia*)e

     + nticipation of change, 2ncre"enta)ity 3ro(ce evo)va*)e s/w (esign

     + 4enera)ity 3ro(ct fa"i)y

  • 8/17/2019 3100-topic5 (1)

    4/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 6

    Prelude

    ♦%igh 7a)ity (esign + "o()ar strctre

     + (eco"position criteria

    ♦2nfor"ation hi(ing: a "o()e is characteri8e(*y the infor"ation it hi(es fro" other "o()es⇐ ###########  + 2nfor"ation hi(ing 9 a*stract (ata type

     - (esign + #############(esign

    ♦Stepwise refine"ent: ########## (esign

  • 8/17/2019 3100-topic5 (1)

    5/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 5

    Top-down vs. Bottom-up Designs

    Top-(own (esign ;otto"-p (esign

  • 8/17/2019 3100-topic5 (1)

    6/127

     © Chinese University, CSE Dept. Software Engineering / 5 - <

    Software Design Activity

    ♦ Software (esign + syste" (eco"position into ############ 

     

    ♦ Description ofa=fnctions of each "o()e >? ####-"o()e

    *=interfaces *etween "o()es >? ####-"o()e

    ⇒  the software strctre @architectre=

  • 8/17/2019 3100-topic5 (1)

    7/127

     © Chinese University, CSE Dept. Software Engineering / 5 - A

    ♦2"p)e"ent

    ♦Design for change

     +  (esign that is f)e0i*)e enogh to acco""o(ate

    changes easi)ye.g. B########### for constant na"es in C

    Software Design Activity

    M  

    M  

    M  

    M  

    D ecom pose   →  

    1

    2

    3

  • 8/17/2019 3100-topic5 (1)

    8/127

     © Chinese University, CSE Dept. Software Engineering / 5 -

    What hanges!

    ♦ Change of a)gorith"s + to i"prove efficiency, genera)ity

     + e.g. sorting a)gorith" @############ →  ############=

    ♦ Change of (ata strctre @1A "aintenance cost= + e.g. arrays vs )ine( )ists

     + Data strctres representing a Tree

    ♦ Change of n(er)ying a*stract "achine + %i(es (etai)s of the n(er)ying h/w

     + e.g. co"p)ier, (ata*ase, S

    ♦ Change of periphera) (evices + e.g. printers, ter"ina)s, icrosoft e0perience

    ♦ Change of socia) environ"ent + e.g. ta0, socia) ha*its, crrency changes

  • 8/17/2019 3100-topic5 (1)

    9/127

     © Chinese University, CSE Dept. Software Engineering / 5 - F

    What hanges!

    ♦ Change of a)gorith"s + to i"prove efficiency, genera)ity

     + e.g. sorting a)gorith" @############ →  ############=

    ♦ Change of (ata strctre @1A "aintenance cost= + e.g. arrays vs )ine( )ists

     + Data strctres representing a Tree

    ♦ Change of n(er)ying a*stract "achine + %i(es (etai)s of the n(er)ying h/w

     + e.g. co"p)ier, (ata*ase, S

    ♦ Change of periphera) (evices + e.g. printers, ter"ina)s, icrosoft e0perience

    ♦ Change of socia) environ"ent + e.g. ta0, socia) ha*its, crrency changes

  • 8/17/2019 3100-topic5 (1)

    10/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 1G

    Data Structure "epresenting a Tree #$%

  • 8/17/2019 3100-topic5 (1)

    11/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 11

    Data Structure "epresenting a Tree #&%

     

  • 8/17/2019 3100-topic5 (1)

    12/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 1'

    Product 'amilies

    ♦  set of (ifferent versions of a progra", (e to + (ifferent h/w or s/w

     + (ifferent environ"ent with (ifferent re7ire"entson perfor"ance or resorce cons"ption

     + syste" evo)tion (e to new re7ire"ents or7a)ity i"prove"ent

     + Usa))y with the sa"e *asic set of fnctiona)

    re7ire"ents

  • 8/17/2019 3100-topic5 (1)

    13/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 1

    Product 'amilies

    ♦The so)tion: + "ini"i8e the cost of changing (esign (ecisions

    !ecessary too)s to "anage pro(ct fa"i)ies:

     ############################ too)s

    S ti l l ti

  • 8/17/2019 3100-topic5 (1)

    14/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 16

    Se(uential ompletion)

    A *raphical +iew

    Requirements

    1

    2

    3

    Version 1

    Version 1

    Version 2 5

    Requirements

    1

    2

    3

    4 6

    7 Version 3

    4

    Requirements

    1

    2

    3

    Version 2 5

    Version 1

    4

     ____________ 

     __________ 

  • 8/17/2019 3100-topic5 (1)

    15/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 15

    ,odulariation Techni(ues

    1= rchitectre (esign @overa)) strctre='= Detai)e( (esign @(esign of each "o()e *y

    Binfor"ation hi(ing=

  • 8/17/2019 3100-topic5 (1)

    16/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 1<

    #$% verall Structure

    ♦o()e - a we))-(efine( co"ponent of a s/wsyste"

     + se)f-containe(

     + with c)ear *on(ary

     + co))ection of  otines @.c=

    Data

    Type#(efinitions @.h=

  • 8/17/2019 3100-topic5 (1)

    17/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 1A

    #$% verall Structure

    ♦!otation)et S *e a s/w syste", co"pose( of "o()es 1, ' ,H, n

     i.e., S > I 1,',H,n J

      re)ation r on S is a s*set of SKS

    @ car(ina)ity > ############## =

     i.e., r: "o()e K "o()e ;oo)ean

    Le say i is re)ate( to  M @*oth in S= iff i r  M is tre.

    @ e.g. r: Bca)) =

  • 8/17/2019 3100-topic5 (1)

    18/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 1

    #$% verall Structure

    ♦ The re)ations for "o()esi. ###########: N@i r i=

    ii. contain ###############: i r 9  M

      iff i r  M or ∃   → i r  an(  r 9

      Miii. ########@########=:if i r 9  M → N @ M r 9 i=

    ♦   hierarchy re)ation "eans there are no ########## in the graph of the re)ation

    (irecte( acyc)ic graph @D4=

    vs. genera) graph @Oiger 5.1=

  • 8/17/2019 3100-topic5 (1)

    19/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 1F

    #$% verall Structure

    *eneral *raph Directed Acyclic *raph#DA*%/evel

     000 

     000 

     000 

     000 

     000 

    M1

    M2M3

    M4

    M1,1   M1,2   M1,3

    M1,2,1   M1,2,2

    M1,2,1,1

    M

    M   M

    M   M

    M

    1

    2   3

    4 5

    6

    a) b)

    'igure 1.$ *raph representation of a relation among modules2

    #a% *eneral graph2 #3% Direct acyclic graph #DA*%

  • 8/17/2019 3100-topic5 (1)

    20/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 'G

    /evels in a 4ierarchy "elation

     + PEQEPG: Ii R ¬ ∃  M ∈ S → i r  MJB ######################################################################################### 

     ######################################### 

     + PEQEP91

    : Ii R ∃

     M∈ PEQEP

     → 

    i r

     M an( ∀ 

    ∈ S, i r "⇒ " ∈ PEQEP", " ∈ G,H, J

    B ######################################################################################### 

     ############################# 

     + "o()e i is Bhigher )eve) than "o()e  M iff i ∈ PEQEPi and  M ∈ PEQEP M and i ? M

  • 8/17/2019 3100-topic5 (1)

    21/127

     © Chinese University, CSE Dept. Software Engineering / 5 - '1

    The 5SES "elation

     +Oor i,  M ∈ S, i USES  M iff correcte0ection of  M is necessary for i to *e

    correct

    i is a c)ient of  M n o*vios USES e0a"p)e is when i an( its

    correctness (epen( on a ca)) to a proce(re in"o()e  M 

     +: 2s  #################   e7iva)ent to ##################  re)ationV

  • 8/17/2019 3100-topic5 (1)

    22/127

     © Chinese University, CSE Dept. Software Engineering / 5 - ''

    5SES 6s 7ot E(uivalent to alls

    a= proce(re ca))s are not the on)y way for "o()esto interact @!ot a)) USES are ca))s=

    WE.g.1 in asse"*)y, a "o()e "ay "o(ify )oca)(ata or instrctions of another "o()e

    WE.g.' ####################### 

    ) 00000000000000000 'ortran) 0000000000000 

    *eneral) 0000000000+aria3les

    write read

  • 8/17/2019 3100-topic5 (1)

    23/127

     © Chinese University, CSE Dept. Software Engineering / 5 - '

    5SES 6s 7ot E(uivalent to alls

     + E.g. e0change of contro) infor"ation @#####= + E.g.6 in se7entia) environ"ent, "o()es "ay

    co""nicate via para"eter passing throghs*progra"s

     + E.g.5 in concrrent environ"ent, "o()es "ayco""nicate via "essages passing throgh tass

    *=!ot a)) ca))s are USES E.g. ca))ing for reporting e0ceptions

  • 8/17/2019 3100-topic5 (1)

    24/127

     © Chinese University, CSE Dept. Software Engineering / 5 - '6

    5SES "elation

    ♦USES re)ation is static, i.e., in(epen(ent of thee0ection of the s/w:

    in o()e :

    Bif con( then proc1 e)se proc'

      in 1  in ' 8 8 5SES

  • 8/17/2019 3100-topic5 (1)

    25/127

     © Chinese University, CSE Dept. Software Engineering / 5 - '5

    5SES "elation

    ♦ Oor a goo( (esign, USES re)ation sho)( *e hierarchyi. easy to n(erstan(

    W Bseparation of concerns >? se( co"ponents first, then theirc)ients

    ii. easy to i"p)e"ent

    W Bincre"enta)ity => otherwise, Bwe "ay en( p with a syste" inwhich nothing wors nti) everything wors.

    iii. easy to (efine strctreW B)eve)s of a*straction => high-)eve) "o()es @c)ients= first, then

    )ow-)eve) @se(= "o()es  #iii% ⇒ 00000000000000000 design

      #i%#ii% ⇒ 0000000000000000 implementation

  • 8/17/2019 3100-topic5 (1)

    26/127

     © Chinese University, CSE Dept. Software Engineering / 5 - '<

    4ow to Build 4ierarchy "elations!

    ♦ &ey: (ecop)ing "o()es to avoi( recrsion a"ong"o()es.

    1. recrsion within a "o()e (oes not affect there)ation a"ong "o()es

    '. consi(er an a)ternative a)gorith" which (oes notre7ire recrsion

    . if two "o()es have to USES each otherrecrsive)y, grop the" together into one )arge"o()e

  • 8/17/2019 3100-topic5 (1)

    27/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 'A

    4ow to Build 4ierarchy "elations!

    6. consi(er sp)itting one "o()e into two:, ,9

    ,

    ,9

  • 8/17/2019 3100-topic5 (1)

    28/127

     © Chinese University, CSE Dept. Software Engineering / 5 - '

    6S0,P7E7T0' "elation

    Pet S *e a set of "o()es 1,',H,nfor any i, M ∈ S, i 2S#C3!E!T#O  M "eans

    B M is rea)i8e( *y severa) "o()es, one of which *eing i

    ⇒  M C32SES i

    Pet s,i *e a s*set of S where

     

    s,i > I  R  ∈ S an(  2S#C3!E!T#O iJ

     

    then we say

    i 2S#C3SED#O s,i or s,i 23PEE!TS i 

  • 8/17/2019 3100-topic5 (1)

    29/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 'F

    : ,; is component of 00000 

    : 0000000 comprises ,;

    : 000000000000000 implements ,&

    : ,& is composed of 0000000000000000000 

    M1

    M   M

    M MM M M

    2   4

    5 67 8 9

    M3

    M MM M M

    5 67 8 9

    M2 M3 M4

    M1

    (IS_COMPONENT_OF)   (COMPRISES)

    'igure 1.& An e

  • 8/17/2019 3100-topic5 (1)

    30/127

     © Chinese University, CSE Dept. Software Engineering / 5 - G

     7otations for a Design

    ♦2n a (esign, once i is (eco"pose( into theset s,i, it is rep)ace( *y the" in the

    i"p)e"entationX i *eco"es "ere)y an

    a*straction for that i"p)e"entation

    ♦3hysica))y, the fina) i"p)e"entation on)ycontains the B)eaf "o()es in a C32SESre)ation graph

    P d ' ili " i i d

  • 8/17/2019 3100-topic5 (1)

    31/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 1

    Product 'amilies "evisited

    6s-composed-of 

    ,929,92&,92$

    ,9

    5ses

    ,;

    ,9

    ,1,=

    ,& ,>

    ,$

    5ses

    +ersion $

    Design

    Decision $

    Design

    Decision &

    +ersion &

    5ses

    ,$

     0000000 ,>

     0000000 0000000 

    ,&

    ,$

     0000000 ,>

     0000000   0000000 

    ,&

    D i / l +i i3ili

  • 8/17/2019 3100-topic5 (1)

    32/127

     © Chinese University, CSE Dept. Software Engineering / 5 - '

    Design /evel +isi3ility

    Data f)ow )eve)

    Strctre chart )eve)

    800000000000000?

    A * d D i 4i h

  • 8/17/2019 3100-topic5 (1)

    33/127

     © Chinese University, CSE Dept. Software Engineering / 5 -

    A *ood Design 4ierarchy

    1. 3artition the (esign: ########  vs ######## 

    '. there is "ore than one )eve)

    . there arent too "any )eve)s6. for each i ∈ S, the set of "o()es

    I M R i r  M J to which it USES is s"a))

    B)ow ######## + n"*er of otgoing e(ges of a"o()e

    @ e0a"p)e =

    A * d D i 4i h

  • 8/17/2019 3100-topic5 (1)

    34/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 6

    A *ood Design 4ierarchy

    5. for each i ∈ S, the set of "o()es @c)ients=I M R  M r iJ which USES i is )arge

    Bhigh ####### + n"*er of inco"ing e(ges of a"o()e

  • 8/17/2019 3100-topic5 (1)

    35/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 5

  • 8/17/2019 3100-topic5 (1)

    36/127

     © Chinese University, CSE Dept. Software Engineering / 5 - <

    6nterface2 6mplementation2 and

  • 8/17/2019 3100-topic5 (1)

    37/127

     © Chinese University, CSE Dept. Software Engineering / 5 - A

    2 p 2

    6nformation 4iding

    ♦ 2n the USES re)ation, the set of services that each"o()e provi(es to its c)ients is ca))e(

     ################ 

     + The services are e0porte( *y the se( "o()es an(

    i"porte( *y the c)ients♦ The interface is an ############# of the "o()e

    as viewe( *y its c)ients

    ♦  (esigner of "o()e on)y nee(s to now the

    interfaces of other "o()es se( *y , an( "ayignore their ################.

    6nterface2 6mplementation2 and

  • 8/17/2019 3100-topic5 (1)

    38/127

     © Chinese University, CSE Dept. Software Engineering / 5 -

    p

    6nformation 4iding

    ♦ 2nterface + ######################### 

     + ######################### 

     + ######################### 

    ♦ 2n s""ary, the c)ients of a "o()e now a*ot itsservices on)y throgh its interface, thei"p)e"entation is hi((en fro" the"

    ⇒ 2nfor"ation hi(ing, an i"portant concept forsoftware engineering princip)es

    4ow to Design 6nterfaces 'acilitating

  • 8/17/2019 3100-topic5 (1)

    39/127

     © Chinese University, CSE Dept. Software Engineering / 5 - F

    g g

    6nformation 4iding!

    ♦The interfaces sho)( *e as si"p)e aspossi*)e, *t not si"p)er 

    ♦ i(entify changea*)e (esign (ecisions an(nchangea*)e "o()e infor"ation

    i. nchangea*)e infor"ation⇒ ################ @sta*)e=

    ii. changea*)e (esign (ecisions⇒

    Bsecret @hi((en in the ################ 

    =Le say sch infor"ation is ################ withinthe "o()e i"p)e"entation.

    Typical Secrets

  • 8/17/2019 3100-topic5 (1)

    40/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 6G

    Typical Secrets

    1. The a)gorith" for carrying ot so"e operation, e.g.a)gorith"s for sorting rotine

    '. The representation of so"e (ata strctre, e.g.a*stract (ata type

     + C)ients now how to operate it, *t (o not now how it

    is i"p)e"ente(. The (etai)s of an interface to the a*stract "achine

    n(er)ying the s/w

    6. The po)icy for a))ocating so"e resorce or or(ering

    certain operations @e.g., 32!T a sorte( )ist=5.  *stract (ata type

    A3stract Data Type

  • 8/17/2019 3100-topic5 (1)

    41/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 61

    A3stract Data Type

    ♦ *stract (ata type is an infor"ation hi(ing"o()e where the representations of (atastrctres are encaps)ate(.

     + e.g. Bstac co)( *e (efine( in on)y for operationsin its interface:  #####,####,####, init

    A 7ote A3out Architectural Design

  • 8/17/2019 3100-topic5 (1)

    42/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 6'

    A 7ote A3out Architectural Design

    ♦  precise (efinition of the interface isnecessary for "o()e @re=sa*i)ity

     + %igh #########X %igh ########## 

    ♦The interface "st contain a)) the infor"ationthat is nee(e( to characteri8e the "o()es*ehavior, an( nothing "ore

     + Pow ########## 

    Procedures for Architectural Design

  • 8/17/2019 3100-topic5 (1)

    43/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 6

    Procedures for Architectural Design

    1. pp)y USES an( 2S#C3!E!T#O!otations

    '. ;i)( hierarchy re)ations @avoi( recrsion=

    . 2(entify "o()es with high cohesion an( )ow

    cop)ing6. Design interface

    5. %i(e infor"ation

  • 8/17/2019 3100-topic5 (1)

    44/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 66

    #&% Detailed Design

    ♦s/w (esign notations + for"a) in synta0

     + infor"a) in se"antics

    1. TD! @Te0ta) Design !otation=

    '. 4D! @4raphica) Design !otation=

    TD7) Te

  • 8/17/2019 3100-topic5 (1)

    45/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 65

    TD7) Te

  • 8/17/2019 3100-topic5 (1)

    46/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 6<

    'igure 1.9 A Sample ,odule Description

    module Z

    uses Y, [export 

    var  : integerX

    type ;: array @1..1G= of  rea)X

    procedure C@D: in out ;X E in integerX O: in rea)=

     ______________________________ 

    Implementation

       ______________________________ 

    is co"pose( of , T

    end Z

    'igure 1 9 A Sample ,odule Description

  • 8/17/2019 3100-topic5 (1)

    47/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 6A

    module Z

    uses Y, [export 

    var  : integerX

    type ;: array @1..1G= of  rea)X

    procedure C@D: in out ;X E in integerX O: in rea)=

    Here is an optional natural language description of what A, B and C actuallyare, along with possible constraints or properties that clients need to know; forexample we might specify that objects of type B sent to procedure C should beinitialized by the client, and should neer contain all zeros!

    Implementation

      "f needed, here are general comments about the rationale of themodularization, hints on the implementation, etc!

    is co"pose( of , T

    end Z

    'igure 1.9 A Sample ,odule Description

    'igure 1 > Sample omponents of ,odule @

  • 8/17/2019 3100-topic5 (1)

    48/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 6

    'igure 1.> Sample omponents of ,odule @

    module 

    uses Y

    export 

    var  &: record H endX

    type ;: array @1..1G= of  rea)X

    procedure C@D: in out ;X E in integerX O: in rea)=

    Implementation

      H

    end 

    module T

    uses Y, [,

    exports var  : integerXimplementation

    H

    end T

    'igure 1.1 An E

  • 8/17/2019 3100-topic5 (1)

    49/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 6F

    Selective 6mport

    module L

    uses Z imports@;,C=,

    ZZ

    exports H

    implementation

    .

    .

    .

    end L

    @ e

  • 8/17/2019 3100-topic5 (1)

    50/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 5G

    TD7

    ♦  TD! (esign taes so"e ti"e toco"prehen(

    ♦TD! can provi(e varios )eve)s of (etai)s

     + e.g., ############## in great (etai)

    ♦The (esigner nee(s to chec for consistencyan( co"p)eteness

    ♦The te(ios checing proce(re sho)( *e

    ato"ate( if possi*)e♦  "ore co"p)icate( e0a"p)e fo))ows.

    *D7 #*raphical Design 7otation%

  • 8/17/2019 3100-topic5 (1)

    51/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 51

    # p g %

    ♦a *o0 represents a ###########♦ inco"ing arrows represent a "o()es

     ##########, i.e., e0porte( ###########

    ♦not to *e confse( with DOD

    ♦can a)so show B2S#C3SED#O an(B2S#C3!E!T#O re)ations

    'igure 1.= *D7 of ,odule @

  • 8/17/2019 3100-topic5 (1)

    52/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 5'

    Oigre 5.< 4raphica) (escription of "o()e Z of Oigre 5.

    gu e . * o odu e

     

    X

    Y

    Z

    A B

    R  TModuleModule

    Module

    Module

    Module

    'igure 1.; @s Decomposition

  • 8/17/2019 3100-topic5 (1)

    53/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 5

    g p

    Oigre 5.A o()e Z is co"pose( of "o()es an( T

     

    X

    Y

    ZBC

     

    R  TModuleModule

    Module

    Module

    Module

    A

    K

  • 8/17/2019 3100-topic5 (1)

    54/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 56

    o()e

    o()e P o()e !

    o()e

    o()e

    o()e

    o()e S

    o()e % o()e 4

    Oigre 5. o()e is a "e"*er of *oth P an( !

    A

    B

    Module M 

    IS_COMPONENT_OF what?

     _________________ 

      IS_COMPOSED_OF what?

     _________________ 

      Exports what?

     _________________ 

      USES what?

     _______ (which exports _______ o()e O

    *D7 #*raphical Design 7otation%

  • 8/17/2019 3100-topic5 (1)

    55/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 55

    # p g %

    ♦2t provi(es Bs/w (esign visa)i8ation

    ♦2t is sef) in co"prehen(ing co"p)icate( s/[email protected]., concrrent s/w=

    ♦2t "ay tae too "ch space

    ♦2t is sef) for high-)eve) view of the s/w (esign

    ♦Detai)e( )eve)s nee( to *e ato"ate( @CSE=

     + E.g., State"ate, ationa), UP

    ategories of ,odules

  • 8/17/2019 3100-topic5 (1)

    56/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 5<

    g

    1= 3roce(ra) a*stractions + prpose: to encaps)ate an ############  + e.g.: sorting "o()e, fast Oorier transfor"

    "o()e

    '= Pi*raries + prpose: to grop together re)ate(

     ########################### 

     + e.g.: "athe"atica) rotines

    graphica) rotines

    ategories of ,odules

  • 8/17/2019 3100-topic5 (1)

    57/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 5A

    g

    = Co""on poo) of (ata + prpose: to share ####### a"ong severa)"o()es

     + e.g.: syste" configration constants grop

     + note:

    ategories of ,odules

  • 8/17/2019 3100-topic5 (1)

    58/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 5

    6= *stract o*Mects + prpose: to hi(e the (etai)s of (ata ##########@change of (ata strctres is ######### of cost fortota) software "aintenance=

     + e.g.: a sy"*o)-ta*)e + note: e0hi*it a state

    ategories of ,odules

  • 8/17/2019 3100-topic5 (1)

    59/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 5F

    5= *stract (ata type + prpose: to hi(e the ########### of a (ata typean( the a)gorith"s se( in ######## the o*Mects ofthat type

     + e.g.:

    Stac  (a - private type

    o()e-' - opa7e type

     + note:

    i= no stateii= can generate "any instances @ ########### =

    Stac as an A3stract Data Type

  • 8/17/2019 3100-topic5 (1)

    60/127

     © Chinese University, CSE Dept. Software Engineering / 5 -

  • 8/17/2019 3100-topic5 (1)

    61/127

     © Chinese University, CSE Dept. Software Engineering / 5 -

  • 8/17/2019 3100-topic5 (1)

    62/127

     © Chinese University, CSE Dept. Software Engineering / 5 -

  • 8/17/2019 3100-topic5 (1)

    63/127

     © Chinese University, CSE Dept. Software Engineering / 5 -

  • 8/17/2019 3100-topic5 (1)

    64/127

     © Chinese University, CSE Dept. Software Engineering / 5 -

  • 8/17/2019 3100-topic5 (1)

    65/127

     © Chinese University, CSE Dept. Software Engineering / 5 -

  • 8/17/2019 3100-topic5 (1)

    66/127

     © Chinese University, CSE Dept. Software Engineering / 5 -

  • 8/17/2019 3100-topic5 (1)

    67/127

     © Chinese University, CSE Dept. Software Engineering / 5 -

  • 8/17/2019 3100-topic5 (1)

    68/127

     © Chinese University, CSE Dept. Software Engineering / 5 - i loop

    if  a(i) > a(j) then

    interchange the elements at positions j and i ;end if ; j := j 1;

    end loop;

    i := i + 1;end loop;

    Step !

  • 8/17/2019 3100-topic5 (1)

    69/127

     © Chinese University, CSE Dept. Software Engineering / 5 - i loop

    if  a(i) > a(j) then" := a(i);a(i) := a(j);a(j) := ";

    end if ;

     j := j 1;end loop;i := i + 1;

    end loop;

    Stepwise "efinement

  • 8/17/2019 3100-topic5 (1)

    70/127

     © Chinese University, CSE Dept. Software Engineering / 5 - AG

    3'

    3

    31 3 5

    3 ',1

    3',1,1

    3',1,'

    C

    C1

    not C1

    Oigre 6.15 4raphica) representation of stepwise refine"ent.

    FWhile loop P&2$G

    G

    F 6f $ then P&2$2$

    Else P&2$2&G

    Step H

    Step $

    Step &

    Step 7

    Stepwise "efinement

  • 8/17/2019 3100-topic5 (1)

    71/127

     © Chinese University, CSE Dept. Software Engineering / 5 - A1

    2t is a "etho( that wors in the s"a)), *t fai)sin the )arge. %ere are the reasons:

    1. s*-pro*)e"s ten( to *e ana)y8e( in iso)ation,re(cing ############## 

    '. !o attention is pai( to ############### . !o attention is pai( to ############### 

    6. The ######## fnction "ay not e0ist

    5. pre"atre co""it"ent to the ############

    strctres

    A Short Summary A3out Design

  • 8/17/2019 3100-topic5 (1)

    72/127

     © Chinese University, CSE Dept. Software Engineering / 5 - A'

    ♦ stepwise refine"ent + top-(own (esign

    ♦ infor"ation hi(ing + *otto"-p (esign

    ♦ co"*ining *oth + yo-yo (esign

    1. (esign sho)( se *oth sche"es

    '. (escription of the res)ting (esign sho)( *e ##############

    4andling Anomalies

  • 8/17/2019 3100-topic5 (1)

    73/127

     © Chinese University, CSE Dept. Software Engineering / 5 - A

    ♦To achieve re)ia*)e so)tions

     + Syste"atic (esign approach

     + igoros an( (iscip)ine( i"p)e"entation

    ♦ne so)tion: e"p)oy ########## (esign

     + 3rpose: *i)( ro*st syste"s

     + The progra" sho)( contine to *ehavereasona*)y even in the case of ne0pecte( an(nforeseen circ"stances

    4andling Anomalies

  • 8/17/2019 3100-topic5 (1)

    74/127

     © Chinese University, CSE Dept. Software Engineering / 5 - A6

    ♦ no"a)os + if a "o()e fai)s to provi(e aservice as e0pecte( an( specifie( in itsinterface

     + ######### + to *e associate( with a service,

    (enoting the ano"a)ies that "ay occr whi)e thatservice is *eing perfor"e(

    4andling Anomalies

  • 8/17/2019 3100-topic5 (1)

    75/127

     © Chinese University, CSE Dept. Software Engineering / 5 - A5

    ♦Defensive (esign re7ires that pon enteringan ano"a)os state, the "o()e sho)( signa)the ano"a)y *y raising an e0ception to thec)ient

    ♦The server "o()e ter"inates the serviceafter ######### an e0ceptionX the c)ientrespon(s *y sita*)y ######## the e0ception

    Why an E

  • 8/17/2019 3100-topic5 (1)

    76/127

     © Chinese University, CSE Dept. Software Engineering / 5 - A<

    1. s c)ient (oes not satisfy the re7ire(protoco) for invoing one of s service

    '. Lhen provi(ing a service to its c)ient, (oes not invoe a service e0porte( *y

    another "o()e proper)y. fai)s to provi(e its service *ecase of an

    nforeseen con(ition

    ,s client,s client

    A

  • 8/17/2019 3100-topic5 (1)

    77/127

     © Chinese University, CSE Dept. Software Engineering / 5 - AA

    ,s server 

    ,

     00 

     00 

     00 

    ,s server 

    B

    B

     000000 an

    e

  • 8/17/2019 3100-topic5 (1)

    78/127

     © Chinese University, CSE Dept. Software Engineering / 5 - A

    module  /exports  . . .

    procedure  3 @Z: 2!TE4EX . . .=

    raises  Z#!!#!E4T2QE#EZ3ECTED,2!TE4E#QEOPLX

     $ is to be positie; if not, exception $%&'&%&()A#"*(%($+(C#( is raised;"()(-%'*(-./'0 is raised if internal computation of + generates an oerflow 

    .

    .

    .

    end  /

    ,odule /

  • 8/17/2019 3100-topic5 (1)

    79/127

     © Chinese University, CSE Dept. Software Engineering / 5 - AF

      module  P uses  / imports  3 @Z: 2!TE4EX . .=exports  . . .X 

    procedure  @ . . .= 

    raises  2!TE4E#QEOPLX . . . 

    implementation "f "()(-%'*(-./'0 is raised when + is inoked, the  exception is propagated  . . . 

    end  P 

    oncurrent Software

  • 8/17/2019 3100-topic5 (1)

    80/127

     © Chinese University, CSE Dept. Software Engineering / 5 - G

    ♦The case of a "o()e (efining share( (ata

    ♦ E.g., a*stract o*Mect ;UOOE + "o()e UEUE#O#C% is 4E!E2C#O2O#UEUE

    @C%=

     + ;UOOE : UEUE#O#C%.UEUE

    with operations + 3UT: inserts a character in ;UOOE

     + 4ET: e0tracts a character fro" ;UOOE

     + !T#OUPP: retrns tre if ;UOOE not f))

     + !T#E3TY: retrns tre if ;UOOE not e"pty

    4ow to ontrol orrect Access toShared Data!

  • 8/17/2019 3100-topic5 (1)

    81/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 1

    !ot sfficient that c)ients chec operationinvocations, sch asif UEUE#O#C%.!T#OUPP @;UOOE= then

    UEUE#O#C%.3UT @Z, ;UOOE=X

    en( ifX

    ♦Cons"er#1 an( Cons"er#' "ight (o thisconcrrent)y

    if on)y one s)ot is )eft, *oth "ay fin( the *ffer not f)),

    the first who writes fi))s it, an( the other writes in a f))*ffer 

    Enforcing Synchroniation

  • 8/17/2019 3100-topic5 (1)

    82/127

     © Chinese University, CSE Dept. Software Engineering / 5 - '

    ♦Ensre that operations on *ffer are e0ecte(in mutual exclusion

    ♦Ensre that operations sch asif UEUE#O#C%.!T#OUPP @;UOOE= then

    UEUE#O#C%.3UT @Z, ;UOOE=Xen( ifX

    are e0ecte( as )ogica))y non-interrpti*)enits

    ,onitors

  • 8/17/2019 3100-topic5 (1)

    83/127

     © Chinese University, CSE Dept. Software Engineering / 5 -

    ♦ *stract o*Mects se( in a ############environ"ent

    ♦ vai)a*)e in the ]ava progra""ing )angage

    ,onitors) an E

  • 8/17/2019 3100-topic5 (1)

    84/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 6

      concurrent module C%#;UOOE

     #his is a monitor, i!e!, an abstract object module in a concurrent enironment  

    uses  . . . exports 

    procedure  3UT @C : in  C%= reuires  !T#OUPPX 

    procedure  4ET @C: out  C%= reuires !T#E/3TYX &'#%(1+#2 and &'#%.3// are hidden Boolean  functions yielding #-3( if the buffer is not empty and not  full, respectiely! #hey are not exported as operations, because their purpose is only to delay the calls to +3# and  )(# if they are issued when the buffer is in a state where it  cannot accept them . . . 

    end  C%#;UOOE 

    omments on ,onitors

  • 8/17/2019 3100-topic5 (1)

    85/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 5

    ♦onitor operations are ass"e( to *ee0ecte( in ################# 

    ♦  requires c)ase "ay *e associate( with anoperation

     + it is ato"atica))y chece( when operation isca))e(

     + if the res)t is fa)se, the crrent process issspen(e( nti) it *eco"es tre @at that stage it*eco"es e)igi*)e for res"ption=

    ,onitor Types) an E

  • 8/17/2019 3100-topic5 (1)

    86/127

     © Chinese University, CSE Dept. Software Engineering / 5 - <

    !eneric concurrent module 4E!E2C#O2O#UEUE @EP= #his is a generic monitor type, i!e!, an abstract data type accessed in a concurrent enironment  

    uses  . . . exports 

    type  UEUE: VX procedure  3UT @1: in out UEUEX E1: in  EP= 

    reuires  !T#OUPP @1: UEUE=X procedure  4ET @': in out UEUEX E': out  EP= 

    reuires  !T#E/3TY@': UEUE=X . . .

     end  4E!E2C#O2O#UEUE @EP= 

    *uardians and "ende-vous

  • 8/17/2019 3100-topic5 (1)

    87/127

     © Chinese University, CSE Dept. Software Engineering / 5 - A

    ♦The (a sty)e of (esigning concrrentsyste"s

    ♦ 2n (a a share( o*Mect is ###########@whereas a "onitor is ############=

     + it is "anage( *y a guardian process which canaccept ren(e8-vos re7ests fro" tass wi))ing toaccess the o*Mect

    A *uardian Tas 

    f

  • 8/17/2019 3100-topic5 (1)

    88/127

     © Chinese University, CSE Dept. Software Engineering / 5 -

    loopselect

    when NOT_FULLaccept PUT (C:in CHAR);This is the body of PUT; the client calls it as if itwere a normal procedure

    end;orwhen NOT_EMPTYaccept GET (C:out CHAR);This is the body of GET; the client calls it as if itwere a normal procedure

    end;end select;

    end loop;

    note _______________ a##eptan#e of 

    rende$%o&s re'&ests

    A 'urther "elation) 6nheritance#*eneraliation I Specialiation%

  • 8/17/2019 3100-topic5 (1)

    89/127

     © Chinese University, CSE Dept. Software Engineering / 5 - F

    ♦ The eywor( in @pre= o*Mect-oriente( (esign:

    Binheritance - to for" a c)ass of o*Mects. + e.g., Bc)ass in C99 @p*)ic, private, protecte(=

     + e.g., Be0ten(s in ]ava creates Bs*c)asses

    ♦ DTs "ay *e organi8e( in a hierarchy

    ♦ C)ass ; "ay specia)i8e c)ass  + ; inherits fro"

    converse)y, genera)i8es ;

    ♦  is a sperc)ass of ;

    ♦ ; is a s*c)ass of

    Cey oncept in - Design) 6nheritance

  • 8/17/2019 3100-topic5 (1)

    90/127

     © Chinese University, CSE Dept. Software Engineering / 5 - FG

    ♦   new re)ation: 2!%E2TS#O

    ♦ 2f 1 2!%E2TS#O ', then 1 has visi*i)ity into

    the interna) strctre @the #######= of ' 

    a hierarchy re)ation

    1. ##################### '. ##################### 

    . ##################### 

    1 2!%E2TS#O ' 

     + ': parent "o()e + 1: heir "o()e

    An 6nheritance E

  • 8/17/2019 3100-topic5 (1)

    91/127

     © Chinese University, CSE Dept. Software Engineering / 5 - F1

    'igure 1.J An E

  • 8/17/2019 3100-topic5 (1)

    92/127

     © Chinese University, CSE Dept. Software Engineering / 5 - F'

    'igure 1.J An E

  • 8/17/2019 3100-topic5 (1)

    93/127

     © Chinese University, CSE Dept. Software Engineering / 5 - F

    o()e E3PYEE

    o()e

     D2!STT2QE

    STOO

    o()e

    TEC%!2CP

    STOO

    4ET#S&2PPDEO#S&2PP

    D#T%2S

    !E 4E

    L%EEo()e S2TE

    ... to "o()es !EY

    e

  • 8/17/2019 3100-topic5 (1)

    94/127

     © Chinese University, CSE Dept. Software Engineering / 5 - F6

    ♦ 2nheritance a))ows a hierarchica) c)assification

    sche"e for a*stract (ata types throghgenera)i8ation-specia)i8ation re)ations

     + (istingish co""ona)ities an( (ifferences a"onga @potentia)= set of a*stract o*Mects

     + co""ona)ities are factore( ot in a ########c)ass

     + variations are sing)e( ot in the ###########

    c)asses

    Properties of 6nheritance

  • 8/17/2019 3100-topic5 (1)

    95/127

     © Chinese University, CSE Dept. Software Engineering / 5 - F5

    ♦2nheritance i"proves resa*i)ity - ########

    c)ass

    ♦2nheritance is a way of *i)(ing software ##############

    ♦Disa(vantage of inheritance

    Properties of 6nheritance

    ♦ s*c)ass (efines a s*type

  • 8/17/2019 3100-topic5 (1)

    96/127

     © Chinese University, CSE Dept. Software Engineering / 5 - F<

    ♦  s*c)ass (efines a s*type

     + s*type is substitutable for parent type

    ♦3o)y"orphis"

     + a varia*)e referring to type can refer to an o*Mect oftype ; if ; is a s*c)ass of

    ♦Dyna"ic *in(ing

     + the "etho( invoe( throgh a reference (epen(s onthe type of the o*Mect associate( with the reference

    at rnti"e

    Several #ontroversial% E

  • 8/17/2019 3100-topic5 (1)

    97/127

     © Chinese University, CSE Dept. Software Engineering / 5 - FA

    ♦ e(efinition: an heir pro(ct provi(es a (ifferent

    i"p)e"entation for one of its parents services + e.g., change of the sorting a)gorith" regar(ing its i"p)e"entation

    @no change to interface=

     +  ####### an( ######### a))ow itX ######## (oes not

    ♦ e(efinition app)ie( to the (ata strctre hi((en in theparent "o()e

    ♦ )tip)e inheritance: (efine a new "o()e *y co"*ining thefeatre provi(e( *y two or "ore parent "o()es

     + e.g., O2O#UEUE, E3PYEE

     +  ######## a))ows it, *t ######### an( ######### (o not

    5sing 5,/ in Software Design

  • 8/17/2019 3100-topic5 (1)

    98/127

     © Chinese University, CSE Dept. Software Engineering / 5 - F

    ♦UP @Unifie( o(e)ing Pangage= notation is

    pop)ar in software engineering.♦UP is a co))ection of )angages that provi(e

    specific notations to specify, ana)y8e, visa)i8e,constrct, an( ######## software.

    ♦UP is a wi(e)y a(opte( stan(ar( notation forrepresenting (esigns

    ♦Le intro(ce the UP c)ass (iagra"

     + c)asses are (escri*e( *y *o0es

    5,/ "epresentation of 6nheritance

  • 8/17/2019 3100-topic5 (1)

    99/127

     © Chinese University, CSE Dept. Software Engineering / 5 - FF

     E,P/EE

    TE476A/0STA''AD,676ST"AT6+E0STA''

     7ote) similar to 0000000000 

    5,/ Associations

    ♦ssociations are re)ations that the

  • 8/17/2019 3100-topic5 (1)

    100/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 1GG

    ♦ ssociations are re)ations that the

    i"p)e"entation is re7ire( to spport♦Can have ")tip)icity constraints

      TE476A/  

     0STA''  

    ,A7A*E"  

    P"KET  L  $ 

     proMect0mem3er   

    $..L  

    manages  

    5,/ Aggregation

    D fi 3T O ) ti

  • 8/17/2019 3100-topic5 (1)

    101/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 1G1

    ♦Defines a 3T#O re)ation

    Differs fro" 2S#C3SED#O

    %ere T!4PE has its own "etho(s

    2t i"p)icit)y ses 32!T to (efine

    its (ata attri*tes

     

    T"6A7*/E

    P67T

    $

    9

    ,ore on 5,/

    ♦ UP evo)ves fro" TD!/4D!

  • 8/17/2019 3100-topic5 (1)

    102/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 1G'

    ♦ UP evo)ves fro" TD!/4D!♦

    USES re)ationship is refine( with se"antica))y richer re)ationship: inheritance,association, an( aggregation + 2f c)ass ; inherits fro" c)ass , ; USES >? ########### USES #########  +  ssociation *etween c)asses i"p)icit)y (efine USES re)ation >? ########### USES

     ############  + 2f ; aggregates , ; USES >? ########## USES ########## 

    ♦ epresentation of 2S#C3!E!T#O via the package notation 

     pacDage0name

    lass $

    lass &

    lass 9

    Software Architecture

    ♦D i* )) t i ti (

  • 8/17/2019 3100-topic5 (1)

    103/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 1G

    ♦Descri*es overa)) syste" organi8ation an(

    strctre in ter"s of its "aMor constitents an(their interactions

    ♦Stan(ar( architectres can *e i(entifie(

     + pipe)ine + *)ac*oar(

     + event *ase( @p*)ish-s*scri*e=

    Standard Architectures

  • 8/17/2019 3100-topic5 (1)

    104/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 1G6

     

    ipeline"a*ple: _________________ 

    e%ent based"a*ple: _______________ 

     _______________________  

    la#,board"a*ple: ____________ -

     _________________ 

    Domain Specific Architectures

  • 8/17/2019 3100-topic5 (1)

    105/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 1G5

    .*odel/%ie0/#ontroller. ar#hite#t&re for soft0arethat has a signi#ant a*o&nt of &ser intera#tion

    ,odel #store 

    data2 e.g.2 te

  • 8/17/2019 3100-topic5 (1)

    106/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 1G<

    ♦Oro" two tiere( + C)ient-server 

    ♦ to three tiere(

     

    "e(uests

    for service

    #data3ase%

    Web browser

    (client)

    Web server

    #server%"e(uests

    for service

    #pages%

    User interface

    (client)

    Decode

    service

    request

    #&nd tier%

    Application

    server

    #data3se%

    Program 6mplementation Techni(ues

    1 3rogra""ing Stan(ar(s an( 3roce(res

  • 8/17/2019 3100-topic5 (1)

    107/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 1GA

    1. 3rogra""ing Stan(ar(s an( 3roce(res

    ♦ !ee( for stan(ar(s an( proce(res  nifor"e( goo( progra""ing sty)e he)psn(erstan(a*i)ity, consistency, correctness of a tea"proMect.

    a= Stan(ar(s for Yo

    Stan(ar(s an( proce(res he)p yo ############ yorthoghts an( avoi( "istaesX they a)so he)p in

     ############ (esign to co(e

    *= Stan(ar(s for thers

    2t is essentia) yo organi8e, for"at, an( (oc"ent yor

    co(e to "ae it easy for others to n(erstan( what it(oes an( how it wors.

    Program 6mplementation Techni(ues

    t hi ith

    3333333333333333333333333333333333333333

    3 5678 95 6 9S95 5 9?5 8S

  • 8/17/2019 3100-topic5 (1)

    108/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 1G

    ♦ atching ####### with ############### 

     + Direct correspon(ence*etween the progra"(esign "o()es an( the

    progra" co(e "o()es + &eep p with the goo(

    (esign for tracea*i)ity an("aintaina*i)ity

     + Use hea(er fi)e to trace"o()e (esign

     

    * MODULE NAME: FINDPT3 5AB: C7B D

    3 ES5: 1FG (! BC 1H)

    3

    3 567 E5B95:

    3 B88 69 (B1- 1- 1- B2- 2- 2- IS- DS- 8BA)

    3

    3 79 BB9S:3 79 8S B 5 9C 5

    3 B13I + 13D + 1 = G B6

    3 B23I + 23D + 2 = G

    3 S5 79 S 59S B1- 1- 1 B6

    3 B2- 2- 2

    3

    3 57979 BB9S:

    3 8S B BB888- 8BA S9 95 1F

    3 8S 8BA = G B6 59 5 9B95

    3 S (IS- DS)F

    33333333333333333333333333333333333333333

    Program 6mplementation Techni(ues

    ' 3rogra""ing 4i(e)ines

  • 8/17/2019 3100-topic5 (1)

    109/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 1GF

    '. 3rogra""ing 4i(e)ines

     + Contro) strctres

     +  )gorith"s

     + Data strctres

     + 4enera) gi(e)ines

    ontrol Structures

    ♦Using On(a"enta) Constrcts

  • 8/17/2019 3100-topic5 (1)

    110/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 11G

    ♦Using On(a"enta) Constrcts

    ain ingre(ients for strctre( progra"s:

    ".  ______________e.!.#___________________ 

    $.  ______________e.!.#___________________ 

    %.  ______________e.!.#___________________ 

     ########   ######## 

    ontrol Structures

  • 8/17/2019 3100-topic5 (1)

    111/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 111

     ########## 

    ontrol Structures

  • 8/17/2019 3100-topic5 (1)

    112/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 11'

     000000000000   000000000000 

    ontrol Structures

    ♦Top-(own O)ow

  • 8/17/2019 3100-topic5 (1)

    113/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 11

    ♦Top (own O)ow

    3rogra"s sho)( *e rea(a*)e fro" the top (own

    ♦Use of S*"o()es

     + Oo))ow the (esign to *i)( s*"o()es @fnctions,

    proce(res, "acros= for e)e"enta) fnctions + ;i)( genera) s*"o()es for ############ 

     + E0p)ain ######### of s*"o()es, *t not their(etai)s

    Program Without Top-Down 'low

    9 = 7

  • 8/17/2019 3100-topic5 (1)

    114/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 116

    9 7

    (BA < JH) A5 95 B;9 = BI7;

    A5 95 ;

    (BA < KH) A5 95 ;

    (BA < HH) A5 95 ;B: (BA < KH) A5 95 ;

    9 = 9 3 1FH + 57S;

    A5 95 ;

    : (BA < HH) A5 95 ;

    9 = 9 3 1FH;

    :e"t state*ent 

    Program With Top-Down 'low

  • 8/17/2019 3100-topic5 (1)

    115/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 115

    (BA < HH) 9C 9 = 7;8S (BA < KH) 9C 9 = 7 + 57S;

    8S (BA < JH) 9C 9 = 7 3 1FH +57S;

    8S 9 = BI7; 

    Algorithms

    ♦3rogra" (esign often specifies a c)ass of

  • 8/17/2019 3100-topic5 (1)

    116/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 11<

    g g p

    a)gorith"s to *e se(♦Efficiency of co(e sho)( consi(er

    1. ############ of co(e

    '. ti"e to ###### the co(e. ti"e to ###### the co(e

    6. ti"e for sers to ########### the co(e

    5. ti"e to ###### the co(e, if necessary

    Data Structures

    ♦&eeping the 3rogra" Si"p)e. estrctring (ata

  • 8/17/2019 3100-topic5 (1)

    117/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 11A

    p g g p g

    can si"p)ify a progra". + &eep 2t Si"p)e an( Straightforwar(: ######### 

    ♦Using the Strctre of Data to Deter"ine the

    Strctre of the 3rogra"♦Poca)i8ing 2npt an( tpt in Separate o()es

    *eneral *uidelines

    ♦Using 3se(oco(e

  • 8/17/2019 3100-topic5 (1)

    118/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 11

    g

    ♦evising an( ewriting 2nstea( of 3atching

    E

  • 8/17/2019 3100-topic5 (1)

    119/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 11F

    p g y

    1. Oor the first ^1G,GGG of inco"e, the ta0 is 1G.'. Oor the ne0t ^1G,GGG a*ove ^1G,GGG, the ta0 is

    1'.

    . Oor the ne0t ^1G,GGG a*ove ^'G,GGG, the ta0 is

    15.6. Oor the ne0t ^1G,GGG a*ove ^G,GGG, the ta0 is

    1.

    5. Oor any inco"e a*ove ^6G,GGG, the ta0 is 'G.

    Program $

     9BI = GF

    9BIB8 5 = G- A5 95 I9

  • 8/17/2019 3100-topic5 (1)

    120/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 1'G

    9BIB8_5 G- A5 95 I9

    9BIB8_5 > 1G-GGG- 9BI = 9BI + 1GGGF8S 9BI = 9BI + GF1G 3 9BIB8_5

    A5 95 I9

    9BIB8_5 > 2G-GGG- 9BI = 9BI + 12GGF

    8S 9BI = 9BI + GF123(9BIB8_5 / 1GGGGF)

    A5 95 I9

    9BIB8_5 > !G-GGG- 9BI = 9BI + 1HGGF

    8S 9BI = 9BI + GF1H3(9BIB8_5 / 2GGGGF)

    A5 95 I9

    9BIB8_5 < 4G-GGG- 9BI = 9BI + GF1L3(9BIB8_5 / !GGGGF)

    A5 95 I9

    8S 9BI=9BI+1LGGF+GF2G3(9BIB8_5/4GGGGF)

    I9: 6

    Program &

    &uild a 'ample (ax (a)le *irst:

    &rac+et &ase ,ercent

    G G 1G

  • 8/17/2019 3100-topic5 (1)

    121/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 1'1

    G G 1G

    1G,GGG 1GGG 1'

    'G,GGG ''GG 15

    G,GGG AGG 1

    6G,GGG 55GG 'G

     

    (he ,ro!ram:

    8E8 = 1

    5 = 1 95 4 65

    ______________________________ 

      9C ___________________________ 

     

     9BI = ______________________________________________________ 

    Program 6mplementation Techni(ues

    . Doc"entation

  • 8/17/2019 3100-topic5 (1)

    122/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 1''

    ♦ 2nterna) Doc"entation @(oc"entationassociate( with the progra" co(e=

     + %ea(er Co""ent ;)oc

     + ther 3rogra" Co""ents

     + eaningf) Qaria*)e !a"es an( State"ent Pa*e)s

    4eader omment Bloc

    ♦Specify < Ls

  • 8/17/2019 3100-topic5 (1)

    123/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 1'

    1. ###### yor progra" is

    '. ###### wrote the progra"

    . ###### the progra" fits in the genera) syste"(esign

    6. ###### the progra" was written an( revise(

    5. ###### the progra" e0ists

  • 8/17/2019 3100-topic5 (1)

    124/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 1'6

    5AB: ?an- 8ai*an !M4! L4L1B88A SN7: B88 SB(8A9C-CB)

    ?here O8A9CP is the length of the line to be s#anned- OCBP isthe #hara#ter to be so&ght- line of te"t passed as array O9I9P

    ES5 1: 0ritten 222G1K

    ES5 1F1: !!2G1K to i*pro%e sear#hing algorith*F

    75S: Aeneralp&rpose s#anning *od&le to be &sed for ea#hne0 line of te"t- no *atter the lengthF

    6B9B S9797S: Eariable 8A9C / 9A

    Eariable CB / CBB9

    BBD 9I9 / CBB9 array of length O8A9CP

    B8A59C: eads array 9I9 one #hara#ter at a ti*e;

    if CB is fo&nd- position in 9I9 ret&rned in %ariable O8A9CP;else %ariable O8A9CP set to G 

     000000 

     000000 

     000000 

     000000 

    Program 6mplementation Techni(ues

     + Oor"atting to Enhance Un(erstan(ing

  • 8/17/2019 3100-topic5 (1)

    125/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 1'5

     #################################  ################################# 

     + Doc"enting Data

     ################################# 

    Program 6mplementation Techni(ues

    ♦E0terna) Doc"entation

  • 8/17/2019 3100-topic5 (1)

    126/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 1'<

     + Descri*ing ################# @what= + Descri*ing ################# @how=

     + Descri*ing ################# @how=

    Topic 1 onclusion

    ♦ Software (esign activities an( "o()ari8ation techni7es

  • 8/17/2019 3100-topic5 (1)

    127/127

     © Chinese University, CSE Dept. Software Engineering / 5 - 1'A

    vera)) strctre (esign + %ierarchica) re)ations, ses re)ation, is#co"ponent#of re)ation + 2nterface an( infor"ation hi(ing

    ♦ Detai)e( (esign + TD!, 4D!

     + Category of "o()es + Stepwise refine"ent

    ♦ %an()ing ano"a)ies

    ♦ 2nheritance

    ♦ UP in software (esign♦ 3rogra" i"p)e"entation techni7es