768
Бертран Мейер Объектно-ориентированное конструирование программных систем Переводчики: Владимир Биллиг, М. Дехтерь, Н. Супонев, Е. Павлова Редактор: Владимир Биллиг Языки: Русский Издательство: Русская Редакция ISBN 5-7502-0255-0, 0-13-62155-4; 2005 г. Книга взята с intuit.ru, где она лежит в виде двух курсов: Основы объектно-ориентированного программирования и Основы объектно-ориентированного проектирования Для конвертации были использованы wget, iPython, LibreOffice Writer, wkhtmltopdf.

Бертран Мейер - Объектно-ориентированное Конструирование Программных Систем

Embed Size (px)

Citation preview

  • -

    : , . , . , . : : : ISBN 5-7502-0255-0, 0-13-62155-4; 2005 .

    intuit.ru, : - - wget, iPython, LibreOffice Writer, wkhtmltopdf.

  • 23030303132323333353535373737383839404141414141424242424243434344444444454545464646474747474848

    (Correctness) (Robustness) (Extendibility) (Reusability) (Compatibility) (Efficiency) (Portability) (Easy of Use) (Functionality) (Timeliness)

    ?

    (seamlessness) (Assertions) , (information hiding) (Exception handling) (static typing) (genericity) (single inheritance) (Multiple inheritance) (Repeated inheritance) (Constrained genericity) (redefinition) (deferred) (memory management) (garbage collection)

    (automatic update) (fast update) (persistence)

  • 4848484949494949515153545455565657575859616162636467696969697070707070727273737373747575767676777878

    (browsing)

    -

    3.1 3.2 - ( Lisp)3.3 3.4 ( )3.5 3.6

    ? (design patterns)

    NIH

  • 7980808081828282828383868687888989909192929395959696979899

    100100101101102103103

    103104104104

    104105105106106

    106107108108109

    ? (The reuse-redo dilemma)

    (Type Variation) (Routine Grouping) (Implementation Variation)

    :

    ( ) (genericity) :

    - :

    ,

    -

  • 110111

    111111112112113

    113114114115117117118119119120120

    122122122123123124125125

    125126126127128128129131

    134134134134135135135135135135135135135136136136136

    ?

    ?

    (Genericity) ,

    , ? -

    ?

    6.1 6.2 6.3 6.4 6.5 6.6 6.7 6.8 6.9 6.10 6.11 6.12 -- BOOLEAN6.13 6.14

  • 137137138138138

    138139139140142142

    143143144144144145145

    146146146147148148148149149

    152152152153153

    154154154155155156158158

    159159159160161162162163163165

    165

    , -

    POINT

    indexing

    - Current -

    ""

    main "Hello" :

    ? :

  • 166166166166166

    167167167168168169170171172172173

    174174175

    176176176177178

    178179180180180

    181181181

    182182184184185186187189

    191191192193194195195

    196197197198

    7.1 POINT 7.2 POINT7.3

    ? - BOOK

    : " "

    ?

    ,

    void :

    : - :

  • 198199199199200200201

    202202203204205

    205205206206206206

    207207209209209210211213215215

    216216216217

    217218218218

    219220221222

    223223223

    223225225226226227227

    :

    8.1 8.2 8.3

    - -

    () ? ? , ,

    : ,

    ?

    "--" (Advanced)

  • 228228228229

    229229230230230230231

    231231232232232232232

    233233234234234

    235235236236236236237238

    238238239239239

    240240241241241241241241

    242242243243244

    MEMORY

    (Bulimia and anorexia)

    9.1 9.2 ?9.3 9.4

    : -

    10.1 10.2 10.3

  • 245245245246247247

    247247

    248249250250

    251251253254254256257

    260260261262262262263

    263264264265

    266266266266267267

    269271271272273275

    277277277279280

    282282283

    () : ,

    () : ?

    ?

    : ?

    ?

  • 284285288

    288288289289289289289289289290290290290290

    290292292292292293

    293293294295296

    296296297298

    299299300301301

    302302304304

    304305306307

    307307308308

    308

    11.1 11.2 11.3 11.4 11.5 11.6 11.7 (bugs)11.8 11.9 11.10 ""11.11 ""

    : 5

    - C-Unix - Ada

    (Rescue Retry)

    , , N-

    rescue rescue rescue

    EXCEPTIONS ?

    ?

  • 309309309309

    310310310311311312

    313315315315316316317318318318319

    319319319319320320

    321322322323323323323

    324324325327328328329

    331331331332

    334334335336336

    12.1 12.2 Exception

    - (re-architecturing) : ?

    (Assignment) (Creation) (Conditional)

    13.1 13.2

    ?

    ,

  • 337337338338

    339339340340

    341341342342343344344345

    347347348348

    349349350351352353353

    353354355356357358

    358358358359360360361363

    364365365365365365365365365366

    ? ?

    ?

    -

    : ,

    : ++

    14.1 14.2 14.3 14.4 14.5 14.6 14.7 ( )

  • 366366

    367367368369370371372375376377377378

    378378379380381381381

    382382383383

    383384384385387388389

    391392393394397397

    390

    398398398

    399399400400400400400400400

    14.8 14.9

    , ? - -

    : :

    -

    15.1 15.2 ?15.3 15.4 15.5 15.6

  • 400400401401

    402402402404404405406407407408409409

    410410411412

    412412412413

    414414415416417417

    417417418419420

    420420421423

    423423424425425426426426427427

    428428

    15.7 15.8 "" (walking) 15.9 precursor ()15.10

    copy, clone equality

    , -

    -

    Current

    -

  • 428429430430430431

    431431431431432432

    433433433434434434

    435435436436437437

    439439441442443443443

    444444444444445

    447448448449

    450450451451453453

    453454454

    ?

    16.1 : 16.2 16.3 ?

    : : " "?

    :

    !

    ,

    -

  • 455456456457457458458

    459460461461462462

    463464464464464464464

    465465466466466466466467467467467468469469

    470471472472472472472472

    473474475475476

    477477

    ,

    Unique-

    : Unique-

    18.1 18.2 unique-18.3 18.4 ?

    : :

    ,

    1.1 1.2 1.3 1.4

    :

  • 478478479480481483

    485485486486486486487

    488488489490490491

    491491492493493

    493493494495

    496497498498

    499499499499499499499500500500500500500

    501501501502503504

    504

    -

    : undo redo

    Command command

    : UNDO-REDO Undo Redo

    3.1 ( )3.2 Redo3.3 Undo-redo Pascal3.4 Undo, Skip Redo3.5 3.6 3.7 3.8 ( )3.9 3.10 3.11

    " " ?

  • 505505505506506506507508

    508508508509510510

    510510510511511511512513

    513513513

    514515515516516516

    517517517518519520520521522523523524

    527527528528529529530

    530

    ...

    :

    (CRC)

    4.1 Floors integers4.2

    , : , :

    ? (), ?

    :

  • 530531532

    532532533536536536537538540540545545545

    548548549549550550

    551552552552

    553554554554554554554554554554554555555555555555

    556558558559561561

    561563564564

    , :

    .

    5.1 5.2 5.3 5.4 5.5 5.6 5.7 5.8 5.9 5.10 5.11 , 5.12 5.13

    (To have and to be)

    : :

  • 565565567567567568569569570570571571571

    572573573573573574574575576577

    577577578578

    579579580581581

    582582583584585

    587587588588588589589

    589590590590591591591

    c

    , ?

    , ?

    ?

    : :

    6.1 , 6.2

  • 591591591591591591592

    593593593593

    593593593594594594

    595595595595595

    596596596597597597

    598598599599599600601

    601601602

    602602604605605

    606606608608609610610611

    612

    6.3 6.4 ?6.5 6.6 6.7 ?6.8 6.9

    .

    !

    : feature

  • 612612613

    613613613613

    614614614615

    615615616616617618619619

    619622623625626626628628630631631632

    633633633635636636636637

    638638639639639

    639640640641

    8.1 8.2

    : BON (Business Object Notation)

    :

    - ()

    (curriculum)

    " "

  • 641641

    642643643644644645645645646

    646647647648648

    650650651651652652653654654

    655656658

    654

    658658658659660

    661661662663664664665665

    665666667668668669669670

    670

    -

    ( - Object Request Broker)

    : (Concurrency Control File) :

    versus , , -

    ()

    -

  • 670671671672

    672673675676677679681682

    683684684684685685

    686686686686686686687687687687687

    688688689689689689689689689690690690690690690690690

    691691691692693693694694

    : "-" ,

    (Coroutines)

    - ?

    12.1 12.2 12.3 " "12.4 ( )12.5 12.6 12.7 (Locking)12.8 12.9 12.10 12.11 12.12 12.13 12.14

  • 695695

    697698698698698699

    699699700701701702702702702702

    703703703

    704704706

    706706707707707

    708708708709709

    709711711712713713

    713713714

    714714714714716717

    -

    -

    -

    -: MatisseVersant

    : - "- " ?

    13.1 13.2 -

    , , , -

    ()

    ---:

  • 717717718719719719720721721

    722723723723724

    725726726727728728

    729729729729729729730730

    731731731732732

    732732733733

    735735735736737738

    738738738738738

    740740

    :

    Ada 83 Ada 95

    - Ada 95: Ada 95 : : - Ada

    15.1 , 15.2 15.3 ( Ada)15.4 Ada15.5 -

    - Pascal?

    Pascal Pascal- Pascal

    Fortran COMMON

    - C OO C:

    16.1 ( Fortran)16.2 ( C)16.3 - C ( )

    Simula

  • 740740742742743744745747747

    748748748749750

    750750751751752752

    753754754754754754754755755755755755755755755

    756756756756

    756756757757757758758

    758758759

    761762

    Simula:

    Smalltalk Smalltalk:

    Lisp C

    Objective-CC++C++:

    Java -

    SimulaSmalltalk C: Objective-C, C++ LispJava

    17.1 17.2 17.3 17.4 17.5

    Bench

  • 762762765

    768

  • - 1. : - ; (softw are) - (softw are engineering). , . , . . ,, , .

    , , , , ,, .. . , , . .

    "" , , , , . , , - - , , , " ", .

    , , , , . , . : , , , . . ; - .

    , - .

    (Correctness)

    : - , . . , , - , - . , . : , . . , , , , . :

    . 1.1.

  • , , , . , . , , , . , : . , , : , .

    . 1.2. , : , . , . : , , , . , , . . , "" - "", "", "", "". , .

    (Robustness)

    : - . . , ; , .

    . 1.3.

  • , , . , , " ", . , , .

    " " ( . 12). , ; , . , - , , , .

    "" "", " ". , , , ,. , . - , ; , " ".

    (Extendibility)

    : - ., (soft) , , ; , , . . . , . , . , , . , , , . . , . . : . - , . : , , , , . . , , , . :

    : , .: , , .

    - - , , , . , -.

    (Reusability)

    :

  • . - . . . . , , , ( ) , , , . . , ( 4) , .

    (Compatibility)

    : - . , : . , . , - , , . . :

    , Unix, - . , Lisp, , , ( ). , Windows, OS/2 MacOS, , , , , . .

    , . , -, (middleware), CORBA Microsoft's OLE-COM (ActiveX).

    (Efficiency)

    : - : , , , , . "" (performance). :

    , . , , :" , " " 50% ".

    Abstract, Microsecond - , . ? . ,

  • , . : " , ". , . , . , . , , . , . . , , , " ". , . , , , , , , , . , - . , . , , . , - . , , , , :

    , , - , , . - ! , "" . , , . n - , N - , . , O(n) , - 2*N. O(n2) N 41%. O(2n) N - . . , , , , , . , " "; , 24 , .

    , , . , - , , , , , . , , , , : , , . .

    -, , . . - , , . -, , , , , . , , . - ; ( ) . , , . , .

  • (Portability)

    : - . , - , , , , , , . "" - ; "Intel X86 + Windows NT" ( "Wintel"). . , , , . , , .

    (Easy of Use)

    : - , . , . . , : , , ? , , - . , , , . , , , . , , , , , . - , - ; , , , . ., , , " ". 1), , . , , . : . - Fortran , IBM 704, Unix Bell Laboratories. , , , . . . , , , (), . , , , , . . , : , - .

    (Functionality)

    :

  • - , . , , - . . , (featurism) , (creeping featurism). , . , , , , . , . - , , . , , . . - , . , . ? , . . - . " " , . - . , , :

    . 1.4. ; [Osmond 1995] : . , , . - , , - . ( ) , . , : , . - , . ,

  • , ( ). "" , : , , , . : " ?", : " ?" , , , . , . , -. (. 10 " - " )

    (Timeliness)

    : - , , . - . , , . , , . - . Microsoft , , , , , Computer World2) ( ).

    , , , , . :

    (Verifiability) - , , . (Integrity) - (,) . (Repairability) - . (Economy) c - , .

    , . -, , . :

    , . ., , - . . , , . , , .

    . . :

    . . . -, . ( ), . . . ,

  • , , , .

    , . , , ? . , . , , . RAD - (Rapid Application Development), . , , . , . . - . , - . , , . , .

    . :

    : (bugs), , . : ; ; ( ); , , , , , . - (reliability) . : ; , , . : , , , . (modularity) .

    -, , , . , :

    : , .: , , , . , - , , . : - , , , (, - , "-" , , ).: , .

  • , : - , , ; .

    , , - - , . - , .

    : (maintainability). , : (maintenance) . . ; . , 70% . , . ? , , : , "", . (noble) . , . , , . - : , .

    . 1.5. . : [, 1980] , , , "". 487 , ; , , . , . , . , , . , , , . , . : . . , "5+4",

  • . , "", . , . - Millenium - . , : , . , . , , , , , . , . ( 6 ), , . , . ( , , ) o , . , , , () . - (5,5%) . , - , . - , , - : , , . , , . :

    - ; , , , , . ( " , " , , .) " ". - . , . , . , - .

    . , . , , , . , , . . - , . , , , , , - , . , , - - , .

    1) . Wilfred Hansen, "User Engineering Principles for interactive Systems", Proceedings of FJSS 39, AFIPSPress, Montvale (NJ), 1971. pp 523-532 2) "NT 4.0 Beats Clock", Computer World, vol.30, 30, 22 july 1996

  • - 2. : -. , , - . . , , -. , , ; , , , -. , ; - . - , . , (spoiler) - , . , 3-6, , . , , . , , .

    , (objectness).

    ?

    , , , -. . , , ? ? , , . , :

    - - . -, 100%. , . . , , , , .

    : , , .

    : (Method and Language) : , , . , ( ) "" , , . (Implementation) (Environment) : , -. (Libraries) : . , , .

    , , . , " ", , . .

    .

    (seamlessness)

    - : . -

  • , , , , . , , , . , . - :

    - , . - , .

    - -, , , .

    - . , - , . - , (features) - , , . .

    (Assertions)

    , . - - . : , . : (, ); ; . , , - , . , .

    - : . . , . -: . , , ( ). "", , Ada. , .

    , : . , INTEGER REAL, ; .

    ,

  • - . , ( ) , , . , display , , - WINDOW. : e d, n , raise e, n d. , (, ) - : ., C, . (message passing) ; e : " " d n.

    (information hiding)

    , , , . , -, , - . ., , . , ( ) ( ). . , : , . - . , - . .

    (Exception handling)

    . - , : , . . . . - , .

    (static typing)

    , , ? ( : , ?) , . , :

    (entity) , . , .

  • - . , .

    , , . , : " ". .

    (genericity)

    , , . . LIST [G] G - " "., , , LIST [INTEGER] LIST[WINDOW] INTEGER WINDOW " ". . , . . , , , .

    (single inheritance)

    , . , . A (heir) B, () B . (descendant)- ; - (ancestor). . - -; .

    (Multiple inheritance)

    . , "". "" , . - ", ", . . (multiple inheritance) - , , , . , (, , ). , , . . ., , .

    (Repeated inheritance)

    (repeated inheritance), , :

  • . 2.1. , , , ( - A). , A D (), - , (). , . , , .

    (Constrained genericity)

    - (constrained genericity). , , , . SORTABLE_LIST ; sort, . . : . COMPARABLE, , . : SORTABLE_LIST [G -" COMPARABLE] . .

    (redefinition)

    , . SESSION, , terminate, . REMOTE_SESSION, . , , , , REMOTE_SESSION terminate. , ( ) . , .

    , , , , , C . BOAT MERCHANT_SHIP SPORTS_BOAT, BOAT.

    , "" - , . - .

    (polymorphism) - . ,

  • . .

    , , . , , , BOAT turn. BOAT, , . , ,, turn , , . (dynamic binding). , , . . -, , my_boat turn. , , . ( merchant_ship? sports_boat?), , .

    - , . . , . , , , . , . , . (assignment attempt) . : ; , ; void. , , , . , .

    (deferred)

    , , , , . , BOAT , turn . , turn BOAT, , , , MERCHANT_SHIP SPORTS_BOAT. BOAT (, ) turn. , , . , - . , , . ( ) - , , .

  • (memory management) (garbage collection)

    , - . . , - .- , , , , Lisp, , . , , , . , , , , . - , (garbage collector) - (runtimesystem). - , . , . , , , ( - cast) , - . , , , .

    , -.

    (automatic update)

    - . ; , , , . , . , f C, , C, f, f, f C C . , , , " " " ". , -, , , , . , , . ( , ), , .

    (fast update)

    , . , , . , . , , . , , ( ). , , , , . , , .

  • (persistence)

    , , , . . , , , . ( ). . , (persistence closure), . , . . ; (database support) . - , , , , .

    , . , . ., , , , . .

    (browsing)

    ; , , . , . . : -, , , ; ; . (: S - , - S. " " .) .

    - - . - .

    - , , ,; - , , , . . , . , , , , , .- , . , .

  • . , . , - . . , .

    - . , . , , , . , . , .

    - . : , ( ) ( , ). , , .

    , , , , , , , . 2 " - ", - , . , , . , , , 3.

    - - , , .[Walden 1995] , , , , .[Page-Jones 1995] .[Cox 1990] ( 1986 ) ; - .[Henderson-Sellers 1991] ( ) -. , " , ", , . - [Eliens 1995]. [Firesmith 1995] . . . [M 1995] , ,

  • , . , , ( , , ). , [Goldberg 1995], . [Baudoin 1996] . , -, , , , , , . , , . :

    Simula BEGIN [Birtwistle 1973] ( - Nygaard Dahl.)Smalltalk-80: [Goldberg 1983]. C++, [Stroustrup 1991].

    - , " ". , , , , . ( ) [Rist 1995]. , - [Wiener 1996]. - . , - [Gore 1996] [Wiener 1997]; [Jezequel 1996] - . 11 " -". Usenet comp.object, , . , , . Computer (IEEE), 1995 , ., :

    Journal of Object-Oriented Programming ( , , ), Object Magazine ( , ), Objekt Spektrum ( ),Object Currents (), http://www.sigs.com.Theory and Practice of Object Systems, .L'OBJET ( ), http://www.tools.com/lobjet.

    :OOPSLA (, USA Canada, . http://www.acm.org); Object Expo ( , . http://www.sigs.com); TOOLS ( - ), ISE (USA, Europe, Pacific), . : http://www.tools.com, , .

  • - 3. : 3-6 , . (extendibility) (reusability), , 1, , . 1 (modularity), . , . , , - - . . , , , . - , , "". , - , . . : (criteria), (rules) (principles), , . , . : ( ), , . , , . , . - , . , . , "" . -, , , , , , , (packages) Ada (, ) Modula. , - - . -, , , - .

    [ , ] - , , . - , , -, , , , . , " " (1637)

    , "", :

    (decomposability). (composability). (understandability). (continuity). (protection).

    , , , , . , .

  • . 3.1. (division of labor): , . , :

    ; . : , , , , , , .

    1), , ( ) (top-down design). , . , , , . .

    . 3.2. (counter-example) , . - . . , , . " " (temporal cohesion) , . " ", . ,

  • . , . . " " , (. ).

    - .

    , , , , , , . , : , , .

    . 3.3. , , . . - , .

    1: . . , , , , , . 2: , Shell UNIX. UNIX , . | "Shell". A | B . A, B, . .: . , , "", . Fortran' C , . ; , , , .

    . . , , , , , , , . ,

  • , . , . , , , . , . : - -. , , .

    , , , ,, , . . , , , . , , , .

    . 3.4. , , :, , .

    : . , , . , B A C, , "" Unix, : A | B | C. , -, B, A C.

    : , . , , , , , , . - , .

    , . .

  • , . . , , . "" . , () . , , , :__: ->

    . 3.5. , . "" "" , . , .

    1: 2). , . , (constant Pascal Ada, C,PARAMETER Fortran 77, ). , . , , , , . 2: . , . 1: . , , , . 2: . , Fortran Pascal, , , .

    , , , , , , , . . , ,

  • (, - ). , , - .

    . 3.6. : . , , , , .3): (undisciplined) . ( . 12) PL/I, CLU, Ada, C++ Java (exception). , . "" ("raised") , . (exception handler) , , , . ; Ada CLU , PL/I. . , . 12, , (disciplined) , .

    , , :

    (Direct Mapping). (Few Interfaces). (Small interfaces - weak coupling). (Explicit Interfaces). () (Information Hiding).

    . - . .

    . , , , . : , , , . , , :

    : .: , .

  • , : . . ( ), . .

    . 3.7. , n , n-1, (A), n (n - 1)/2, (B). , , : , . ( , ), . (A) , , n-1, : , . "" , (C), . , . , . , . , - .

    , : , .- , :

    . 3.8. , , . Fortran, " " ("garbage common block"). Fortran'

  • :COMMON /_/ 1 : n.

    , , , COMMON _. Fortran', COMMON , . , , ; ( ) ( ) . , , ., , . , Algol , , Pascal, "" , begin ... end, . , (syntactic scope) . :local -- B1 x, y: INTEGERdo ... B1 ... local -- B2 z: BOOLEAN do ... B2 ... end -- B2 local -- B3 y, z: INTEGER do ... B3 ... end -- B3 ... B1 () ...end -- B1

    x , z ( BOOLEAN, INTEGER) B2 B3. x, y B1, B3, y. Pascal' , ( ).4)

    , "" Fortran' () . (external). ( . 10 "- ". " (selective exports)".) , . - , . Simula - - Algol' - . , , . - : ; ; ( (attributes) (routines)). , , , ; , , (flat) , .

    : ,

  • ; , ! A B A/ B. :

    . , .. , .. A, B?

    , , , ; , , (data sharing):

    . 3.9. , A , B x. A B x, ,, .

    : , . , ( ) , (public)., ( , ): , ! , : . , ()(secret). - - : () (private) . (interface) ( ). . , , ; , , . , , . , , ; - - .

  • . 3.10. , , . - , -, (B-Tree) .. , . - - . , - - . , , . , , , ( ) . , - ? , , , , , , . , (specification) (implementation). , , , , , - ! - .(. 6, " ".) , . , - - - (supplier module). - . , , , , , . , , , -( , -) -. , , .

    . -. ,

  • - .

    , . -, , , . , , - . , , . , ( ), ; , . : , , -, - - , , . " " ("informationhiding"), . , -, "" ("encapsulation"), , - " ". , , , , . , " " Ada Modula-2. - .5)

    , , :

    (Linguistic Modular Units). (Self-Documentation). (Uniform Access). - (Open-Closed). (Single Choice).

    , (, , ) : . , , . . . (, , ) , , , . , , , Ada, , Pascal C, . :

    : , . , . "" , . : .

  • , , .: , ; .: , , ?: , , .

    , , : , . , .

    , , . , , CD-ROM . , . (." " 1)

    . -, , , . , , - . , , , . , , , . , -- - , , -, : . , , . , : . , , , . , .

    . ISO, "2167" , (Capability Maturity Model), (Software Engineering Institute). , , "" . , ( , ) .

    - - , . , : ( ). . (. " (assertions) " 11. . 5 " -" .) , (views). , , - . - , ,

  • -, , . .

    , , , , - . ; .6)

    x - , , . f - (feature), x. ; . , x , , f - , (account's currentbalance). , , f x, - f. , f x, f, . , x, , , . :

    A1 , . , , .A2 , , , , . , .

    , Pascal, Ada, C, C++ Java x.f A1 f(x) A2.

    . 3.11. A1 A2 " ": , - . , , . , . x' , , f. . :

  • , , , , . . Algol W, , a(x). -, , Simula 67, x.f . , 7-18 , .

    -

    : -: - , . , :

    , . , . , . , ( - ) . , , ( ). , , - (project baseline), .

    . , - , - . , . , , . , , . , (parsing module) - . , . , , , : , . , . , , , , . , , , . A - B,, D, - E, F .

    . 3.12. - F ,

  • A, A':

    . 3.13. -, , :

    N1 A , , .N2 A , , A', . A' A.

    N1 . A , B, D. , , , A; A "" , , . : , - , , "" , , . - , , - -, . N2 : , ( ). , , . , - , . , : , , . , ( , , , , ), . . , "" , . , .

    , , , , , , . ( 3.6 , - .)

    , ? A ,

  • A' , ? (inheritance), - . , . , - - A' A, . A' class A' inherit A redefine f, g, ... endfeature f is ... g is ... ... u is ... ...end

    feature , A', u, ( f, g,:), A' , A. "" (heir) ( A') "" (parent) ( A):

    . 3.14. , , . - - . "" (slipshod) ( , , ). , . , , , . , , , . , , "" : if(__) then. , , , , ( , "", "").

  • , . : . :

    , , , , . -, , . - , , . , . - , "" , , , .

    -, . , ., ( - : , ). , . Pascal-Ada:type PUBLICATION = record author, title: STRING; publication_year: INTEGER case pubtype:(book, journal, conference_proceedings) of book:(publisher: STRING); journal:(volume, issue: STRING); proceedings:(editor, place: STRING) -- Conference proceedings end

    " " (record type with variants) , ( author, title, publication_year) , - .

    . Algol 68 C "" (union). union T, A, B,:: T A, B,: . , (tag), book, journal, conference_proceedings.

    A - , . A , . A , , , . , B A. B , :p: PUBLICATION

    p - , :case p of book:... Instructions which may access the field p.publisher... journal:... Instructions which may access fields p.volume, p.issue... proceedings:... Instructions which may access fields p.editor, p.place...end

    case Pascal Ada; . Fortran' C goto (switch C).

  • , (if ... then ... elseif... elseif ... else ... end). , , , - , A. . , , . PUBLICATION A, . : , . : A, B, , , p. , , ., : -. , . "" ("publication"), : (book), (journal article), (conference proceedings); :

    : (figure), (polygon), (circle), (ellipse), (segment) . : (user command), (line insertion), (line deletion), (character deletion), (global replacement) . : (language construct), (instruction), (expression), (procedure).

    , , , . , . : , , . , , : , - . , - , . , , , , : (polymorphism) (dynamic binding). ; . (. "" 4) :

    , . , , ; , . , , , - , - . , , (distribution of knowledge) . , . , , , . , , (need-to-know): , .

  • -. , : A , PUBLICATION; B, C , ; A' A, - (technical reports). (. "-") . -, A A', ( ) -.

    . ( ), (-). , . ; , ( -) ( -). . , . , -. , , ,-. , . , , . . .

    , " " [Yourdon 1979], . "" "" . , . ( " ") [Geschke 1975]. Algol W, Algol 60 Pascal ( , Pascal'), , [Hoare1966]. [Parnas 1972][Parnas 1972a]. , , , , Make, Unix [Feldman 1979]. - - . , . , -, (Christine Mingins) [Mingins 1993][Mingins 1995] - (Brian Henderson-Sellers) [Henderson-Sellers 1996a].

    3.1

    ,

  • , .

    3.2 - ( Lisp)

    Lisp' , . , Lisp -, ?

    3.3

    , ?

    3.4 ( )

    , . . :

    . . . . . .

    , , . -: (. ).

    3.5

    , , . , . - (, , ) , , , , ?

    3.6

    , . , , . - , - , . , -, , - . , , - .

    1) , . 2) : (Symbolic Constant Principle.) 3) " (assertions) " 4) . , Algol. "--" . 5) , "Ada" Ada 95,

  • ( 1983 .). 15 " - ". 6)

  • - 4. : " ! , . , , (VLSI devices). , , . , ,, . , , , - , . ?" , , . 1968 . , - (Doug McIlroy) " ". , . , . , 1988 . , . , , Visual Basic (VBX) Microsoft OLE 2 (OCX, ActiveX), , " " ("framew orkapplications"). : , (w ired society), , . . - , . - . , , , , , . , .

    , , . " ". , , , .

    : (timeliness) ( , : ). , , , . (decreased maintenance effort). - , . : " , ". , . " ", - , - . .. , , , . , - . , , . - , , - , . , , .. , , , . , , , . . , .. -, , " ", . .. , .

    , , , - .

  • . , , . . , , 1. . : , , - , . . - ., - , , . , , , .

    - . , . . - - . : , , , . , , . . - . , . , .

    ? , - , , ? - : ,, , , , .

    , . , . .

    , , - , . , , , , , , . , , . : .

  • . , . , , . ; ( -) ( ). "" , , , , , . (, -, ), . (design for a module) , : , ; , , . ( ) .

    (design patterns)

    ( ) . - , ; .( 3 "- ".) , . : , , , , , . : COMMAND ( ) " ". .

    , : 1), , , . -, . ? , " - ". , - (book pattern), , " ", . -, , AVL-( - ), (Quicksort), , - , . ,, , , . - , . , (. " ", 14). -, , . , . - . , , . - - , . "" , , , - , . , (behavior class) ( (programs with holes)). , () (deferred class), . ,

  • - (frameworks) - , .

    , , . , "", : . , ? - : . . , Unix, , , . , . Lisp. . :

    (source) . , , . . , .

    , "" .

    , , :

    , . , , , . , ., -, -, -. , . .

    . ( ). , . , , . , , , (reusers), : , , ( ). (units of reuse), , , . 3-6 ; 7-18 .

    , (source form).

  • : , , , , . , , .

    . , . "" : , ,, , , , - . de_ja vu ( - , ), . ( , ), : , , , ?

    , x t. , , t, .

    , . . , , 3 . . , . :

    , , . , , , -, .(. .)

    ? ; ( ). , , , .

    NIH

    : " "(Not Invented Here "NIH"). , , , . . . , , . . , (parser generators), Lex-Yacc, . : , , . , . . , NIH, " " (Habit Inhibiting Novelty "HIN"). , , , , .

  • - Unix' , Yacc, HIN., -, NIH, . , , , . . , . , , . N , R - , . R : , , . r=(N - R)/ N

    , "" , .

    , , (, ). , . , , , .

    , , , - , ! -. , , , , . 90% " " , , 100%. . , : , , , - . , , , , , , , . (engineering part) ; , , - . , ( , , ), , , - . , , . :

    , , - , , . . , : . , ,

  • . ; . , , , . , , , .

    : , "" , . , , , . , , , - . , . . , - , , , . , , , . WWW , , (Intranet)., (, , -). , , - .

    : , ? , , , - . , 7-18 . ."", 3. . (indexing clause) Indexing index_word1: value, value, value ... index_word2: value, value, value ... ... ... (. 7-18) ...

    index_word ( - ) ; value ( - ) (, . .), , . ( . " ", 8 " - ") , , (standards group), , , . , ,

  • . , - - , , ( ). , , , .

    , , , : ? , . ( (short form) ) . . (" (assertions) : ", 11) , , , -. , , , , (League for Programming Freedom), , . : . . , (porting efforts). , , , - . ( , , , .)

    , . . , , C, C.2)

    , UNCOL (UNiversalCOmputing Language - ), 20- . , , , . 1988 . (Advancedcomputer environment (ACE) consortium). Java - Java-, . . , , , - . , . , , , .

    , , . , ; . , . , , . , . , - :

  • . . ( ) , ., . , . . , , .( , -, 11 " -".)

    , , : - .

    , , , . , ? :

    , (League forProgramming Freedom): .(. .) , (superdistribution), (Brad Cox) . , , . , , "" , , . , -, , . JEIDA (Japanese ElectronicIndustry Development Association) . , , ( ). , .

    : , , ., , , STARS (Software Technology forAdaptable, Reliable Systems - , ) " " ("software factories"), . , , . , , . . , , , , .

    ?

    , , . , .

  • , , . , , , . , .

    , , Simula. -, : , , , , . , , , , , , , .

    , , . , : . , : t, , , , , . , , . , ( ), ( ), , , - -. :has (t: TABLE, x: ELEMENT): BOOLEAN is -- x t? local pos: POSITION do from pos := INITIAL_POSITION (x, t) until EXHAUSTED (pos, t) or else FOUND (pos, x, t) loop pos := NEXT (pos, x, t) end Result := not EXHAUSTED (pos, t) end

    : from ... until ... loop ... end , from, loop, until. Result , has. or else ( or else 13), , or. , , ( ). , : (ELEMENT), (INITIAL_POSITION), (NEXT), (FOUND), , (EXHAUSTED). , , , , .

    ? (The reuse-redo dilemma)

    , : ? : , - , . . - "soft - , "", .

  • "" - : , , . . , , , . : , - , , , . , . ( "", ). , , . -. (. " -", 3) . , , . , .

    , , , , , ? has , . , . :

    (Type Variation). (Routine Grouping). (Implementation Variation). (Representation Independence). (Factoring Out Common Behaviors).

    (Type Variation)

    has , ELEMENT. , INTEGER BANK_ACCOUNT, . , . "" . , , (type-parameterized), - () . (genericity) ( ) -; . (. "" ("Genericity"), 4)

    (Routine Grouping)

    has, , . , , , . - . , , - , ,, . "", : Ada, Modula-2 . .

    (Implementation Variation)

    has ; , , . ,

  • , - . . .

    - . ., - C ( ,, ) , x t (, , ). C present := has (t, x)

    , t . C , t , x . , t , - . , . , t, , .- C, , t ( ). C t , . (), : , (. " ", 3). . , , - ! , , has t , . , , , , if "t , " then " "elseif "t " then " "elseif ( ..)end

    ( , , , ), -. (. " ", 3) , , . (dynamic binding), -, . (. " " ("Dynamic binding"), 14)

    - - . (commonality), . , , , ,

  • , . , . :

    , ., ., .

    , . , , - , .

    . 4.1. , . , , () , , . :has (t: SEQUENTIAL_TABLE; x: ELEMENT): BOOLEAN is -- x t? do from start until after or else found (x) loop forth end Result := not after end

    , ( 5 " - "" " ("Active datastructures"). ):

    start () , , .forth () , .after () , , .found (x) , , true, , x.

  • . 4.2. , , - , , ( 7-18 ). start,forth, after found, has. . , . capacity , 1 count + 1.( , ("after") .)

    . 4.3. , first_cell right. cursor.

    . 4.4. , .

    . 4.5. start, forth, after found . 3) . t @ i i- t, t [i] Pascal C; Void "" ; f- Pascal, f, .

    4.1.

  • start forth after found (x) i :=1 i :=i + 1 i >count t @ i =x c := first_cell c :=c. right c =Void c. item =x rewind read end_of_file f -=x

    , . , , . . has, . , has , . has; start, forth, after found.

    , , , , , , - . , -, , , -.

    , . (routine) , , , , , , . ( - ) (actualarguments) . ; . , , , . , , ( ) . , , , ( - ) , :

    R1 . , .R2 , , , - - .R3 , .

    . , , - . , :

    . , , . , . ; .

    , , . . , . - :

  • , .

    , , , , . , : CLU, Modula-2 Ada. , Ada , CLU - , Modula - . .4)

    - , :P1 , "" , .P2 , , (features) .P3 , . , .P4 (, , ) .

    P3, . P2, . , , , . , , , . - , , - - INTEGER_TABLE_HANDLING, , :package INTEGER_TABLE_HANDLING feature type INTBINTREE is record -- , : info: INTEGER left, right: INTBINTREE end new: INTBINTREE is -- INTBINTREE. do ... end has (t: INTBINTREE; x: INTEGER): BOOLEAN is -- x t? do ... ... end put (t: INTBINTREE; x: INTEGER) is -- x t. do ... end remove (t: INTBINTREE; x: INTEGER) is -- x t. do ... endend -- INTEGER_TABLE_HANDLING

    (INTBINTREE), , . ( ).- , INTEGER_TABLE_HANDLING. , f , CLU: P$f. : -- :x: INTEGER; b: BOOLEAN -- t , INTEGER_TABLE_HANDLING:t: INTEGER_TABLE_HANDLING$INTBINTREE -- t , new :t := INTEGER_TABLE_HANDLING$new -- x , put :

  • INTEGER_TABLE_HANDLING$put (t, x) -- True False b, -- has :b := INTEGER_TABLE_HANDLING$has (t, x)

    : , INTEGER_TABLE_HANDLING, , INTBINTREE. - . .

    ( INTEGER_TABLE_HANDLING). , , (shortcuts), , , Ada:

    with INTEGER_TABLE_HANDLING then ... has INTEGER_TABLE_HANDLING$has, .. ... end

    : . , , , (generic). , . , INTBINTREE, , , . ( record, ), ( do). , (, , ), .

    , , . , Ada, , INTBINTREE, , private ().

    , , (interface) (implementation)(. 11 5 "- "). , , . , . . .

    :

    , . " " , :

    - , . . , ; , new, put has, remove. - , .

    , , , . . , , . , - " " . , INTEGER_TABLE_HANDLING , - . , , . . : , , , , , - . ,

  • . . :t: INTEGER_TABLE_HANDLING$INTBINTREE

    . : - -, .

    - (overloading) (genericity) , . , .

    - . : , ( - Algol ). , , . : , a +b, , a b (, , ). Algol 68, , , , ., Ada , , . , Ada , . , square:5)

    square (x: INTEGER): INTEGER is do ... endsquare (x: REAL): REAL is do ... endsquare (x: DOUBLE): DOUBLE is do ... endsquare (x: COMPLEX): COMPLEX is do ... end

    square (y) y , . , :has (t: "SOME_TABLE_TYPE"; x: ELEMENT) is do ... end

    , "SOME_TABLE_TYPE". , has, , . , , : , . , . ? . - , , , . . , . has (t, x)

    t, ( ) , t!

  • , . , has_binary_tree (t, x)has_hash (t, x)has_linked (t, x)

    ? . , , (non-deception): . . has , - , . ( ) - . , ., - - . , square has , , . , -, , , :p1 := new_point (u, v)

    : x y; r q ( , ). new_point, , , :new_point (p, q: REAL): POINT

    , , , . .

    , Java , , .

    ( )

    . - , , . . has (t, x) . :

    (Hardware-Software Machine):, , t; , , , - , , , . -, , [ , ..]. - . , , 'has', . , , 'x' 't', . . , , 't' , 'x' , . , .

    , . (non-deception), (assertions),

  • , (, , has ). -, - , , . -, , C++ Java, , , .

    (genericity)

    - (module patterns), . . , :INTEGER_TABLE_HANDLINGELECTRON_TABLE_HANDLINGACCOUNT_TABLE_HANDLING

    :TABLE_HANDLING [G]

    G, , (formalgeneric parameter). ( , .) (generic module), , - . , , ., G , , , :TABLE_HANDLING [INTEGER]TABLE_HANDLING [ELECTRON]TABLE_HANDLING [ACCOUNT]

    INTEGER, ELECTRON ACCOUNT , , . ( ) (generic derivation), "" (generically derived.).

    . -, (generic instantiation), (generic instance) -, "" , (). "". "". , , . "" (, ) (, ). , , , "" , "" .

    , TABLE_HANDLING INTEGER_TABLE_HANDLING, , G INTEGER. :package TABLE_HANDLING [G] feature type BINARY_TREE is record info: G left, right: BINARY_TREE end has (t: BINARY_TREE; x: G): BOOLEAN -- x t? do ... end

  • put (t: BINARY_TREE; x: G) is -- x t. do ... end( ..)end -- TABLE_HANDLING

    , , BINARY_TREE, BINARY_TREE [G]. "" . , . , , (genericity) -. : , . , , . ? , , , , , . 7-18 .

    :

    . "", (package construct), , . , . , , , , - , . , , , . , , , , . , , . , . , . - - , , . -.

    , (common patterns). , , , , . , . , , , . : . . - " " . . : , , , , . , , , .

  • , , . : . , , . , . : , ; , , .

    , , ,, -, - (McIlroy's 1968 Mass-Produced Software Components). [McIlroy 1976] 1968 . , (NATO Science Affairs Committee). 1976 . , [Buxton 1976], . - . :

    " . , , ... , : " ?". : " ?" ... , ... ."

    , , , . , [] .

    - "" (routine), ""; , , - - .

    Transactions on Software Engineering, (Biggerstaffand Perlis) [Biggerstaff 1984], ; , , [Jones 1984], [Horowitz1984], [Curry 1984], [Standish 1984] [Goguen 1984]. ( ) [Biggerstaff 1989]. [Tracz 1988]. (Tracz) IEEEComputer [Tracz 1995], . , , (MIT Programmer'sApprentice project); [Waters 1984] and [Rich 1989], -, . , ( cliches and plans), . " ": Ada, Modula-2 CLU. Ada , Modula-2, CLU, Mesa and Alphard, " " . Alphard (form). STARS , , Ada. STARS DoD-Industry 1985 . [NSIA 1985].

  • " () " [Gamma 1995] [Pree1994]. [Weiser 1987] . ; , , . (RichardStallman), (League for Programming Freedom),, ; [Stallman 1992]. [Cox 1992] (superdistribution) Algol 68 [van Wijngaarden 1975]; Ada ( ), C++ Java, , . (genericity) Ada CLU, Z [Abrial 1980]; Z . LPG [Bert 1983], . ( "Language for ProgrammingGenerically".), , [Knuth 1973]. , , [Aho 1974], [Aho 1983] [M 1978]. . Reusable Software [M 1994a], , , . Object Success [M 1995] , , , , , , -, (, , ). , [M 1996].

    1) [Gamma 1995]; [Pree 1994]. 2) ISE C, -. 3) i, - c. 4) 15 " -", Ada. , "Ada" Ada 83. ( Ada 95 , .) 5) , , , Ada-, Ada. REAL Ada FLOAT; .

  • - 5. : , - - , . . , , : . , . . , , , . : , . , , "-" ( "" ) . , .

    : ? , .

    , - - .

    . 5.1. - ( ), . (, ), "" . - , . . , , - - , . - , . - , , - , ( , ) , . , . , ( ). , . - , , , - .

  • . : , , , . "" , : , . , , "", ., , "" - , "". "" . , "", "".

    , , : , . , - : ? , . - . - . , - . , . - , , , "--", . , , -. , "" , , , . , - . , , , . - , , , , , . .

    , . , - - , , , , , -.

    : " : ?" , - , . , , , , . - , , . . , , , , , , ,, , . ( ), , , , . " ",

  • . ?

    , . . - . , " " . , [C0]" - "

    [P0]" "

    . , . , ( ) [C1]" "" "" "" "

    , ( , - - ):[C'1]from " "until " "loop " " " "end" "

    ( " ..." " ") , , , . . , "B A".

  • . 5.2. : . , , , , , . . , :

    . , , .

    , , . . , : . , , , , :

    . 5.3. ( ) ( . .). , "". - . , - "" ., , . , . , . , , - . : " ?"" , , - , ?" ", ,

  • ". " ". ", ? . , ?" - - . , , . , . , , , , , - . . "", : , , . " ", , , , . , , . , , . , .

    , . - "", " 8 " . . - "" , . - . , , , , -, . . , . : " "" ?", . " ",

    :from until loop " " " r " " r" " " " q " " q "end

    . , - . . , , - -, . . , , , , , , .-, - ,

  • - : ""!

    , . , : "", , - , . : , " , ", , " , , -". .[B0] - " "[B1] - " "" "" "

    . . .[I1]" "[I2]if " " then " " " "elseif " " then " " " "elseif " " then if " " then " " " " else " " if then " " " " " " end endend

    ( . .) . , , , - . : -, ( ), -, (.. ).

    , . - .

  • , : " ?" . , , , . , , -. .

    : . , ( ). , . .[C1]" "" "" "" "[C'1]from " "until " "loop " " " "end" "

    , . ( , - ), . . , (, , , ) , , , , , . , . : , .- . , , , , , . : , .. , . , . .

    -

    , - . - . -, , . , - case , -. , , , , . - -

  • , , , . , (. 11). . , : , , . , , , :[H] _ _ _

    - . , , , - , . :[H1] _ ensure _ _ ensure _ _ require _ and _

    11, . require , , ; ensure - , , . , , . H1, , , H? :H1 , , H. , , , , , - . , , ., , , . , , - . , , , , , (case ) . - , , -.

    - . , . , , , . , , , .

  • . 5.4. , , : C2 , C. C2 , .. C. , C , , C2 , ( ). , . , , , . , C , , C2, , - ., , , , , . , "" . , , , , , . : n- (n-1)- (n+1)-. , .

    , . , , . " " ([Jackson 1983], . 370-371): - . , - . . : . ... , , , . , : . , .

    :

    , . , , . .

    ,

  • (, , , - ) , 1, , , . , : . , , . , , - . - , . , .

    , , . , , . , , , , , , . , , , , , . , , - , . . , , , , , , , . .

    , ( ) . ( 4) : . , , - , , , , . , , , . , , , - . , , , .

    , , , ( - ) . , . ?

    -

    , - . , .- ( 1)- - , , , (

  • , ). -: , ., ! , , . . - , , . . . . , , . , : , , - , , , , - . , , , . , , , . , - , , - .

    -. - , , :

    ? ? ? ?

    . .

    " ?" . 4 "- " , . -, , :

    . , . - , () (, ) , . -, CALL () LINE (), - DOCUMENT(), PARAGRAPH () FONT (). : , . , -, . - , ., . - , .

    ,

  • "" - .

    , , , . , . :

    , : . , , - - .

    , .

    , . : " " . A B :B A , B A .B A, B A . , , -, . , , , . :

    " " . , ( B A ), . . . , " 1- n" ( B n A) , B A, , " ". , , - .

    : ( ), () ( ). ., , , , . , , . "" , . . . , . - , . - , , , . , ( ), . , - .

  • : " " .

    - [Cox 1990]( 1986), [Goldberg 1981], [Goldberg 1985], [Page-Jones 1995] [M 1978], [M 1979], [M 1983], [M1987], [M 1988]. . [Wirth 1971] . , , -, JSD [Jackson 1983] [Jackson 1975]. . [Orr 1977]. , - , [Yourdon 1979], [DeMarco 1978], [Page-Jones 1980],[McMenamin 1984], [Yourdon 1989]; Merise [Tardieu 1984], [Tabourier 1986]. - [Chen 1976].

  • - 6. : () , . , . , , , , , ( ). , , -, , , , . , , , . , , , , , .

    , , , . , . [] , : , , , . , : " , , , , , , , . . , A. , , , ." , ..., " " , , , . , , , . - , - , . , " , "

    , :

    . - , , ( ). .

    . , , , " ", . , , , . , . , , (, ) , , , . , , , , .

    , . . , " - " ("LIFO"),

  • " - " ("LIFO"),, , . , , .

    , , . - , " , ". . , , . , .

    :

    . 6.1. . :

    _: representation count, 0 ( ) capacity - representation, 1 count._: _, , . , free, 0, capacity 0 . capacity free+1.: :item, , previous, . last ,

  • . ( ), : x (push). _ _ (count free) x . capacity , :if count " capacity then ...if free " 0 then ...,

    ( ). :

    n ( new, ); x item ; previous last; last , .

    , ., , count _ free _. , - . count= free. : n, _ _, , n . 2n, , , 2n, , . ( p q, max (p +q) "= max(p) + max (q)).

    . 6.2. . . , , _ ? _ - , count, - .

    ? (Lientz) (Swanson) . , 17% . , ,

  • , . , .

    ?

    , , . , (Risks) ( Usenet comp.risks), , . . . , , , "". TRW , "". :

    , , , -, , TRW, , . : " (sic) ".

    (""), , . , , - , , , (Risks) . " " , , .

    , , ?

    , "" (.., ), , . , , , , ,, . :

    . put. . remove. , ( ). item. . ( remove item.)

    , - . make.

    . -, , , put push, remove pop, item top. -, : , , , , , . .

    , , , _. count: INTEGERrepresentation: array [1 .. capacity] of STACK_ELEMENT_TYPE

    capacity - . put, remove, item, empty make , , .

  • , : . , - , .

    . , , , . - , "----". (, , ) , . , - - , , -, , " " - . ( ): . -.

    , . , , . :

    6.1. , Push () Put ()Pop () Remove ()Top () Item ()New () Make ()

    , ? - - "", . , , . (put), (item) (remove) , , . , LIFO, , , . -, " , " (FIFO): , - . , , - , , . (, ..) , , , , , ,, . item, remove, .. - "", . , - , , . . , , ( ) .

  • , - . , - , ., , , .

    ?

    , , , , , , . ( ) , , . . ( ), .

    , . -, , , , , , . (, , , .) , , , , , , . - , , , , , . , , , - . , , , . , , . , , ! : , , , , , , , . , , , ., , , , , , .

    . , , , MAIL_MESSAGE (_) . , , , sender(), . , , sender. , , , sender. , , set_sender(_), ., . . , " " .

    , . . , , , ! - put "" ,remove , . , .

  • . , :

    .

    - - , . , . , .

    . , , STACK(). , ? , : - , , . "" - STACK , INTEGER .. : , STACK, - ( ), ( ). , : . , - , , . - , , , , , , ., , , . , , STACK, STACK. - , . , . :

    STACK[G]

    , - STACK, G.

    (Genericity)

    STACK[G] G , . G STACK, STACK . , , , . , . , , ! , , ( - G), . STACK - , . , ACCOUNT, , G., STACK , STACK[ACCOUNT] . , , , . : , , ,

  • , ACCOUNT . , , STACK ( , ) . , STACK[STACK [ACCOUNT]] : , , , . , "" . , STACK (, , , ), , STACK, , STACK[ACCOUNT]. , S , , ., STACK : -" ". , , "". - , :

    , . . , - . , , , STACK[ACCOUNT], STACK[G].

    , , . , , , , , . STACK. , : , Pascal Ada. new , - .

    put: STACK [G] G STACK [G]remove: STACK [G] STACK [G]item: STACK [G] Gempty: STACK [G] BOOLEANnew: STACK [G]

    , . , put , . ? put . put , , , , . put "" - , . ( - ). - . , , - : 2 . . , . , . - , , . , R ,

  • square_plus_one: R Rsquare_plus_one(x)= x2 + 1 ( x R)

    square_plus_one, R , 1. . , put

    put: STACK [G] G STACK [G]

    , put : STACK G G STACK [G]. ( , put STACK [G] _ G, STACK [G] G, .. , s STACK [G] , x G.) , :

    . 6.3. put , , , . , , - , "" . . , , . , STACK:

    put , . put(s, x), s x. remove , . put, (, , ). , , . item , . empty , ( ). , BOOLEAN, , . new .

    , - . put

    STACK [G] G STACK [G]

    , put , s - STACK [G], x - G, STACK [G]. , ( , STACK [G]) . , .

    remove item . , . new

  • new: STACK

    . ,

    new: STACK,

    . , new - . . (. . ) new, new(), new .

    , . T, STACK [G] . , T:

    "", "" "". , .

    , T , new, -. , T , new. item empty, T , -. , T, ( - BOOLEAN G). put remove, T , -. , T ,, T.

    , (, STACK) , . , , - . , , - , . , : " - ", ., , , ( , ), . :

    square_plus_one: R Rsquare_plus_one (x)= x2 + 1 ( x R)

    , , . ? square_plus_one, , . , , , _. , STACK - , representation - , count - . put ( x G) :put (, x)=

  • a [n: v] , a n v( ). put put, _ . , . " !" - ( ) . (, , : - ). , . - , . (AXIOMS). STACK . x: G, s: STACK [G],

    (A1) item (put (s, x)) = x(A2) remove (put (s, x)) = s(A3) empty (new)(A4) not empty (put (s, x))

    ( - ) LIFO. , , s x, s' put(s, x) , .. x s. :

    . 6.4. put A1, , s' x - , , A2 , s' s, x. . A3 A4 , , - : , new , , ( ) . , , ( ), s x. A3 A4 empty : x: G, s: STACK [G]A3' empty (new) = trueA4' empty (put (s, x)) = false

    ,

    . "": , .

  • , ; , , . . , . : , , , .

    , , - - - . , - , , , . , . : . . "" . " " .

    , , : . , remove item: , . , , , . X Y , X. , , . inv, x inv(x)= 1/x.

    inv x = 0, R :

    Inv: R R

    , , , , .

    () X Y X, . inv R - {0},.. , 0. STACK remove item - . , : ? put , , _ _, put . - STACK , , . , . , remove item , .

    , : . : f X Y , , f(e) , e X - , f.

  • , , . (PRECONDITIONS). STACK : (preconditions)

    remove (s: STACK [G]) require not empty (s)item (s: STACK [G]) require not empty (s)

    "" , , . , , . remove item , . "" ( - s), .

    f - f. A X ch: X BOOLEAN, ch(x) , x A, .

    (PRECONDITIONS) STACK. , . . (TYPES)

    STACK [G]

    (FUNCTIONS)

    put: STACK [G] G STACK [G]remove: STACK [G] STACK [G]item: STACK [G] Gempty: STACK [G] BOOLEANnew: STACK [G]

    (AXIOMS) x: G, s: STACK [G]

    (A1) item (put (s, x)) = x(A2) remove (put (s, x)) = s(A3) empty (new)(A4) not empty (put (s, x))

    (PRECONDITIONS)remove (s: STACK [G]) require not empty (s)item (s: STACK [G]) require not empty (s)

    . , , , - . , . . , . , .

  • . STACK stackexp:item (remove (put (remove (put (put (remove (put (put (put (new, x1), x2), x3)),item (remove (put (put (new, x4), x5)))), x6)), x7)))

    -, stackexp , :s1 = news2 = put (put (put (s1, x1), x2), x3)s3 = remove (s2)s4 = news5 = put (put (s4, x4), x5)s6 = remove (s5)y1 = item (s6)s7 = put (s3, y1)s8 = put (s7, x6)s9 = remove (s8)s10 = put (s9, x7)s11 = remove (s10)stackexp = item (s11)

    , , stackexp: ; x1, x2, x3 ( ); (x3), s3; . . . 6.5. , .( x4). , , , , . :

    A2 s3 - . . remove(put (put (put (s1, x1), x2), x3)) put (put (s1, x1), x2)). ( A2 remove-put ).

    . 6.5. s6 put(s4, x4) . A1 , y1, .. item(put(s4, x4)) x4, ( ), s7 x4 s3.

    . , , stackexp, x4 ( ,

  • ). : . : , , . .

    , - , , - . - , ! ? . , , , . -.

    , 3, . , - ( , ) , . - :: - , ( ) , , , . - , - , . , , , . :: (effective). , , (deferred). , . , . , . - . .

    . ? :

    (E1) ( , ).(E2) .(E3) (E1) (E2) ( (features)), . - , "" ( ).

    , STACK ( E2) , _, ,

    representation - , count - . (E3) put, remove, item, empty new, ., put put (x: G)

  • is -- x . -- ( .) do count := count + 1 representation [count]:= x end

    , (E1), (E2) (E3), - .

    ( E2 E3). - , . "" , , , , . :

    - , - , , , . , .

    , . - : , ( ) . - , . , - , , - , , . - . , . , , ( ) . , -, . , -.

    -, (), , , : - ?

  • . 6.6. , , . , , E1- , , E2 E3 - - (). , , , - , . , , .

    : . , , . ., , . , , . , -:

    put: STACK [G] G STACK [G],

    , , . , . , put , G ( ) , , . , . ( "" ""). . A1 A4,

    (A1) item (put (s, x)) = x(A4) not empty (put (s, x))

    , (routinepostcondition), ensure ():put (x: G) is -- x

  • require ... ( ) ... do ... ( ) ... ensure item = x not empty end

    , put item x( ), empty . , ., (. 11.10 " ").

    , ?

    , , , , , , , . , , , - , , - . : . , : ( - ), , ... ! ?. , , ., , : , . - : - . . - - . , : , .

    -

    -: , : " , , ". , : - ( 2) - - ( ) . . :

    . ( ), - . , " " , , , - . - . : "" .

    , .

  • , , , , . , , , - . , , . , - , , , - , , , - , , , - , , , - , , , "" . , , - , , , : . , , - , . , , , . ( , , , ). , . - - , , , , . . , , , " ", . . () , ( , ), , , , , , , , . - - - . , , . , , , , , , ,, , , , . , . , -, , . , .

    . ( , , ). , , , , , , , -. , :

    ; ; ; ; .

    .

    , ,

  • . ,

    x: POINT REALy: POINT REAL

    , Pascal:typePOINT = record x, y: real end

    : , POINT x y REAL. , :

    Pascal : , POINT . . , POINT x y, , , .

    , POINT :

    POINT REAL REAL,

    " " (" "), POINT. POINT , POINT, , . , , , . .

    , : - , , - , . , " " " ". , , . : " x , ". ( ). : - , :: () - . - - : , , . , - , , . -

  • ( ) , - .

    , , . , :class POINT feature x, y: REALend

    . , , - ! : ( ) - ,:class MOVING_POINT inherit POINTfeature mass: REAL velocity: VECTOR [REAL]end

    . (, ) POINT, p1: POINT

    POINT, , MOVING_POINT. , , " ":p1 := mp1 mp1 MOVING_POINT.

    : , . . POINT, , , . (), (), , , -. .

    , , , - . . ?, . , , "" . T "". wT . f

    f: ... ... T

    , f , , wT.

    , . , , .

  • , , - STACK [INTEGER], INTEGER - , - . INTEGER, (,, " " . .), . . : n:[Z1]n + 1 n

    n , . . item(new), new - . n wINTEGER . n+1? wINTEGER , wINTEGER:

    wINTEGER + 1 = wINTEGER.

    . wINTEGER+1 , "" q, , , !, wINTEGER n + 1 n wINTEGER, Z1. , wINTEGER+p wINTEGER p. , (INTEGER, ) , , wINTEGER, wINTEGER. .

    . , ( - ). . , , , , . , . .

    ?

    , : - , , ? , (, ), : " , ?" : , ? , - . , , - , , , . :

    (, ), , . , , , , : ?

    , . , . , , , . , , , ,

  • . ? " " - , .. , , , . , STACK , x G, :newput (new, x)item (new) - , . .empty (put (new, x)stackexp - . put (x) put (x, new) , : put - STACK [G] G. item (new) , new item. , . .: f(x1 , ... , xn) - , . , xi ( ) f, . "" " ". " " - , , , , , , ,, . , put (x) ( , ), item (new) , . , , ( , ), - , , 0 . -, . :empty (put (put (new, x1), x2))item (put (put (new, x1), x2))stackexp

    - , ( ) , . , BOOLEAN, - G , STACK [INTEGER], INTEGER.- , , . , , , . , , , , , , :empty (put (put (new, x1), x2)) = Falseitem (put (put (new, x1), x2)) = x2stackexp = x4

    , ,

  • , , , , - . . ( ).: T , expr :

    (S1) , expr .(S2) expr - - S1 , expr , T.

    S2 expr f(x1 , ..., xn), f - , empty item . S1 , expr , , , , ( BOOLEAN G). , , . , . : , ? , , , - , . , ; STACK , . S2 expr, , ? . , :: , expr . . - : ( ), ().

    ( ). , , . , , . . , . - , , STACK . . S1 S2, , , e:

    (S1) , e .(S2) S1 e item empty (.. -), e BOOLEAN G STACK [G] STACK.

    , - item empty, . . , new, put remove.

  • , S1 ( ).- S2 . S1 : e, item, empty, , ( ) . "" , put remove. :: , item, empty, :

    (W1) new 0.(W2) put (s, x) ws + 1, ws - s.(W3) remove (s) ws- 1, ws - s.

    , , , put ( ), remove ( ). , , , . , put remove, item empty. , , . : e - , item empty. empty (e) , e 0. ( ). , empty: x: G, s: STACK [G]

    (A3) empty (new)(A4) not empty (put (s, x))

    0 ( ) e new, 0 , new . A3 , empty (new) . , . : , n. , e n+1. -, e :E1 e = put (s, x)E2 e = remove (s)

    x G, s n. ws - s. E1, put - , e , s, . . ( ) , s . , e , . , e ws+1, ( A4) , .

  • E2 e , :EB1 _ s .EB2 _ not empty (s) ( remove).

    EB2 , s ws , , e, ws - 1, . , e . , , , e , 0. s , s put, e. put e, remove ( remove e). , e ( , e) remove (put (stack_expression, g_expression)),

    A2 stack_expression. e 2, , , e, . E2. , , - item empty, remove, .. , , , A2, , put new., :put (remove (remove (put (put (remove (put (put (new, x1), x2)), x3), x4))), x5)

    , :put (put (new, x1), x5).

    : , - item empty, , remove (.. put new>). A2 , . , , , -, , , S1 ( ). , -, S2 ( -). , f(s), s - , f - item, empty. . n- s. n=0, s new, , , . - :

    empty (new) (true) ( A3);item (new) , item not empty (s) .

    : , s n 1. - u s item empty, u n-1, u , u , , . , s , put, remove new. , remove, s put new. , s new , , s put(s', x) . :

    empty (s) A3 (false);item (s) , not empty (s) item ; A1, x.

  • , - , , - - BOOLEAN G.

    () . , . , .. . , , . . . , , .- - . . , , . , ; -. , . , , -. "" . . , , ; .

    , 1970-, . " "[Hoare 1972a], , , 3., , . [Liskov1974]; [M1976] [Guttag 1977]. ADJ (, , ) , . , . [Goguen 1978], . . ADJ CLEAR [Burstall 1977] [Burstall 1981] OBJ-2 [Futatsugi 1985]. . Larch, , [Guttag 1985]. Z [Abrial 1980][Abrial 1980a] [Spivey 1988] [Spivey 1992] VDM [Jones 1986]. Z -, . , Object Z [Duke 1991] . 11. " " , . , "" [Dijkstra 1976]. [Guttag 1978] ( 1975.) , , [M 1982] (, ,).

    6.1

  • , (POINT), . : , , , , .

    6.2

    - - , . , . , : , b, . . : _, , . (: "", "", .)

    6.3

    " " " ", " "," ", "", " ". , ? (: ).

    6.4

    . _. -, .

    6.5

    , .

    6.6

    , . . ( , , ).

    6.7

    , . , .

    6.8

    , count ( ), change_top ( ) wipe_out ( ). .

    6.9

    , . (: - put ).

    6.10

    ( - ) , . . (: item remove , put (s,x) , s ).

  • 6.11

    ( , ). , . ( ) , . (: , ).

    6.12 -- BOOLEAN

    BOOLEAN , . , (= ) .

    6.13

    ( , ). , , , . , , , , .

    6.14

    , .

  • - 7. : : , , - . , , - . - - . , , ! C -, . ( ) . - .

    , - ? , "". , . , Cobol, , Pascal , C , . -. . . ( .) - , . () , - . , , . , , , - . , , , (instances) . - . - , ., STACK, , , - .