Вы находитесь на странице: 1из 768

-

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

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



(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)

2
30
30
30
31
32
32
33
33
35
35
35
37
37
37
38
38

39
40
41
41
41

41
41
42
42
42
42
42
43
43
43
44
44
44
44
45
45
45
46
46
46
47

47
47
47
48
48

(browsing)

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

?


(design patterns)



NIH


48

48
48
49
49
49

49
49
51
51
53
54
54
55

56
56
57
57
58
59

61
61
62
63
64
67

69
69
69
69
70
70
70
70
70

72
72
73

73
73
73
74
75
75

76
76
76
77
78
78



? (The reuse-redo dilemma)


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



( )
(genericity)
:







-


:

79
80

80
80
81

82
82
82
82
83
83

86
86
87
88

89
89
90
91
92

92
93
95
95

96
96
97
98
99
100
100
101
101
102
103
103

103
104
104
104

104
105
105
106
106

106
107
108
108
109

110
111

111
111
112
112
113

113


(Genericity)



,

114
114
115
117
117
118
119
119
120
120

122





, ?
-

6.1
6.2
6.3
6.4
6.5
6.6
6.7
6.8
6.9
6.10
6.11
6.12 -- BOOLEAN
6.13
6.14

122
122
123
123
124
125
125

125
126
126
127
128
128
129
131

134
134
134
134
135
135
135
135
135
135
135
135
135
136
136
136
136

, -



137
137
138
138
138

138
139



POINT

139
140
142
142

143



indexing


143
144
144
144
145
145

146






Current

-

146
146
147
148
148
148
149
149

152




""

main

"Hello"
:


?






:

152
152
153
153

154
154
154
155
155
156
158
158

159
159
159
160
161
162
162
163
163
165

165

7.1 POINT
7.2 POINT
7.3

?


- BOOK

166
166
166
166
166

167
167
167
168
168
169
170
171
172
172
173

174


: " "

174
175

176

176
176
177
178

178
179
180
180
180

181

181
181

182



void



:

: -

182
184
184
185
186
187
189

191
191
192
193
194
195
195

196
197
197
198

8.1
8.2
8.3



-
-

()
?
?
, ,

:
,





"--"
(Advanced)

198

199
199
199
200
200
201

202
202
203
204
205

205
205
206
206
206
206

207
207
209
209
209
210
211
213
215
215

216
216
216
217

217
218
218
218

219
220
221
222

223
223
223

223
225
225
226
226
227
227

228

MEMORY

228
228
229

229




(Bulimia and anorexia)

9.1
9.2 ?
9.3
9.4

229
230
230
230
230
231

231
231
232
232
232
232
232

233
233

234
234
234

235


: -

235
236
236
236
236
237
238

238
238
239
239
239

240
240
241
241
241

10.1
241
10.2
241
10.3 241

242
242
243
243
244



() :



()

: ?

245
245
245
246
247
247

247
247
248
249
250
250

251
251
253
254
254
256
257

260
260
261
262
262
262
263

263

264
264
265

266

266
266
266
267
267

269
271



:

?

271
272
273
275

277
277
277
279
280

282
282
283

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
?

284
285
288

288
288
289
289
289
289
289
289
289
290
290
290
290
290

290
292
292
292
292
293

293
293
294
295
296

296
296
297
298

299
299
300
301
301

302
302
304
304

304
305
306
307

307
307
308
308

308

12.1
12.2 Exception





- (re-architecturing)
: ?


(Assignment)
(Creation)
(Conditional)

13.1
13.2

309
309
309
309

310
310
310
311
311
312

313
315
315
315
316
316
317
318
318
318
319

319
319
319
319
320
320

321
322
322
323
323
323
323

324

324
325
327
328
328
329

331
331
331
332

334

334
335
336
336

?
?

337
337
338
338

339

339
340
340

341



:
,






:
++

14.1
14.2
14.3
14.4
14.5
14.6
14.7 ( )

341
342
342
343
344
344
345

347
347
348
348

349
349
350
351
352
353
353

353
354
355
356
357
358

358
358
358
359
360
360
361
363

364
365
365
365
365
365
365
365
365
366

14.8
14.9

366
366

367

,
?

-
-




367
368
369
370
371
372
375
376
377
377
378

378
378
379
380
381
381
381

382
382
383
383

383


384

384

385

387

388

389
:
:
391390

392

393

394

397

397

398
398
398

399
399
400

15.1
15.2 ?
15.3
15.4
15.5
15.6

400
400
400
400
400
400

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



copy, clone equality


,
-


400
400
401
401

402
402
402
404
404
405
406
407
407
408
409
409

410
410
411
412

412
412
412
413

414
414
415
416
417
417

417
417
418
419
420

420

420
421
423






Current



423
423
424
425
425
426
426
426
427
427

428
428

16.1 :
16.2
16.3 ?

428
429
430
430
430
431

431
431
431
431
432
432

433
433
433
434
434
434

435


:
" "?

435
436
436
437
437


!
,

439
439
441
442
443
443
443

444
444
444
444
445

447
448
448
449

450
450
451
451
453
453

453
454
454


Unique-

:

Unique-

18.1
18.2 unique-
18.3
18.4 ?


:
:

1.1
1.2
1.3
1.4

455

456
456
457
457
458
458

459
460
461
461
462
462

463
464
464
464
464
464
464

465
465
466
466
466
466
466
467
467
467
467
468
469
469

470
471
472
472
472
472
472
472

473
474
475
475
476

477
477

478

478
479
480
481
483

485
485
486


: undo redo


Command



command

: UNDO-REDO

Undo
Redo

486
486
486
487

488
488
489
490
490
491

491
491
492
493
493

493
493
494
495

496
497
498
498

499
499

3.1 ( )
3.2 Redo
3.3 Undo-redo Pascal
3.4 Undo, Skip Redo
3.5
3.6
3.7
3.8 ( )
3.9
3.10
3.11

499
499
499
499
499
500
500
500
500
500
500

" "

501

501
501
502
503
504

504


...






(CRC)

4.1 Floors integers


4.2






,

:
,

?

()

,
?

505
505
505
506
506
506
507
508

508
508
508
509
510
510

510
510
510
511
511
511
512
513

513
513
513

514
515
515
516
516
516

517
517
517
518
519
520
520
521
522
523
523
524

527
527
528
528
529
529
530

530

530
531
532

532





,

:




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)

532
533
536
536
536
537
538
540
540
545
545
545

548
548
549
549
550
550

551
552
552
552

553
554
554
554
554
554
554
554
554
554
554
555
555
555
555
555

556
558
558
559
561
561

561
563
564
564

, ?










, ?

:


:

6.1 ,
6.2

565
565
567
567
567
568
569
569
570
570
571
571
571

572
573
573
573
573
574
574
575
576
577

577
577
578
578

579
579
580
581
581

582
582
583
584
585

587
587
588
588
588
589
589

589
590
590
590
591
591
591

6.3
6.4 ?
6.5
6.6
6.7 ?
6.8
6.9

591
591
591
591
591
591
592

593
593
593
593

593
593
593
594
594
594

595

595
595
595
595

596


:
feature

596
596
597
597
597

598
598
599
599
599
600
601

601
601
602

602
602
604
605
605

606
606
608
608
609
610
610
611

612

8.1
8.2

:

BON (Business Object Notation)

-


()





(curriculum)


" "

612
612
613

613
613
613
613

614
614
614
615

615
615
616
616
617
618
619
619

619
622
623
625
626
626
628
628
630
631
631
632

633
633
633
635
636
636
636
637

638
638
639
639
639

639
640
640
641

( - Object Request Broker)


641
641

642
643
643
644
644
645
645
645
646

646

647
647
648
648

650

650

651

651

652

652

653

654

654
: (Concurrency Control File)

655654
:
656

658


versus
,
,
-

()

658
658
658
659
660

661
661
662
663
664
664
665
665

665
666
667
668
668
669
669
670

670



: "-"
,

(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

670
671
671
672

672
673
675
676
677
679
681
682

683
684
684
684
685
685

686
686
686
686
686
686
687
687
687
687
687

688
688
689
689
689
689
689
689
689
690
690
690
690
690
690
690
690

691
691
691
692
693
693
694
694

-:
Matisse
Versant

: -
"- " ?

13.1
13.2 -

, ,

-

695
695

697
698
698
698
698
699

699
699
700
701
701
702
702
702
702
702

703
703
703

704
704
706

706
706
707
707
707

708
708
708
709
709

709
711

()

711
712
713
713

713

---:

713
714

714
714
714
714
716
717

Ada 83 Ada 95
- Ada 95:
Ada 95 :
:
- Ada

15.1 ,
15.2
15.3 ( Ada)
15.4 Ada
15.5 -


- Pascal?
Pascal
Pascal
- Pascal

Fortran

COMMON

- C




OO C:

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

Simula

717
717
718
719
719
719
720
721
721

722
723
723
723
724

725
726
726
727
728
728

729
729
729
729
729
729
730
730

731
731
731
732
732

732
732
733
733

735
735
735
736
737
738

738
738
738
738
738

740
740


Simula:

Smalltalk


Smalltalk:

Lisp
C
Objective-C
C++

C++:

Java
-

Simula
Smalltalk
C: Objective-C, C++
Lisp
Java

17.1
17.2
17.3
17.4
17.5

740
740
742
742
743
744
745
747
747

748
748
748
749
750

750
750
751
751
752
752

753
754
754
754
754
754
754
755
755
755
755
755
755
755
755

756
756
756
756

756

756
757
757
757
758
758


Bench

758
758
759

761
762

762
762
765

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, AFIPS
Press, 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) - (runtime
system).
- , .
, .
, , ,
( - 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: INTEGER
do
... 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). -
. ,
, , , ,
. , , , -
( , -)
- . ,
,
.

.
- . ,

-
.
, .
-, , ,
. ,
, -
. ,
, .
, ( ),
; , .
:
, , -,
-
- , , .
" " ("information
hiding"), . , , "" ("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 current
balance). , ,
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, ... end
feature
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'), , [Hoare
1966].
[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 ork
applications"). : ,
(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 (UNiversal
COmputing Language - ), 20 . , ,
, . 1988 .
(Advanced
computer environment (ACE) consortium). Java - Java-,
.
. ,
, ,
- .

, . , ,
,
.
, ,

.

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

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

, ? :
, (League for
Programming Freedom): .(.
.)
, (superdistribution),
(Brad Cox) .
, , .
, , ""
, ,
. , -,
,
. JEIDA (Japanese Electronic
Industry Development Association)
.
, ,
( ).
, .


:
,
, .
, ,
, STARS (Software Technology for
Adaptable, 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 data
structures"). ):
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

i :=1

forth

after

i :=i + 1

i >count

c := first_cell c :=c. right c =Void

rewind

read

found (x)
t @ i =x
c. item =x

end_of_file f -=x

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


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

, .
(routine) ,
, ,
, , , .
( - ) (actual
arguments) . ;
.
, ,
,
. , ,
( ) . ,
, ,
( - ) , :
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 ... end
end -- 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
square
square
square

(x:
(x:
(x:
(x:

INTEGER): INTEGER is do ... end


REAL): REAL is do ... end
DOUBLE): DOUBLE is do ... end
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_HANDLING
ELECTRON_TABLE_HANDLING
ACCOUNT_TABLE_HANDLING
:
TABLE_HANDLING [G]
G, , (formal
generic 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, (Biggerstaff
and Perlis) [Biggerstaff 1984],
; , , [Jones 1984], [Horowitz
1984], [Curry 1984], [Standish 1984] [Goguen 1984]. (
) [Biggerstaff 1989].
[Tracz 1988]. (Tracz) IEEE
Computer [Tracz 1995], .
, ,
(MIT Programmer's
Apprentice 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] [Pree


1994].
[Weiser 1987] .
; ,
,
. (Richard
Stallman), (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 Programming
Generically".)
, , [Knuth 1973].
, ,
[Aho 1974], [Aho 1983] [M 1978].
.
Reusable Software [M 1994a], ,
,
. Object Success [M 1995]
, , ,
, , , -,
(, ,
). , [M 1996].
1)

[Gamma 1995]; [Pree 1994].


ISE C, -.
3) i, - c.
4) 15 " -
", Ada. , "Ada"
Ada 83. ( Ada 95 , .)
5) , , ,
Ada-, Ada. REAL Ada FLOAT;
.
2)

-
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
end
end
( . .)
.
,
, , -
.
: -,
(
), -, (..
).

, .
-
.

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

:
.
,
( ).
, .
.
[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], [M
1987], [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: INTEGER
representation: 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]


item: STACK [G]
empty: STACK [G]
new: STACK [G]

STACK [G]
G
BOOLEAN

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

. ,
.
, .
- ,
,
. , R ,

square_plus_one: R
R
square_plus_one(x)= x2 + 1 ( x R)
square_plus_one, R
, 1.
. , put

put: STACK [G]

STACK [G]

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

. 6.3. put
, ,
, .
, ,
- ,
"" .
. ,
, .
, STACK:
put ,
. put(s, x),
s x.
remove ,
. put,
(, , ). ,
, .
item , .
empty , (
). , BOOLEAN, , .
new .
, -
. put
STACK [G]

STACK [G]

, put <s,x>, 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
R
square_plus_one (x)= x2 + 1 ( x R)
, ,
. ?

square_plus_one, ,
.
, , ,
_.
, STACK - <count,
representation> , representation - , count -
. put ( x G) :
put (<count, representation>, x)= <count + 1, representation [count+1: 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) = true
A4' empty (put (s, x)) = false
,
. "":
, .

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

, ,
:
. , remove item:
, .
, , ,
. X Y
, X. , ,
.
inv, x
inv(x)= 1/x.
inv x = 0, R
:
Inv: 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
, ch(x) , x A, .

BOOLEAN


(PRECONDITIONS)
STACK. , .
.

(TYPES)
STACK [G]
(FUNCTIONS)
put: STACK [G] G

STACK [G]

remove: STACK [G]


item: STACK [G]
empty: STACK [G]
new: STACK [G]

STACK [G]
G
BOOLEAN

(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 = new
s2 = put (put (put (s1, x1), x2), x3)
s3 = remove (s2)
s4 = new
s5 = 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>,
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]

STACK [G],

, , .

, . , put ,
G ( ) ,
, .
, . (
"" "").
. A1 A4,
(A1) item (put (s, x)) = x
(A4) not empty (put (s, x))
, (routine
postcondition), ensure ():
put (x: G) is
-- x

require
... ( ) ...
do
... ( ) ...
ensure
item = x
not empty
end
, put item x
( ), empty .
, .
,
(. 11.10 " ").
, ?
, , ,
, , , , .
, , ,
- , , - .
: . , :
( - ), ,
... ! ?
. , , .
, ,
: ,
. - :
- .
.
- -
. , :
, .
-
-: ,
: " ,
, ". ,
:
- ( 2)
- -
( ) .
. :
.
( ),
- .
, " "
, , ,
- .
-
.
: "
" .


,
.

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



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

, ,

.
,

x: POINT

REAL

y: POINT

REAL

, Pascal:
type
POINT =
record
x, y: real
end
: , POINT
x y REAL. , :
Pascal : , POINT
.
. , POINT
x y, , ,
.
,
POINT :
POINT

REAL

REAL,

" " (" "), POINT.


POINT
, POINT, ,
.
,
, ,
<x, y>.
.

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

( ) , -
.

,
, .
, :
class POINT feature
x, y: REAL
end
. ,
, - ! :
( ) - ,
:
class MOVING_POINT inherit
POINT
feature
mass: REAL
velocity: VECTOR [REAL]
end
. (
, ) POINT,
p1: POINT
POINT, ,
MOVING_POINT. , , " "
:
p1 := mp1
mp1 MOVING_POINT.
:
, . . POINT,
, , .
(), (
), , ,
-.
.

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

f: ... ...

, f ,
, wT .
, . ,
,
.

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

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,
:
new
put (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)) = False
item (put (put (new, x1), x2)) = x2
stackexp = 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.
, ,
. [Liskov
1974]; [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,
, , . POINT, .
, POINT
x, y - .
"" "".
.
, , .
.
,
- .
, -,
.


, . ,
. ,
, -
, . . - -
"" . , - ,
. ,
.
-, Smalltalk,
(metaclass). - , . " ",
, " ". ,
.
, , ,
. , ,
.
:
, .

, , - ANY,
.
, , , ,
. .
-, ANY,
. ,
.
- ,
, .. .
E_CLASS, .
C
C,
E_CLASS.
.
- .


, ,
, ,
.
- , ,
- . .

, , - , , ,
, - ,
.
- , . ,
, (. 3).
, .
, ,
. , Ada
, Pascal . ,
,
. , ,
.
( ,
.) , ,
.
.
- , .
, INTEGER CHARACTER,
: (), , ( Pascal), .
, ,
, .

- .

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


- ,
.


, (
, ), - ,
,
(INTEGER, REAL, DOUBLE, BOOLEAN, CHARACTER).

. ,
, ,
. .
, .
.

. , , INTEGER
, "+", , ""="
, .
,
. ,
.
- INTEGER, REAL DOUBLE ;
NUMERIC, ("+", "-", "*"); COMPARABLE,
("<" ).
MATRIX, . MATRIX
[INTEGER] , MATRIX [REAL]
.
MATRIX [NUMERIC],
INTEGER REAL T, NUMERIC.
-
.
. INTEGER BOOLEAN
, .
, . ,
; ,
(a < b -a a.less_than (b) a.negated);
, ,
. , MATRIX , ,
.


, , ,
, .

. 7.1.
POINT -: x, y, , . (
rho theta). x

( ), y - ( ), -
, - , . x y , . distance,
.
, translate (
), rotate ( ) scale
( ).
,
. :
x: POINT

REAL

translate: POINT

REAL

REAL

POINT

:
x (translate (p1, a, b)) = x (p1) + a
, p1 a b <a, b>
a.
, , .
, , , ,
. - .

POINT ,
. , , (features) , .
6 , : (queries), (commands)
(creators). , ,
- (by space or by time). (. "
", 6)
.
- . ,
x y :

. 7.2.
p1 , x y
. (x2 + y2 ) arctg
(y/x) ( x).
(. 7.3) .
, x y ( cos, sin,
).

. 7.3.
:
, ,
. (attributes). ,
, x y,
rho theta.
,
(), .
(routines). - rho theta
, x y .
- - .
, (functions). x y
, rho theta - ,
REAL. , ,
(procedures). , POINT translate,
rotate scale.
"", , ,
.
.
. 7.4 , :

. 7.4.
, ,
.
, ,
:

. 7.5.

.
, p1, ,
p1 - , .
?
, - ,
POINT , , POINT.
. ,
. ,
, . x p1,
, .
(Uniform Access principle),
( 3). , ,
, , -
( , ).
. ,
x p1 :
p1.x
, .
,
. ,
, .
.
,
. (. " : ", 11)
Pascal, C Ada ,
. - ( 1966 . Algol W Pascal
). , C++ Java, .
, (
)
. .
.
, ,
, .
, .
POINT

POINT. , "--",
, . ,
, .
indexing
description: " "
class POINT feature
x, y: REAL
--
rho: REAL is
-- (0, 0)
do
Result := sqrt (x^2 + y^2)
end
theta: REAL is
--
do
-- (. 7.3)
end
distance (p: POINT): REAL is
-- p
do
Result := sqrt ((x - p.x)^2 + (y- p.y)^2)
end
translate (a, b: REAL) is
-- a , b
do
x := x + a
y := y + b
end
scale (factor: REAL) is
-- factor
do
x := factor * x
y := factor * y
end
rotate (p: POINT; angle: REAL) is
-- p angle
do
-- (. 7.3)
end
end
.
, ,
feature. , indexing (description),
, .
: inherit - ; creation -
; invariant - .
feature.


POINT , .
.

x y REAL , ,
.
is
do
... ...
end
, . rho, theta
distance REAL ,
rho: REAL is ...

. , translate scale,
( : T, T ) , , .
x y , rho theta ,
.

( do) .
Algol-Pascal, .
,
. (. "
", 8 " - ")
POINT .
":=" , Algol Pascal.
"=", , , .
. ,
"--". , ,
, .
(header comment).
is POINT.
.
,
, . x y.
indexing
, indexing.
, description. indexing
, .

index_word: index_value, index_value, ...
index_word - ( ), index_value (, , ..) (. " indexing", 4).
:
.

( , , ..)
, .

index_value.( 18 " - "
-.)
- description, - ,
.
description.
indexing, ,
.
indexing
(Self-Documentation principle): , ,
. (. "", 3)

rho, theta distance POINT .
, (, )
, ,
. , ,
(entity) Result. ( .)
, rho
Result := sqrt (x^2 + y^2)

Result - , . ,
T, Result
, .
Result .
( ),
Result ,
T. REAL :
non_negative_value (x: REAL): REAL is
-- x>0; x<=0
do
if x > 0.0 then
Result := x
end
end
( ), ,
else.
Result
, . ,
-.

.
, , , .
,
8 " - ".
"" . , , .
, , ,
.
. ,
, .
.
, , , , .
, ,
( , . .)
, .
, , , .
.
,
( 8 " - ").

POINT, , rho distance
sqrt. , ,
?
,

, , , ARITHMETIC. ,
, .
POINT
class POINT inherit
ARITHMETIC
feature
... ...
end

. - , - sqrt
, , , REAL.
, .

"" , ARITHMETIC. (. "


", 6 " - ".)

-
POINT ,
. ,
- .

, translate:
translate (a, b: REAL) is
-- a , b
do
x:= x + a
y:= y + b
end
- a b
a x, b y.
. , . x y,
a b? - .
, .
, .
.
" " , " ".
- .
.
Current
. Current .
Current , distance ,
, p ;
. distance :
distance (p: POINT): REAL is
-- p
do
if p /= Current then
Result := sqrt ((x - p.x)^2 + (y- p.y)^2)
end
end
/= .
else, p = Current.
, ,
Current . x translate " x
" .
, - , - "Current"?
, ,
- .

, Current, ,
. , -
. - ,
.
, , POINT. -
. ,
(client) POINT. ( 14-16.)
S, - S.

: ,
S . C (client) S, a:
S. S (supplier) C.
a C, ,
C.
, POINT x, y, rho, theta distance
REAL. , POINT. :
class GRAPHICS feature
p1: POINT
...
some_routine is
-- p1.
do
... POINT p1 ...
p1.translate (4.0, -1.5)
--**
...
end
...
end
"--**" p1 ,
POINT. , , x
= 0, y = 0:

. 7.6.
, p1 (attached) (
). , ( "...
POINT ..." ).
. , p1
( ).


p1.translate (4.0, -1.5)
,
- (basic mechanism of object-oriented computation).
(feature call). -
.
translate POINT p1
4.0 -1.5, a b translate .
.
x.f
x.f (u, v, ...)
x (target) ,
. x, , ,
C, , f C. ,
f , - .
u, v, ... (actual arguments) ,
(formal arguments)
f C.

, f () , .
(. 7),
.
:
f x
f , x,
f ( ) .

? , ,
translate, . ,
, :
translate (p1, 4.0, -1.5)
- . -
, ( p1) ,
( 4.0 -1.5) .
- .

- -

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

,
-. ,
( ).
. ,
, (
, ) (
). POINT :
-
POINT, ,
POINT,
(services), ,
, -.
Current
,
.
, (translate POINT)
Current.
, ,
(, x translate) . ,

p1.translate (4.0, -1.5)


x translate,
x := x + a
: "x p1".
Current, .

Current , p1.
Current .
(Feature Call principle):

(F1) .
(F2) .

, - .
, .
:
x.f
x.f (u, v, ...)
(qualified),
, .
, .
, POINT transform,
translate scale . translate scale:
transform (a, b, factor: REAL) is
-- a , b ,
-- factor .
do
translate (a, b)
scale (factor)
end
translate scale.
. (unqualified).
F2 , .
. transform
, translate scale .

do
Current.translate (a, b)
Current.scale (factor)
, Current ( ,
).
.
.
, . ,
translate x x + a x .
- x Current.x+a.
:
f
:
f (u, v, ...)

:
Current.f
Current.f (u, v, ...)
. , f
(
- ). f ( ).
-

:
x + a
- (operator feature).
, , . ,
, , . -
- .
, x + a ( x), .
, , + x a
REAL. , -
. , , ,
.
REAL.
( 7) , - .
, REAL, , , POINT.
, REAL . :
(, , ...), ( ,
...). , :
indexing
description: " ( !)"
class REAL feature
plus (other: REAL): REAL is
-- other
do
...
end
minus (other: REAL) REAL is
-- other
do
...
end
negated: REAL is
-- ,
do
...
end
less_than (other: REAL): BOOLEAN is
-- other?
do
...
end
... ...
end
: x + a.
:
x.plus (a)
, -x x.negated.

- Lisp
. : Lisp
. ,
, . .
(
, )
.
x + a
REAL.
plus , , .
, :
indexing

description: "Real numbers"


class REAL feature
infix "+" (other: REAL): REAL is
-- other
do
...
end
infix "-" (other: REAL) REAL is
-- other
do
...
end
prefix "-": REAL is
-- ,
do
...
end
infix "<" (other: REAL): BOOLEAN is
-- other?
do
...
end
... Other features ...
end
- infix prefix. ,
( distance plus),
( , " ". . " ".)
infix ""
prefix ""
(+, -, *, <, <= .).
, plus, minus less_than
REAL.
.
, - (operator features),
(identifier features). .
- infix "" prefix "", .
- :
u v
:
u
- . plus (y)
REAL Current + y.
Current.plus (y) , .
-
, .
REAL, , -,
VECTOR "+".
, -, . , ,
:
+ - a / < > = \ ^ @ # | &
, , .
,
:
not and or xor and then or else implies
(INTEGER ) :
: + - not

: + - a / < > <= >= = // \\ ^ and or xor and then or else implies .
// , \\ - , ^ -
, xor - "". BOOLEAN and then or else and or (
), implies : a implies b ( not a ) or else b .
, "", .
.
ARRAY - "@" ,
. i- a @ i.
POINT distance - "|-|"
p1 and p2 p1 |-| p2, p1.distance(p2).
, ,
.
-
.
INTEGER .
a + x ,
, C, Pascal, Ada , "+"
.
,
, , .
, -.


. , ,
,
.
.
- ( 5
" - ").
, -.

.
class S1 feature
f ...
g ...
...
end
f, g, ... S1. , C x S1,

x.f ...
, f.

h,
feature.
class S2 feature
f ...
g ...
feature {A, B}
h ...
...
end
f g - . h A B,
( ). , x S2

x.h
A, B .
, i ,
( (. S5).):
class S3 feature { }
i ...
end
x.i(...) . i
i (...)
S3 . .
-,
, h, , .
.
.

.

i .
( (. S5).)
class S4 feature
exported ...
feature {}
secret ...
end
secret , exported - . feature {}
feature . ,
NONE ( .)
class S5 feature
... exported ...
feature {NONE}
... secret ...
end
NONE .
. , ,
NONE, . S4 S5
, .
.
""

indexing
: " ( . )"
class S6 feature
x: S6
my_routine is do ... print (x.secret) ... end
feature {NONE}
secret: INTEGER
end -- class S6
x S6 x.secret .
, secret ! ,
S6, - secret
x.secret. .
: feature {NONE} feature {S6} ,
.

.
, ,
print (x.secret). , secret print
(secret) . , ,
.
.


- ,
.

, , ,
. ,
. ,
, p1 :
p1.translate (u, v)
: p1? .
, GRAPHICS, p1 GRAPHICS.
, p1 Current.p1. ,
, Current ! ,
, GRAPHICS, .

. , ,
-.
:
(F1) .
(F2) .
:
: f (a, b, ...);
: x.g (u, v, ...) .
. r
r. , - OBJ.
- t. ,
, - :
(T1) t OBJ.
(T2) x , x - OBJ- , , ,
- t.
(T3) x - , (),
t.
(T4) x - r, x,
, t.
, , ,
OBJ. , OBJ ! ,
( : , , ...) -
.
, ,
- . , :
:
- :
, .
, , .
.
, - .
(

) .
, , Current .
, , .
. r- , r OBJ.
r Current :
(C1) r , (, ),
.
(C2) .
(C3) x.f ... , x.
OBJ, x, T1-T4.
OBJ.
C2 C3
, .
, ,
. , ,
, . - ,
, ,
, .

- -.
.
. :
CS, (class set) .
CS, (root class).
, (root creation
procedure) .
. ,
, CS. (system
closure) .
, :
D C , C D.
: C D, D.
E C, , C E, D
, D (, ) E. ,
, ,
C, - E.
.
:
,
.
, , ,
. ,
. , .
(assembly)
.
main
, , -,
. ,
?
. :
, .
.

, , .
. - .
, -
(Thread) .
.
.
. ,
.
.
, , ,
.
.
, , - "
?". ,
. - ,
.
.( . " ", 5)
.
. .
,
. ,
.

?
, .
(, ) :
(A1) .
(A2) (universe) , , .
.
(1) .

, , . ,
.
, ,
.
Lace. , , Lace . Lace ,
, .
Lace, Ace:
system painting root
GRAPHICS ("painting_application")
cluster
base_library: "\ library\ base";
graphical_library: "\ library\ graphics";
painting_application: "\ user\ application"
end -- system painting
cluster , .
. - , . (
10 " - ")
, Windows, VMS Unix, . . (),
" ", , , ,
, .

. 7.7.
. Lace :
, base_library, , - "\
library\ base". Windows (\dir1\dir2\ ... )
. Unix
.
. , Lace
,
.
, cluster, .
,
. - NAME name.e
( ). ,
name.e , cluster.
root Lace .
GRAPHICS painting_application.
GRAPHICS, .
, , Ace.
, .
GRAPHICS graphics.e painting_application,
\user\application. GRAPHICS, ,
GRAPHICS .
, ,
GRAPHICS.
.
, "Make-", ,
(" Include" C C++).
. ,
-
.

Ace, cluster (,
, . .) .
Lace.
,
Ace, - painting.
,
, .
- . , Lace
,
.
Lace

. , ,
,
.
"Hello"
, ,
. , "".
.
, :
class SIMPLE creation
make
feature
make is
-- .
do
print_line ("Hello Sarah!")
end
end
print_line ,
. print , .
GENERAL, . (
GENERAL . " ", 16)
, :
(E1) simple.e.
(E2) .
(E3) Ace ,
- SIMPLE, - my_first .
(E4)
my_first.
(E5) my_first. my_first.
my_first
.
:
Hello Sarah!
:
- . ,
, . :
[A]
x.g (u, v, ...)
r C , x .
? C ,
Ace. , .
,
C_OBJ - C, :
[B]
a.r (...)
a C_OBJ. [A] g ,
, x C_OBJ.
, , ,
. , . , ,
, .
,
.
, ,
, . , .
, . ,

.
.

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

,
. ,
.

- . .
, .
procedure function. ,
, . :
f ...
.

g (a1: A; b1: B; ...) ...
, g , . :
f: T ...
g (a1: A; b1: B; ...): T ...
- f , .
g . f
, T. , f , :
my_file: FILE
is, (do once external,
), :
f: T is
-- ...
do ... end
f - .
f: T is some_value
f - (constant attribute), some_value. (-
18)
,
. ,
. .
?

- . (." ", 3. . .)
,
. ,
, ,
.

PERSON, INTEGER .

Isabelle.age
, age - PERSON,
Isabelle. age , ,
, birth_date .
, PERSON.
,
, .
, .
. 7.4 . 7.5,
. . 7.5 -
, . . 7.4
- .

, :
. ,
, ,
. (. " : ", 11)
,
. ,
, -
. (. " ", 14)

.
POINT x y , rho theta.

my_point.x my_point.theta.
, -.
Smalltalk, () ,
() .
Smalltalk,
, . POINT internal_x, internal_y
abscissa ordinate. Smalltalk
, .
class POINT feature
-- :
abscissa: REAL is
--
do Result := internal_x end
ordinate: REAL is
--
do Result := internal_y end
... ...
feature {NONE}
-- :
internal_x, internal_y: REAL
end
:
, abscissa ordinate.
, ,
, .
,
. ,
. ,
, ?
, , .
,
. ,

, .
( ),
( ) ( ).


my_point.x. .
(: - .):
my_point.x := 3.7
. attrib , a.attrib , .
, , a + b.
attrib :
set_attrib (v: G) is
-- attrib v.
do
attrib := v
end

(: . .)
class C feature [AM]
...
feature [A]{D, E}
...
A , M - .
set_attrib.
.
. ,
, , +1 -1:
class COUNTING feature
counter: INTEGER
increment is
--
do
counter := counter + 1
end
decrement is
--
do
counter := counter - 1
end
end
POINT x
y. translate scale.

a.attrib := some_value. some_value
.
set_polygon_size (new_size: INTEGER) is
--
require
new_size >= 3
do
size := new_size
end
3 .
.
,
(. 7.8).

. 7.8.
0 . 1 .
2 . 3
, , . 4
.
, , .
( 1).
. , ( 2),
(3) (4).
, -:
Smalltalk 1
abscissa and ordinate.
.
C++ Java . ,
4 my_point.x := 3.7.

2 4 1. Smalltalk. 3
.
:
.

2 3 my_polygon.set_size (5)
. , 4
. my_point.set_x (3.7)
, my_point.x := 3.7, .
ISE
.
,
-. , ,
. ,
.
, .
, Ada C++, ,
. ,
.
,
.
, ,
. , .
.
, .
,
.
.
, ,
, .
C++ Ada.
- . (. "
", 9, " C++ ", 14)

, -.
,

. , ,
, .
,
. - Ada Java -
. , ,
.
.
Simula, . .
.
,
. , . ,
, .
, .
.
.
( 10 " - ").
. ,
- .
, ,
. ,
.

, feature, , .
, , , ? Modula-2 ,
, import.
, - . f
C, . ,
f
a.f
a:
a: C
, f C.
, .
, import. (" ", 11)
,
, .

,
. , -.
- , .
. ,
,
.
Result.
, ,
Result. ,
Result .
f: INTEGER is
do
if some_condition then Result := 10 end
end
10 some_condition 0 (
INTEGER) . , Result

.
- Borland Delphi. , ,
, Result .
:
(A) return (C, C++/Java, Ada, Modula-2).
(B) (Fortran, Algol 60, Simula, Algol 68, Pascal).
A return e , , e
. ,
. :
(A1) ,
.
.
(A2) .
.
(A3) , ,
, return. Ada .
, return ,
, :
function name (arguments): TYPE is
do
...
return
expression
end
return . ,
, A1 .
B .
. ,
A1.
. ,
, .
: . ,
, . f, f
,
f := x
f ,
x := f
f .
f := f + 1
f ,
, f.
, f ,
.
.
, Result, A B. ,
, Result,
. , ,
, . ,
do
if some_condition then Result := "Some specific value" end
end
else. , .
.
Result (. . 11).
Result ,
. :

prefix "|_": INTEGER is


--
do
... ...
ensure
no_greater: Result <= Current
smallest_possible: Result + 1 > Current
end
ensure , :
, ,
.
:
,
. , .
, , ,
, . :
: (entity)
:
(E1)
(E2) , Result
(E3)
E2 , Result .
local. Result
.
, (E3), ,
x x := some_value.


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

.
. .
Lace.
Lace, Ace, ,
.
Make- Include.
.
. ,
.
.
.

.
- - .
.
- .

. ,
.


Simula 67 (. 17 " "). Simula ,
Simula.
,
: (currying). f
g , .
x y:
(g (x)) (y)= f (x, y)
, , .
rotate, :
rotate (some_point, some_angle)
, :
some_point.rotate (some_angle)
[M 1990] , ,
.
( 14 " - ").
,
.
. Self [Chambers 1991],
"".
, , [M 1992].
James McKim Result (
).

7.1 POINT
.
7.2 POINT
POINT. , rotate
( ), , .
7.3
POINT ,
, .

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

- .
. .
?
, "".
( , . 7):
:
-
, C, ,
, C, - , ,
C. , POINT , ,
x y .
.
-. ""
. , "":
, , ;
.. , , .
EMPLOYEE , .
"" -,
. (direct
mapping), , , . ,
, . (. " ", 3)
"" "".
. ""
, . :
. ,
, .
.
,
, .
STATE, , COMMAND. (. 20
21 " - ")
"" , ,
. , , -
.

, , .
O - . . ,
(direct instance) , C.

O , - C.
; . ,
, "" .
C (generating class) (generator) O.
, C- , O - ,
.
C . ,
, .
POINT ( POINT . 7). :
class POINT feature
x, y: REAL
... ...
end
, .
x y REAL, , - ,
:

. 8.1. POINT
- - ,
. ( - POINT). ,
- (x y). ( P_OBJ),
, .
, - ,
. .

POINT REAL. , POINT
.
, "" . ,
. (,
) :
BOOLEAN, , true false;
CHARACTER, ;
INTEGER, ;
REAL DOUBLE, .
STRING, , .
, . ("", . 13)
. :
BOOLEAN True False.
CHARACTER : 'A'.
STRING : " ".
INTEGER : 34, -675, +4.
REAL DOUBLE : 3.5 -0.05,
: -5.e-2.
- BOOK

:
class BOOK1 feature
title: STRING
date, page_count: INTEGER
end
:

. 8.2. ,
,
, .
, Pascal C.
, , ,
. Pascal C

(: ! .):
b1: BOOK1
...
b1.page_count := 355
page_count , b1, 355.
.
. ,
. - ,
, .
BOOK1.
b1.page_count := 355 C++ Java ,
C.
Java , ,
.
, : " ". ,
.
- . ,
, .
, , ,
.
, .

, WRITER :
class WRITER feature
name, real_name: STRING
birth_year, death_year: INTEGER
end

. 8.3.

, . , ,
WRITER.
. BOOK2 , WRITER.

. 8.4.
, , , ,
.
, . BOOK2
. :
.
, .
. , .
, . ,
WRITER
- .
, .8.5 . , BOOK3.
BOOK3 author (reference) WRITER.
.

:
. (void) (attached).
( ).

. 8.5.
.8.5 author BOOK3 WRITER. ,
, .
, .

. 8.6. , ( (Candide) )
- . ,
.
, , .
, .
. , , , .
.
, .
Pascal Ada ( C). , .
- .
, .

. , , . :
(I1) .
(I2) , ,
.
"a , b".
(I1)
(I2). ,
, " ". (I1)
( ) , .
I2 , .
"" , , -
.
(1832 date BOOK3 .8.6 ).
, , .
BOOK3 , title, date, page_count,
author. .
, (persistent),
. (. " ", 13 " - ")

BOOK1 , BOOK3, ,
.
class BOOK3 feature
title: STRING
date, page_count: INTEGER
author: WRITER -- .
end
author : WRITER.
:
class C feature ... end
C
x: C
, C. ,
, .
.

O1 ,
O1. . .8.7 , name:
"Almaviva", ( ). ,
( ).

. 8.7.
,
.
class PERSON1 feature
name: STRING
loved_one, landlord: PERSON1
end
(PERSON1 - PERSON1).
- ,
.
class PERSON2 feature
mother, father: PERSON2
end
.
, ,
.

-
.

. 8.8.
. ,
.
, ( ).
, . .8.8 TYPE1
, - .
( TYPE4) ( TYPE5).
( TYPE2, TYPE1).
. ,
, : " ".
. ,
. ( "", " ").
,
. ,
- . "" ,
.
,
.
.
.
, .
, ,
. . -
, .
, .


- .
, , : ,
.

, -,
:

, - ,
.
, .
, , - (" ", " ").
, ,
, .
.8.9.

. 8.9.
( )
( , ).
.
loved_one loved_one,
.
"",
, . ,
<x, y>, x y
TX TY. x TX, y - TY.
, ,
. ""
, ,
.
11,
, - . (.
" ", 11)
: " "
" ", -
" ".
. "
"; -. ""
, , .
-, . ,
, , . ,
- ,
. ,
, (, ) , -
- ? (. 2)
-, ,

. C, Pascal. "" C.
, ? ,
, . (. 6)
. .
,
. .
.
, . " " -
. , , .
,
, ,
.
. .
.
, .
. ,
- .
. ,
, .
, -, ,
, , " ".
, , ,
, - , , ,
. ( - , , , .)
, : ,
. .
" "
(cousin twice removed).


, ,
.

,
-.
Fortran Pascal . -,
, . ()
, ,
.
, , .
, ,
.
,
.
, ,
, .

BOOK3. ,
BOOK3, , :
class QUOTATION feature
source: BOOK3
page: INTEGER
make_book is
-- BOOK3 source.
do
... . ...
end
end
. :
, .
QUOTATION ( )

. , ( - ,
source) . ,
QUOTATION BOOK3.
, , - .
, , , . make_book :
make_book is
-- BOOK3 source.
do
create source
end
: create x , x - (enclosing)
, , .
.
x, ( source), (target) .
" ". , ,
. :

create x , x , C,
:
(C1) C( , C). OC -
.
(C2) OC .
(C3) x () OC.
C1 C. C2 ,
:

- .
BOOLEAN - False.
CHARACTER - null.
( INTEGER, REAL DOUBLE) -
.
, source BOOK3
class BOOK3 feature
title: STRING
date, page_count: INTEGER
author: WRITER
end
create source, make_book QUOTATION,
.8.10.

. 8.10.
. author title STRING,
. STRING, , , , . ( .
13)

. BOOK3
:
(B1) QUOTATION. Q_OBJ - a,
, Q_OBJ.
(B2) B1 a.make_book make_book
Q_OBJ .
- Q_OBJ ( B1)? , , .
: - .
, .
- - .
, ; ,
objectus ex machine ( ). , ,
, .
, .
, ,
, , ,
.
?
.
b: BOOK3
, ,

create b
. b ?
, ?
,
.
- reductio ad absurdum ( ). ,
. BOOK3, author
WRITER, author - , .
, .
PERSON1, :
class PERSON1 feature
name: STRING
loved_one, landlord: PERSON1
end
PERSON1 (
loved_one landlord ) . .
.
,
. , :
, .
author .
, . (.
.8.7) loved_one PERSON1,
.
. , , - ( )
.
( landlord ).
.
( , ), . ,
, , .
, create {T}x
, T x. ( , . 14)

.
, , -
. .

, ,
. ,
creation feature. :
indexing
...
class C creation
p1, p2, ...
feature
... , p1, p2, ...
end
, : - make.
make_, ,
POINT. (. " ", 8 " -
")
:
create x.p (...)
p creation, (...)
p. ,
, p .
(creation call). ( POINT
7)
POINT,
- . : make_cartesian
make_polar. :
class POINT1 creation
make_cartesian, make_polar
feature
... :
x, y, ro, theta, translate, scale, ...
feature {NONE} - .
make_cartesian (a, b: REAL) is
-- a b.
do
x := a; y := b
end
make_ polar (r, t: REAL) is
-- r t.
do
x := r * cos (t); y := r * sin (t)
end
end
:
create my_point.make_cartesian (0, 1)
create my_point.make_polar (1, Pi/2)
, Pi
. , . ,
, :

create x.p(...).
x , C, p(...) - C,
. :
(C1) C ( , C). OC -
.
(C2) OC .
(C3) x () OC.

(4) p c OC.

, POINT1, feature feature {NONE}.
, , .
, ,
my_point.make_cartesian (0, 1) my_point.make_polar (1, Pi/2) ,
.
,
, , ,
translate scale . , ,
, .
.
creation , :
class C creation {A, B, ...}
p1, p2,
...
,
feature. ,
, .
,
: create x create x.p (...) , .
creation , ,
.
,
. - , ,
, . . ,
- . ,
, ,
. .
,
. ,
.
, , ,
.
, ANY, nothing. ,
, . :
class C creation
nothing, some_creation_procedure, some_other_creation_procedure...
feature
...
- ,
create x.nothing
- ,
. , :
class C creation
-- !
feature
... , ...
end
creation , . ,
, , .
-, ,
. , -
. . , ,
(). , ,
. , .

,
C++/Java. , . :
, , - ,
. ( / ).
, . :
make_cartesian make_polar ,
, .
. ( ),
; ;
, , ;
, , make_polar .


. , ,
(void) .

- . ,
void .
, :

. 8.11.
, . ,
- , :
"" - ; ,
.
"" - . void , .
"" .
.
" " - , , - ,
.
, , .
b - , ,
O. , b O.

, , .
void - .
- - - .
:
some_entity.some_feature (arg1, ...)
some_entity .
, some_entity void , ,
.
- void .
(exception).( 12)
, ,

, ,
. , ,
. ,
, . , - :
if "x void" then
x.f (...)
else
...
end
, ,
, .
.
, , void , ( )
. , ,
- ,
. - .
:
, ,
, , , .
, .


x:
create x , . ,
.

, , - . ,
, .
, Pascal-C-Java-C++, :
my_beloved.loved_one := me ( loved_one),
.
,
. PERSON1 , loved_one.
:
class PERSON2 feature
name: STRING
loved_one, landlord: PERSON2
set_loved (l: PERSON2) is
-- loved_one l.
do
loved_one := l
end
end
set_loved loved_one PERSON2
l. ( ) (
) ().
: ,
- void, . , ,
, .8.12 , landlord loved_one
.

. 8.12.
, :
a.set_loved (r)
a O1, r - O3. set_loved
:
loved_one := l
O1, l r - O3.
loved_one O1 - O3,
:
r , loved_one
O1.

. 8.13.

- ,
. =.
x y - , :
x = y
, .
" " /=.
:
r = a.loved_one
, .8.5 .8.12 .
, , , .
, false,
. , , , .
void
- .
, void .
Void
.
Void , :
if x = Void then ...
, :
x := Void
, .
:

. 8.14.
Void , , -
. ,
( x
O1, ). .

, .
, , .
clone.
y OY,
clone (y)
OX , , , OY,
. y void, clone (y) void.
y x :
[1]
x := clone (y)
:

. 8.15.
, .
equal . :
equal (x, y)
true, x y void
. [1], ,
, equal (x, y).
, , clone , equal - . -
: y.twin x.is_equal (y). ,
, .

clone . , ,
, . copy . :
x.copy (y)
x y ; - ,
y, , x.
, copy , x . ,
y . copy clone.
y , .
: ,
. , ""
. ,
, , - clone equal.
copy , clone , , ,
clone copy :
clone (y: SOME_TYPE) is
-- Void y void; y
do
if y /= Void then
create Result --
Result.copy (y)
end
end

Result
. else : Result Void ,
void , y void.

, clone, equal copy , ,
, .
, .
, .8.16. ,
A, a O1.

. 8.16.
:
b := a
B, , b O1,
a. .
:
c := clone (a)
, C , O4, ,
O1. , O1 O3,
O1. , , O3,
O1. clone ,
- .
, . landlord O1
O1. O4 O1.
, ,
. deep_clone .
deep_clone (y) , ,
. ( y void, void.) , ,
.
- D - :
d := deep_clone (a)
. , O1,
, O5, O6 O7. (O1, O2 O3)
. O5, O1, .
, ,
. deep_equal , .
, , deep_equal a, b d. equal (a, c)
, O1 O4 , equal (a, d) - . equal
d . :
x := clone (y) x.copy (y), equal (x, y)
true ( , y void).
x := deep_clone (y), deep_equal (x, y) true.
.
:
,
-, , .
. , , -
.
- , , .
, .
"" (retrieval) "" (storage), (input,
output). ,
.
, POINT BOOK1 -
. , , ,
INTEGER, REAL STRING, .
-
. .
, - ,
read write, clone copy .
,
- . - ,
. .
. . ,

- , ,
, .
(dependents) :
: ,
, ,
.
() .
, .8.17,
O1. O1 - O2 O3.

. 8.17.
. ,
.8.18, W1 , B1 B2 W1.

. 8.18. Book Writer


deep_equal. :

(Persistence Closure principle)


, , .
, ,
, .
, , STORABLE,
Base. STORABLE :
store (f: IO_MEDIUM)
retrieved (f: IO_MEDIUM): STORABLE
x.store (f) , f, , x, .
, x, . x
STORABLE. .
IO_MEDIUM Base, ,
. , f void,
.
retrieved (f) , , f
store. retrieved - ,
.
STORABLE (persistence) . ,
. STORABLE
, :
- .
.
, , ,
, , .
retrieved .
,
.
- ,
13 " - ".
STORABLE ,
.
STORABLE .
, -
. :
,
-, . -
, .
STORABLE ,
, , .
STORABLE SAVE. ,
, .
SAVE, .
, .
STORABLE SAVE :
head.store (save_file)
-
.


.
, , ,
.

, .
, :
- .
(BOOLEAN, INTEGER .) ,

(POINT, BOOK .). , n INTEGER,


, n - , .
. ,
, - . ,
- . ,
.
, ,
O1 O2, O2.
, , .

. C- , ,

class C feature
...
end
C . C . C
(reference type).
, x, C,
. x:
x : expanded C
expanded (). expanded C ,
C.
, C , C,
expanded C C.
, , , (composite
object). O , -
(subobjects) O . :
class COMPOSITE feature
ref: C
sub: expanded C
end
COMPOSITE : ref, , sub, .
COMPOSITE.

. 8.19.
ref , C (, ). sub
C .
. , E, ,
. ,
:
expanded class E feature
... ...
end
.

, , class E. E , .
:
:
:
: expanded C
E, E - .

x: expanded E
E - , ,
x: E
, . , , .
- .
.

? :
;
;
- .
:
. ,
"" (dereferencing), . , ,
, .
, , . -
. ,
. , .
:
D1. ref: S
D2. exp: expanded S
C, , S . D1 ,
C " " S ( ref void).
D2 : , C""
S. , , .
"", , ,
" " , .
:
class WORKSTATION feature
k: expanded KEYBOARD
c: expanded CPU
m: expanded MONITOR
n: NETWORK
...
end
, , . ,
.
. ,
"".

. 8.20. :
, , ,
, . ""
" " ;
.
.
, ,
. REAL , ,
.
: BOOLEAN, CHARACTER, INTEGER, DOUBLE. .
, ,
r: REAL
, ( REAL).
: ,
. - REAL
. :
expanded class REAL feature
... ...
end
.

- , , -
, .
"" (aggregation), , -
, . :
, , .
. , , CAR
: expanded ENGINE expanded BODY. ,
" ". , C S,
expanded S ( S, S ).
, - " ",
, , ,
. - WORKSTATION KEYBOARD,
- WORKSTATION NETWORK.

-, ,
, - : ( ) .

E ( ) x E.
x , void. :
x = Void
false, x.some_ feature (arg1, ...)
- void , .
O x. , , x O. ,
, void, , -
- .
? :
create x
x. x : (C1) ; (C2)
; (C3) x. x, C1 ,
C3 ; .
,
C2. , , , :
class F feature
u: BOOLEAN
v: INTEGER
w: REAL
x: C
y: expanded C
z: E
...
end
E , C . F u false, v - 0, w -
0.0, x - void, y z C E ,
.
, C E .
, , ,
. , ,
, . , C
expanded D, D expanded C. ,
C D, C . " ",
:

" " : C
S, C , S.
.
, A, B, C, ... N,
, N A. ,
A expanded A, A .

, .
, , . ,
, :

. 8.21.
:
Class COMPOSITE1 feature
other: SOME_TYPE
sub: expanded C
end
class C feature
ref: D
x: OTHER_TYPE; y: YET_ANOTHER_TYPE
end
class D feature
...
end
COMPOSITE, O_COMP .8.21, , (OC )
ref, (OD ).
, , .
, . ,
, .8.22, OE OC, - O_CMP1,
OC .

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

: -
, .

,
, - . , ,
, .

, , -
. , ( ) :
r (..., x: SOME_TYPE, ...)
x r. r
- :
r (..., y, ...)
t.r (..., y, ...)
y , x.
r
. ,
, , . ,
:
x := y
:
:
y x :
x := y
x , x - , y - .
x , y - .
(
). ,
.
:
.
, :
x := y
, x y.
. y void, x
void; y , x .
, x y ? ,
. . :
x, y: expanded SOME_CLASS
x := y , y, ,
x, , :
x.copy (y)
, . (
, .)
, ,
. , m n INTEGER,
m := n, ( ) n m.
.
: x = y x /= y. x y , , (
) , void
. x y, , - ,
, x = y

, equal (x, y).


, , equal
.
=,
standard_equal.
.
y x x, x y .
, x y . , : x=y x/=y x y
; , x y .

-
. ?
, x := y x , y - .
: ,
y, , x. , y void . y - void,
. ( 12)
x x = Void ;
false. x := Void,
.
: x := y, x , y - .
y , OY,
x . , x OY.
, .
OY x . :
class C feature
...
end
class COMPOSITE2 feature
x: C
y: expanded C
reattach is
do x := y end
end
reattach x ,
y.
:

8.1. x:=y
y

: x := clone(y)

: x.copy(y) , y - void : x.copy(y)



, (= /=) .
= equal. ,
.
(E1) x y - , ,
, void. x = y,
. equal, ,
, x y - void.
(E2) x y - , .
(E3) x - , y - , -
. , , x - void, false
, y void.
= .
equal, , void.

8.2. x=y
y

equal(x,y) , y void,
- false

equal(x,y) , x void,
- false
equal(x,y)

8.1 8.2
. , , equal (x, y) x := clone (y) x. copy
(y).
, , Pascal, Ada, Modula-2, C,
Lisp . -,
. , ,
, .

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

x y y x := y
, x y .

. 8.23.
x y , x y .
x.f, f ,
, y.f, .
x , y, (dynamic aliasing).
, .
,
, .
. Fortran EQUIVALENCE ,
. C #define x y ,
x y.

, . x y
INTEGER x := y x y x y .
x y .

( , )
, .
:
[ ]
-- , P(y)
x := y
C (x)
-- P(y) .

, P (y) y, C (x) x, y.
x y.
. x y INTEGER:
-- , y "= 0
x := y
x := -1
-- - y "= 0.
y x.
. x y C:
class C feature
boolattr: BOOLEAN
-- .
set_true is
-- boolattr true.
do
boolattr := True
end
... ...
end
, y C, y .
" ":
[, !]
-- , y.boolattr false.
x := y
-- y.boolattr - false.
x.set_true
-- y.boolattr true!

y,
y.


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

, .
,
.
. .8.24 , .
, .
.

. 8.24.
,
.
class BOOK3 feature
... ...
author: WRITER
end
,
. , - PERSON
. , .
b1 b2 BOOK3 , b1.author b2.author - , ,
,
.
, . ,
.
" ", .
b :
NOT_NOBEL (b) : " ".
NOBELIZE (b) : " b".
, rb " ", cp - " ".
:
[ ]
-- , NOT_NOBEL(rb)
NOBELIZE(cp)
-- NOT_NOBEL(rb) !
cp rb, !
( , ..).
, , ,
x.set_true, y y.
,
. (""
), .
(polyonymy), , "" (Cybele), "" (Demeter) "" (Ceres) "
, (antonomasia) - , , ,
, " ", .

,
, , , .
? " " ,

. , , ,
.
, -.
, Pascal, C, PL/I, Ada Lisp ,
.
. : C PL/I
, Pascal Ada ,
.
-? (
, , - Pascal Ada),
. - . , ,
,
-. .
, ,
:
, , - . -
.
A Base.
. ,
.
,
, .
,
.
.
, ,
. Suzuki, .

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

, . ,
. , .
. ,
. , ,
. ,
- .
. ,
. -
. ,
, , . CASE .
, - , .
,
BON (Nerson Walden). BON, (Business Object Notation)
CASE- , , ,
, .( BON . 9 "
- ")
,
, .
.
, , Ian
Graham -, :
, . ,
, , ,
.


-
. ,
. , - (:=, =, /=).
? , ,
?
Simula 67.
( Simula reference ref), Simula
C:
x: reference C
reference , x . :
m, n: INTEGER
x, y: reference C
Simula, , .

8.3. Simula

m := n

x :- y

m=n

x == y

m /= n

x =/= y

Simula . ? ,
, , .
. , - , :=
:-.
. , ,
, - . ,
, , ,
. , .
Simula , : ,
. a b
:
a :- b a == b ;
a := b ( a := clone (b) a.copy (b) )
a = b ( equal (a, b) ).
, Simula .
(copy clone , ),
. TEXT, Simula .
,
. , - := :-,
, , , ,
.
, , , Simula:
.
,
:
a := clone (b) a.copy (b) ;
equal (a, b) .
, , (:= =, )
.
, ,
, ,
. , Simula, - :
" ".
, , :

" ".
" " " , ".
", ".
, ,
. .
( INTEGER) .
, , , ,
. := =
.
" ,
". -
.
" , ,
".
, (:- :=), .
, , .
, LIST [G], G,
, .
G . ,
, , . ,
LIST [INTEGER] LIST [POINT]. ,
, , - .
, a b G, a := b
a = b , ,
INTEGER, - , POINT.
, , x
. . x , x. x
, , x .
, , , , ,
. ,
, : (
);
clone ( copy) equal, (:= =).

clone equal , .
:
clone (x)
equal (x, y)
-. "- "
(. "- ", 7):
x.twin
-- twin - .
x.is_equal (y)
, . x.f (...)
x .
, ,
. x , ,
twin :
if x = Void then
z := Void
else
z := x.twin
end
, is_equal (and then and. . "
", 13):
if
((x = Void) and (y = Void)) or
((x /= Void) and then x.is_equal (y))
then
...
, .
, , .

, , , x,
void, - clone (x) void, equal (x, y) true, y - void.
copy x.copy (y) , x y.
copy, , ,
. , y copy,
.
, is_equal . ,
, .
is_equal .
equal is_equal (, is_equal),
is_equal.
clone, twin. , clone
copy. clone
copy . (. 16)

clone, copy, equal, is_equal,
deep_clone, deep_equal.
, .
ANY Kernel. , ,
, ( ) ANY.

. (. " ", 16)
, .
, , ,
, , - , ,
.


- ,
.
, , ( ).
.
, .
(, ).
, , .
(void) . x = Void
. x.f (...) , x
.
class C ..., C ,
C. expanded class D ...,
D ( D) .
(BOOLEAN, CHARACTER, INTEGER, REAL, DOUBLE) .
: .
.
create x ,
x. ,
create x.creatproc (...) , , .
(:=) (=)
. .
.
.
.
.


, -.
13 " - ", ,
.
BON (Business Object Notation) Jean-Marc Nerson Kim Walden [Walden
1995]. James McKim Richard Bielak
[Bielak 1994].
, ,

, ,
goto . Nori Suzuki [Suzuki 1982]

( goto, "
"). , .
Ross Scaife . .
http://www.uky.edu/ArtsSciences/Classics/rhetoric.html.

8.1
BOOK and WRITER , .
, .
8.2
PERSON mother, father sibling (
, ). ,
, , , . :
, , ,
, .
8.3
, x.is_equal (y), ,
( , ).
, x y.
, ,
. , ,
( ) . (. "-", 7)

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


- . ,
, .

.

create x
: ; x;
.
;
clone deep_clone.
, create x .
, .

-, . , , : ,
. , .
, - ,
. , ( )
. , ,
Result. :
x , x
( x ), ( x ). x ,
, x. ,
.
.

. , Fortran,
.

. 9.1.

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

. 9.2. ,
Algol 60 (
) .
, . Pascal C
, Algol.
. ,
, . 1)
: ,
"", - . , .
.
, . ,
.

. 9.3.
, ,
, .


, , , -.
-. :
Pascal , , , ,
, .
new.
C Pascal, ,
, ,
malloc.
PL/I .
Lisp
. Lisp,
, - CONS, .
, - . CONS, ,
.

, , , ,
? , ,
?
:
. , .
.
. , ,
, ,
, ,
, . ,
(overlay), , .
- , , , ,
, - .
:
. .
, .
, , , , .
:
, . ,
:

9.1.

( )


(
)

(
)


. . :
, ,
.

;
, ( ) .
- (detachment),
. , ,
. .
x . x - x

O, x O. , , x
, O BO. BO, O,
, .
.

. 9.4.
. , x y
O1 O2. D1 D2.
(D1) x := Void, x := v v void, x O1.
(D2) y := z, z O2, y O2.
(D3) .
(D4) create x , x , ,
x, O1.
D3 : a r
t.r(..., b, ...), b a r,
a := b.

, O1 O2 (.9.4 ), ,
, ?
! , ,
, - .
, .9.4 .
, (.9.5 ) , O1 O2 .
. ,
, , , O4 O5 , , O1 O2
.
, : " ?"
. :
(C1) , , ( )
.
(C2) C1. (, ,
C1,
.) .

. 9.5. -
C3 , .
(origins). 2
(reachable) . 3 (unreachable).
.
" " 3 "" . (
, , ,
.)
"" "". ,
- " " " ".
, , ,
.
-
.
. , - ?
, .

, Pascal, C Ada,
. (, ,
, -.)
. C Ada
, ,
. ,
. Pascal .
, . -
- (
). , ,
.
,
, , .

. 9.6. - (
)
, .
.
, .
. , .
(reference origins).
:
(O1) (
).
(O2) , ( ).
, Pascal ,
( reference G - , G):
type
COMPOSITE =
record
m:INTEGER
r:reference COMPOSITE
end
...
procedure p is
local
n: INTEGER
c: COMPOSITE
s: reference COMPOSITE
do
...
end
p :

. 9.7.
: n, (
); s, 1;
COMPOSITE.
. r, 2.
, ,
, (
), ,
.
-
- , ,
.

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

some_routine is
local
rb1, rb2: BOOK3
eb: expanded BOOK3
do
. . .
create rb1
. . ., rb1, rb2 eb . . .
end
some_routine,
rb1, rb2, eb , . ,
, . , eb
, rb1 rb2 void.
, rb1 rb2, ,
. , eb,
, .
some_routine, rb1, rb2 eb .
. ,
, - .
, , - :
some_routine is
local
rb1, rb2: BOOK3
eb: expanded BOOK3
do
create rb1;create rb2
a := rb1
end
, some_routine,
.

. 9.9. ,
some_routine , , , (
). B1 BOOK3,
. B1
. , B2 EB, rb2 eb ,
: , -
"" 2 .
-
, :
: ,
:
.
, , ,
( Result).
, , .
. , , (,
) .
- ,
: .
.
, , - LINKED_LIST, ,
LINKABLE, . LINKABLE
LINKED_LIST
remove, .
. ( .)
, , .
- ?

:
, :
. (casual) .
, ,
.
(manual reclamation) .
( (runtime system)) ,
.
(automatic garbage collection).
.

()
: .
, , .
?
, , ,
.
, , ,
. ,
. , .
,
.
: ,
,
.
"" ("hard-real- time"),
(, ).
.
, , ,
.
, .
, -
. ,
.
?
, , -
.
, .
, .
.
-, , ,
.
,
.
, .
, .
,
, ,
, (trashing),
. ,
- . (. "", 1.)
. .
, .
, .

, ,
.
, , , 1500 .
, c
.
.
, ( ).
, , ,
. , 1992
, . .
28 29 , -
. , ,
, .
, .
,
- , . :
27 1992 . 4 .
4 ,
. .
.
, ?
. :
,
. XX ("XX" ,
)
, , ,
. .
.
.
, ,
, .
, , , ,
,
.

:
, ,
. :
(detection). ?
(reclamation). ,
?
:
- ,
.
- .
-
. .
, , , -
.
-. ,
, .
, .
, - .
. .

,
- ,
.
: , , - ,
, reclaim, a.reclaim , , a, ,
.
-, Pascal (dispose ), C (free), PL/I (FREE), Modula-2
Ada. ' " , C++.
-,
. , Objective-C
, , :
, ! - .
, , .
? ( (Ian Stephenson), 11 1993.)
.
- "" : .

, reclaim.
reclaim ; .
reclaim, - , .
, -
. , , ,
, ,
( ) .
,
. - .
, -
reclaim, - , .
, - reclaim
- - .
, -, . ,
,
.
, " ", , ,
. ; .
, , ,
. ,
.
++ , , .
, - .

reclaim, -
? , ,
, ,
, .
, .9.10, ,
. , ,
. - ,
, - . , :
? Pascal :
, ,
. , ,
. .

. 9.10.
PERSON1. , x
MY_TYPE , :
class MY_TYPE feature
attr1: TYPE_1
attr2: TYPE_2
end
MY_TYPE, , , ( void)
TYPE_1 TYPE_2. , ,
. , ,
, - , , ,
.
.
. , , ,
. .
,
.
- .
,
. , . ,
. reclaim
, , :
, .
. ( ),
, , .


( , ;
.)
, ,
, , .
- "-",
, .
- ? ,
: .
- -
, ,
. , , ,
(component manufacturers).


.
,
, , reclaim.
. .

. LINKED_LIST, ,
(header) , LINKABLE.
.
. (, LINKED_LIST LINKABLE)
, "" LINKABLE -
. .
, LINKED_LIST : put_right put_left,
.
LINKABLE . :
put_right (v: ELEMENT_TYPE) is
- v .
require
...
local
new: LINKABLE
do
create new.make (v)
active.put_linkable_right (new)
... ...
end

. 9.11.
create new.make (v)
.
, , , , ,
- . : remove, remove_right, remove_left.
, remove_all_occurrences (
) wipe_out ( ). , ,
. remove, , :
remove is
- .
do
...
previous.put_linkable_right (next)
... ...
active := next
end

. 9.12.
, ,
. -
.
LINKABLE -
, , .
, LINKABLE , available.
. create new.make (v) put_right
put_left
new := fresh (v)
fresh LINKED_LIST,
linkable. fresh available ,
, .
available . , remove
:
do
recycle (active)
- :
... : previous, next, first_element, active...
recycle LINKED_LIST , fresh,
available. , .

fresh recycle, available :
fresh , recycle .
STACK_OF_LINKABLES LINKED_LIST (
23.1. , fresh .):
available: STACK_OF_LINKABLES
fresh (v: ELEMENT_TYPE): LINKABLE is
- v,
-
do
if available.empty then
-
create Result.make (v)
else
- linkable
Result := available.item; Result.put (v); available.remove
end
end
recycle (dead: LINKABLE) is
- dead .
require
dead /= Void
do
available.put (dead)
end
STACK_OF_LINKABLES :
class
STACK_OF_LINKABLES
feature {LINKED_LIST}
item: LINKABLE
-

empty: BOOLEAN is
- ?
do
Result := (item = Void)
end
put (element: LINKABLE) is
- .
require
element /= Void
do
element.put_right (item); item := element
end
remove is
- .
require
not empty
do
item := item.right
end
end

. 9.13. STACK_OF_LINKABLES
right,
LINKABLE, , ,
LINKED_LIST. LINKABLE
right put_right STACK_OF_LINKABLES.
available . ,
. , ,
. (once
functions), ; available ,
STACK_OF_LINKABLES ,
. ( 9.3. 9.4. . 18)

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


.
.

- ,
, .
, .
(Michael Schweitzer) (Lambert Strether): "-
, :
!" ( [Schweitzer 1991])
, , .
, .
. ,
. :
- - - -
,
.
: .
, .
?
, .
, - ,
? :
, , "
", , .
( create x... )
. ,
. .
.
: ,
,
. .
, . .
, . ,
. ,
.
,
, , . 9.1 ,
.

, - ,
.


- .
. , .
.
, , .
, , , . ,
create a , . (
clone .)
, , .
, a , :

A1 L b := a ().
A2 L x.r(..., a, ...) , r - ( ).
, , .
:
(D1) a := b. , (1) ,
b. ( b , ,
, .. - .)
(D2) x.r(..., a, ...). ( a
, a.)
, , , ,
, .
clone, . a := clone (b)
, b, . A
a. A , , .
,
, , ,
.
,
. ,
, - . , .
, , , . ("
", .) .
:

. 9.14.
1, 2 3 . ,
, - .
.
, 1 ,
:
:=void
1, 2, 3 , :
1 .
, .
- , , .
.
, .
. , ,

, , , ,
, .



.

(garbage collector) - (runtime system)
. ,
,
.
. (
.) ,
, .

, , , :

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

, , (timeliness).
, , ,
, .
,
, . , ,
++? :
"" ( ); -
. , ,
, ++ , , ,
.
, .
++, , ; ,
. :
(OTHER_TYPE) x
, x OTHER_TYPE,
x. ++ .
, - .
. - ,

NUCLEAR_SUBMARINE, integer. , ,
, integer. ,
. ,
NUCLEAR_SUBMARINE, , - .
. -
. Java C++,
,
, , , , .
, ,
.

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

, ,
.
"--"
. , 50-
. , ,
, , ,
.
, ,
, , , 10 ,
.
,
:
, , .
.
. , , .
, , : " ,
, , ".
, , .
- , .
, 5-15%. , ,

, . ,
, .
, .
:
(overall performance) (incrementality).
(Advanced)
, ,
,
.
-
. , :
collection_off
collection_on
collect_now
; -
, ; -
. ,
.
collection_off collection_on ; ,
(, ), collect_now.
, ,
(generation scavenging). :
, ,
. : " ".
, , .
, .
(tenuring) ,
PROFESSOR, ,
, . - ,
, "" .
. ,
,
.


, ,
. , " " (on-the fly) .
- (
): .
;
reclaim .
,
.
. ,
, .
( 12 " -
", "")

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

, ,
. , " ?" .


, ,
, , , ,
.
MEMORY
- , MEMORY.
, , MEMORY.
( EXCEPTIONS, 12)
( CONCURRENCY, 12 " -
")
MEMORY : collection_off,
collection_on, collect_now.

MEMORY dispose ( Pascal,
). ,
(finalization). , ,
,
, . - FILE,
.
FILE , .
, dispose,
. , ,
.
: dispose
reclaim. ++ dispose reclaim.
,
dispose .
, , .
( ,
.) MEMORY dispose,
:
dispose is
- , ;
- .
- .
do
end
, ,
, dispose , . ,
, FILE opened close.
dispose :
dispose is
- , :
- , .
- .
do
if opened then
close
end

end
: dispose -
( ), , ,
MEMORY.

- .
- , -.
, . (. " ", 13)
, (
), , .
. ,
( ):
r (x: SOME_TYPE) is
do
...
a := x
...
end
a , r. ,
, -.
r(y), y 1. ,
, 1 , ( a)
. - - 1,
.
, ,
. :
adopt (a) -
wean (a)
- ,
, -
. . ""
; "" - .
- - .
. , - . ,
.
. , .


, , ,
, . ,
.

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

.

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

.


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

, .
, ,
, - .
, .
: , - , ,
.
: , , .
, , ,
, .
;
, .
, . ,
- .
-
, . - : -
; - .
,
. n n-1 .
(Bulimia and anorexia)
, -
.
, .


, ,
; .

: ( create x )
. , :
, , .
, .
. , -
- . ,
.
;
.
.
, , , speed
,
. , :
collection_off, collect_now dispose MEMORY.
, ,
, , ,
, - .


: , , .
-, , , Lisp, Pascal ( new), C
(malloc), Ada ( ).
, , .
, , , - ,
.
,
,
.
( , )
: .
: , ,
.
-
. .
.
, - , ,
.
.
.
, , ,
.
, ,
, , .

, .
,
,
.


, , "
" , [Johnston 1971].
,
Risks.
[Dijkstra 1978].
[Cohen 1984]. [Ungar 1984].

ISE's , , (Raphael
Manfredi) (Xavier Le Vourch) (Fabrice Franceschi) (
).

9.1
,
. , ,
, . ,
, .
1, 2, 3,..., i 1, (
), (-n), n .
9.2 ?
, Pascal C,
dispose free,
. .
9.3
( 18) available,
.
. (:
once.)
9.4
( , , 18)
available ?
1)

, mallok - ,
, ; Pascal
.

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

. 10.1.
, - LIST_OF_BOOKS,
. : put , remove
, count ..
LIST_OF_BOOKS.
, .
, . LIST_OF_BOOKS,
SET_OF_BOOKS ( ).
LINKED_LIST_OF_BOOKS, . -
.
, , .
, , .
- , .
, ,
, LIST_OF_BOOKS LIST_OF_PEOPLE, ,
.
- -.
, ,
?1)
, ,
: . , , ,
. , ().

, .
- ,
.

, STACK, , STACK [G].
" ", .
G, , - . ,
.
. , , : INTEGER_STACK,
REAL_STACK ..
, : , , , , ,
.
, .

, , . , INTEGER_STACK,
INTEGER. count ( ), put (
), item ( ), remove ( ), empty ( ?).
INTEGER . , put
item:
put (element: INTEGER) is
-- ( ).
do ... end
item: INTEGER is
--
do ... end
INTEGER , :
, ,
, element: INTEGER. , item,
element put , .
, : INTEGER_STACK, REAL_STACK,
POINT_STACK, BOOK_STACK...
item, element .
. , ,
.
- ,
.
: .
: ,
.

( )? ,
( 17).
, - .
: ,
. , , ,
.
:
, . x.f (a,..), - TX.
: TX f; ,
; ;
. Smalltalk,
, , ,
: "Message not understood",
.

- ", ". ,
, . ,
, - .
.
, .. ,
, .
, Smalltalk, . ,
:
my_stack.put (my_circle)
my_account := my_stack.item
my_account.withdraw (5000)
, , , ,
. ,
" ".
.
.


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

, G ( Generic). .
, H, I ..
, ,
, . :
indexing
description: " G"
class STACK [G] feature
count: INTEGER
--
empty: BOOLEAN is
-- ?
do ... end
full: BOOLEAN is
-- ?
do ... end
item: G is
--
do ... end
put (x: G) is
-- x .
do ... end
remove is
-- .
do ... end
end -- class STACK
G (
item) ( put), .


, .
- , :
sp: STACK [POINT]
,
.

(generic derivation), , STACK [POINT],
.
, :
STACK [POINT] .
, ,
(POINT ).
. ,
. , LIST [G],
, :
slp: STACK [LIST [POINT]]
, STACK [POINT] , - :
ssp: STACK [STACK [POINT]]
, .

, .
, STACK [POINT], POINT STACK,
"generic instantiation". ,
. ,
- , , .
"" "" -. ,
- .
.

, ,
. , :
sc: STACK [CIRCLE]; sa: STACK [ACCOUNT]; c: CIRCLE; a: ACCOUNT.
:
sc.put (c) --
sa.put (a) --
c := sc.item -- .
:
sc.put (a); -- : .
sa.put (c); -- : .
c:= sa.item -- : .
, .

, , ,
.
, . C . ,
, , :
f(a:T):U is ...
x.f(d), B, x C ,
, :
f B, - , B;
d T. , d T.
U. , f .
, C G :
h (a: G): G is...
h y.h(e), y ,
y: C [V]
V - . - - ,
e V V. h.
: V - , G
C, G .
: s.put(z) z POINT, s STACK [POINT];
INTEGER s STACK [INTEGER]; s.item POINT
INTEGER .

C [G, H, ...] , - ,
x G. , G, ,
. , C x,
. :

x, G,
.
1.
2.
3.
4.
5.

x := y, y G.
y := x, y G.
x = y x /= y, y G.
G, ANY.
ANY.

, create x ,
, , , ,
G.
(4) (5) ANY. , ,
. , G
. ANY
: clone, copy, equal, deep_clone, deep_equal . x y
G :
x.copy (y)
x := clone (y)
if equal (x, y) then ...
(4) a.f(x) C [G], f G.
, , a D [G], D . D [G]
f, G,

D, . ( , , , ,
2), .)

- , -
: . , - ,
.
, .
, C [G], , ,
. , ,
, , .
.
: " T"
" T", x , T. T C [U]
C U. , C,
.
, . T
T, T. T ,
. T C [U, ...], C T.
, (
-) , : (. . 16.7).

ARRAY,
.

.
: -
, , ARRAY.
ARRAY . : 3)
indexing
description: " ,%
% "
class ARRAY [G] creation
make
feature
make (minindex, maxindex: INTEGER) is
-- minindex maxindex
-- (, minindex > maxindex)
do ... end
lower, upper, count: INTEGER
-- ; .
put (v: G; i: INTEGER) is
-- v i
do ... end
infix "@", item (i: INTEGER): G is
-- i
do ... end
end -- ARRAY
a m n, ARRAY [T] T,

create a.make (m, n)
put: a.put(x, i)
x i- . item ( @,
), :

x := a.item (i)
, :
pa: ARRAY [POINT]; p1: POINT; i, j: INTEGER
...
create pa.make (-32, 101) -- .
pa.put (p1, i) -- p1 i.
...
p1 := pa.item (j) -- p1 j.
(, Pascal) :
pa [i] := p1 pa.put (p1, i)
p1 := pa [i] p1 := pa.item (i)

.
: ARRAY2 . .
Count , count = upper lower+1. , .
put item, ,
, i lower upper.
( ARRAY ) -
,
.
, put item.
ARRAY - , , ; , . ARRAYED_LIST,
- LIST ARRAY.
.
,
. ,
.

?
, - -
. item put? . ,
ARRAY ,
. item put
, , Fortran, Pascal C
(p1 := pa [i] pa [i] := p1 Pascal).
: , , , -,
.
. , ARRAY

.
. , ,
ISE , ,
C Fortran.

ARRAY , , .
item - 4) :
infix "@", item (i: INTEGER): G is...
: infix "@" item , ,
.
, :
a, b, c... " "

:
a " "
b " "
c " "
...
" ".
( " " : _),
(is _).
, , .
, , , a.item(i) , a[i],
Pascal, C, Fortran . "@" item,
. a @ i, , , ++!. ,
, -, -, .


, -, ,
, . .
.
?
, - ++, , ,
. ,
,
! ++
:
- ++.
List<int>, List<String>, List<Widget> List<Blidget> ( Widget Blidget ,
) head, tail insert ,
(- ). List
. 5)
(++ AT&T, ++ [Ellis
1990]) , .
.
,
:
;
;
;
, .
, , ,
, .

: -
, ,
.
: .
, . ,
, . ,
, , , . ,
. , ,
figure_stack.put(that_point) figure_stack STACK [FIGURE], that_point , FIGURE.
(polymorphic data structure). , -
.
: . ,
. , ,

, . ,
-, , - .
, ,
, ,
(constrained genericity).
- ,
.


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

.
-
- .


, - LPG [Bert 1983]. Ada
.
, Z, CLEAR OBJ-2,
6 . , , ,
Z [Abrial 1980] [Abrial 1980a] [M 1985b].
, -, , DEC's Trellis
[Schaffert 1986].

10.1
- ,
. - , .
, , -. Ada
, .
, -.
,
.
10.2
ARRAY , ARRAY2,
.
10.3
, C [G] ,
D [G], G.
1)

B "Genericity versus inheritance".


10.3.
3) 11
4) 7
5) Martin Carroll, Margaret Ellis, "Reducing Instantiation Time", in "C++ Report", vol. 6, no. 5, July-August 1994, pages 14,
16 and 64.
2)

-
11. : :
, , ,
. !
. ,
. , , - ,
, - ( ).
, .
, - .
, .
: , .
, . - -
. , ,
. , , .
,
. (Design by Contract) -
,
.
.
- ,
. - .
: . -
, -
, . ( ), , ,
( ) - .
, ,
.


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


, - ? ,
, . , ,
, - ,
.
, 300 000 , ?
, - "". , , .
, ,
, , .

x:= y+1
, .
. , :
" x y ".
: " x ", y,
.
, :
, .
. ,
, (consistent) .
"",
, , - "
".

- .
(assertions),
. , -
, , ,
. ,
, , . .
, , .
.
" ". ""
,
.
.
. ,
- .
.
. :
, ++ assert,
,
. , ,
-. ,
, , , ,
.


,
.

- ( ). (correctness formula)
- :
{P} A {Q}
, :
{P} A {Q}
, , P ,
Q.
, , - ,
. ,
. , , , P Q -
, (
). P , Q - .

, ,
, P Q. ,
{P} A {Q} ().
, , x integer:
{x>=9} x:= x+5 {x>=13}
13 . ,
. x>=9 , x>=13
. , :
, , x>=14. ,
x>=13 x>=8.
,
. , "" "" -
.

"" "" . , P1 , P2, P2 , P1, P1
P2 . True, False .
, True , False .
,
. P Q,
? ,
, ,
. " " . , :
1
{False} A {...}
, .
, , .
, , - ,
.
.
, , : " ,
!"
.
- " "; .
- , :
2
{...} A {True}
, . ,
- ? ,
, (terminate). ,
, Q, , , P.
1, , P, ,
, .
. 2, , ,
, , , , ,
.
, , , {P} A {Q} (total
correctness) , .
, , , ,
. . [M 1990] .

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


,
.
. , , - (the
how); - (the what) - .
- , .
,
. ,
, .
,
.

. "old", -
";" ( ). :
n>0; x /= Void
, , ";" ,
, , , ,
.
, :
Positive: n > 0
Not_void: x /= Void
, Positive Not_Void, ,
. , , .
:
, , ,
.


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

.
"" :
class STACK [G] feature
... :
count, empty, full, put, remove, item
end
. ,
, . :

remove item , .
put , remove - .
,
.
. .
.
require ensure . "" ,
:
indexing
description: ": Last-In, First-Out %
% - "
class STACK1 [G] feature - Access ()
count: INTEGER
--
item: G is
--
require
not empty
do
...
end
feature - Status report ( )
empty: BOOLEAN is
-- ?
do ... end
full: BOOLEAN is
-- ?
do
...
end
feature - Element change ( )
put (x: G) is
-- x .
require
not full
do
...
ensure
not empty
item = x
count = old count + 1
end
remove is
-- .
require
not empty
do
...
ensure
not full
count = old count - 1
end
end
require ensure ; ,
, require - local.
feature, ,
. Access, Status report, Element change -
, .

, . :
put , ;

remove item .
, , .
, .

, . :
put ; ,
.
remove , .
, ,
, ,
, .
old. , , remove item
count. old e, e - ( - )
, . e,
old, .
put :
count = old count + 1
, put, , count
.

,
; put , , empty true
put? ,
- (it depends).
, . ,
. ,
.
, .
,
. .
, .
.
. .
, , , ;
. ,
, , , , ,
.
, ,
- old.
, old ? :
(, ) ; - (
) .
,
- , ,
, (reliability is built-in),
.

r require pre ensure post, :


" r , pre,
post".
- , .
, , ,
. ,
; ,
. .
: ,
. .
: .
.
:

11.1. : put
put

( :)

( :)

put(x) .

: , x
, (item x, count
).

( :)
: x
(item x), count ,
.

( :)

, .

() :
, , , .
, - .
, ,
, .
, , . , " ".
, .
, ,
, ; . ,
:
sqrt (x: REAL): REAL is
-- x
require
x >= 0
do ... end
, x,
, .
, . .
, do :
if x < 0 then
" -"
else
" "
end
, , !
:
-

, ,
" " (defensive programming).
, ,
. , ; ;
, .
: . ,
, . , ,
, . , ,
sqrt, x<0,
x>=0. ? , sqrt,
, .
- .
, .
. - .
, .
(
) (if x<0 then ...), , -
. , . , , , ,
. ,
- . , .
, .
,
- . ,
- . ,
; , . ,
. ,
, . ,
, .
,
. , ,
; - , , . ,
.
, .
, ,
: , , ,
..
. .
, .
. , , ,
, .
,
; .
,
- .
, - ,
- .
-: - .

. ,
( - ).
: - , - .
, read_positive_integer,
. :
require
input > 0

, . .
, if - then - else;
.
.
, ,
- , , . .
, - "".

. 11.1. -
. - ,
, ,
.
- .
, . ,
.

- ,
. , . sqrt,
, - ,
- require . :
if - then - else, case Pascal, inspect,
.
. . sqrt ,
, x<0, "" (bug).
(1)
"" .
"" , .
, :
(2)
"" .
"" .
, - " ".
, , , ,
. , ,
, , .
, , ,
, . , , : ""
, .
,

"" -
. . , ""
- , "" , , . , , -
. ,
( ) , .
,
(Error) - , .
(Defect) - ,
.
(Fault) - ,
.
: , , ,
.
"" (" , "?).
.
.


,
. , , ,
.

STACK (STACK1).
, .
.
, .

. 11.2.
, representation, 1 capacity:
count, . , ,
, ,
, . c ,
, ,
Array. .
. , a , x i- ,
: a.put(x,i). i- : a.item(i) a @ i. , ,
, i : 1<= i <= capacity.
indexing
description: ": Last-In, First-Out %
% - , "
class STACK2 [G] creation
make

feature - Initialization ()
make (n: INTEGER) is
-- , n
require
positive_capacity: n >= 0
do
capacity := n
create representationlmake (1, capacity)
ensure
capacity_set: capacity = n
array_allocated: representation /= Void
stack_empty: empty
end
feature - Access ()
capacity: INTEGER
--
count: INTEGER
--
item: G is
--
require
not_empty: not empty -- i.e. count > 0
do
Result := representation @ count
end
feature -- Status report ( )
empty: BOOLEAN is
-- ?
do
Result := (count = 0)
ensure
empty_definition: Result = (count = 0)
end
full: BOOLEAN is
-- ?
do
Result := (count = capacity)
ensure
full_definition: Result = (count = capacity)
end
feature -- Element change ( )
put (x: G) is
-- x
require
not_full: not full -- .. count < capacity
do
count := count + 1
representation.put (count, x)
ensure
not_empty: not empty
added_to_top: item = x
one_more_item: count = old count + 1
in_top_array_entry: representation @ count = x
end
remove is
--
require
not_empty: not empty -- i.e. count > 0
do
count := count - 1
ensure
not_full: not full
one_fewer: count = old count - 1
end
feature {NONE} -- Implementation ()
representation: ARRAY [G]
-- ,
invariant
... ...
end

. ,
invariant, , .
.
, ,
-, .
. - ,
.
feature. ,
, , .
, Implementation,
representation. .
- , .
feature , Feature
(Feature Clause Comment). - ,
. , , , STACK1
Initialization ().
feature Feature
.
()
STACK2 -
.
empty full . full:
full: BOOLEAN is
-- ?
do
Result := (count = capacity)
ensure
full_definition: Result = (count = capacity)
end
, Result (count = capacity).
Result. ?
?
. ,
. ,
, , .
(prescriptive), (descriptive). "",
"". , - .
, - .
.
- .
( ),
.
. ,
2 . ,
, , v2, (applying "") .
, , - -
. ,
. , .
, .

.
: abs(Result^2 -x) <= tolerance, abs - , tolerance . , ,
, .

, .
put STACK2 ,
:
if count = capacity then Result := True else Result := False end
, :
if count = capacity then Result := True end
, :
, ,
. (short form),
.
: -
. .
,
:

11.2.



() make STACK1 .
n>=0 , , . n=0, make ,
make, 1 0 . ,
, ,
, .
, . ,
put item.
, ,
. , ,
, - .
, , .
: ?
_, ,
, ,
.
? .
.
.
. ,
.
(demanding), - (tolerant). STACK2
, , , :
remove is
--
do

if empty then
print (": ")
else
count := count - 1
end
end
, ,
, ,
.
, , :

. 11.3.
? , ,
, .
;
. ,
, ?
. ,
. remove ,
. , , ,
? ,
- , , , .
- , , , , . ,
, . , :
, , , ,
.
, :
if x < 0 then
" -"
else
" "
end
"-". then , : ,
x<0. , -
, , ...
, remove, ,
, , , -
.

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

, . ,
, , integer . ,
,
.
: ,
. , ,
False, .
"" :


:
1. , .
2. , .
, .
, . ,
, , not empty
, , -
. x>0
, - .
. , put STACK2
require not full .
, STACK2
, , , indexing . ,
, ,
.
;
, .
, 1), STACK2 ,
; ,
.

, ,
. ,
, .
:
-- : , .
class SNEAKY feature
tricky is
require
accredited
do
...
end
feature {NONE}
accredited: BOOLEAN is do ... end
end

tricky , ,
accredited.
, tricky. ,
.
, , ,
, ,
, .
,
(tricky) (accredited). ,
, , feature
, feature {A, B, ... }, A, B, ...
. :

, , ,
.
, ,
. SNEAKY , ,
tricky . ,
accredited. tricky feature feature {A, B,
C}, accredited , , A, B, C,
feature, tricky. accredited feature- :
feature {A, B, C}, feature {A, B, C, D, ...} feature.
. SNEAKY, , .
. ,
. ,
, .
put STACK2:
put (x: G) is
-- x
require
not full
do
...
ensure
... ...
in_top_array_entry: representation @ count = x
end
, count
. , put (
), representation . .
, (" "), ,
, .
- , .

( .)
,
. ,
. ,
, ""
.
, , ,
, . STACK3,
, .
,
"unique" .

:
a, b, c, ...: INTEGER is unique
a, b, c .
,
( ). ,
,
, Underflow.
. , ,
, .
, ,
.
indexing
description: ": Last-In, First-Out %
% - , ; %
% , %
% ."
class STACK3 [G] creation
make
feature - Initialization ()
make (n: INTEGER) is
-- , n , n > 0;
-- Negative_size.
-- !
do
if capacity >= 0 then
capacity := n
create representation.make (capacity)
else
error := Negative_size
end
ensure
error_code_if_impossible: (n < 0) = (error = Negative_size)
no_error_if_possible: (n >= 0) = (error = 0)
capacity_set_if_no_error: (error = 0) implies (capacity = n)
allocated_if_no_error: (error = 0) implies (representation /= Void)
end
feature - Access ()
item: G is
-- , ;
-- .
-- Underflow.
-- !
do
if not empty then
check representation /= Void end
Result := representation.item
error := 0
else
error := Underflow
--
end
ensure
error_code_if_impossible: (old empty) = (error = Underflow)
no_error_if_possible: (not (old empty)) = (error = 0)
end
feature -- Status report ( )
empty: BOOLEAN is
-- ?
do
Result := (capacity = 0) or else representation.empty
end
error: INTEGER
-- ,
-- ,
full: BOOLEAN is

-- ?
do
Result := (capacity = 0) or else representation.full
end
Overflow, Underflow, Negative_size: INTEGER is unique
--
feature -- Element change ( )
put (x: G) is
-- x , ; .
-- !
do
if full then
error := Overflow
else
check representation /= Void end
representation.put (x); error := 0
end
ensure
error_code_if_impossible: (old full) = (error = Overflow)
no_error_if_possible: (not old full) = (error = 0)
not_empty_if_no_error: (error = 0) implies not empty
added_to_top_if_no_error: (error = 0) implies item = x
one_more_item_if_no_error: (error = 0) implies count = old count + 1
end
remove is
-- , ; .
-- !
do
if empty then
error := Underflow
else
check representation /= Void end
representation.remove
error := 0
end
ensure
error_code_if_impossible: (old empty) = (error = Underflow)
no_error_if_possible: (not old empty) = (error = 0)
not_full_if_no_error: (error = 0) implies not full
one_fewer_item_if_no_error: (error = 0) implies count = old count - 1
end
feature {NONE} - Implementation ()
representation: STACK2 [G]
--
capacity: INTEGER
--
end - class STACK3
( , True ).
, ,
. , s.remove, s
STACK3, s.error 0; - Underflow.
. s.error
. , , STACK3 ,
: , ...
, .
, :
- , ,
- . ,
-. , , -
, ,
.
.
.
STACK3 - representation, STACK2,
, , .

, , .
or else or, True, ,
.
check, put remove,
. .
: , , STACK3 STACK2,
. , ,
. , ,
. , - -
. ,
, , ,
. (tough love) ;
,
, , .
, ,
. , ,
- .
, . ,
, . STACK3
.


.
. (class invariants),
, .

STACK2:
class STACK2 [G] creation
make
feature
? make, empty, full, item, put, remove?
capacity: INTEGER
count: INTEGER
feature {NONE} -- Implementation
representation: ARRAY [G]
end
- representation capacity, count - .
,
, . , count :
0 <= count; count <= capacity
, capacity >=0 capacity :
capacity = representation.capacity
, ,
. ,
.
.
. , STACK2
, empty count:
empty = (count = 0)
, , empty.
, .

. , ,
Bank_Account : deposits_list, withdrawals_list balance.
:
consistent_balance: deposits_list.total - withdrawals_list.total = balance
total ( ).
, ,
.

, invariant,
feature, end. :
class STACK4 [G] creation
... STACK2...
feature
... STACK2...
invariant
count_non_negative: 0 <= count
count_bounded: count <= capacity
consistent_with_array_size: capacity = representation.capacity
empty_if_no_elements: empty = (count = 0)
item_at_top: (count > 0) implies (representation.item (count) = item)
end
C ,
"" . :
, create a create a.make(...), a C;
a.r(...) r .
, ,
:

. 11.4.
. - - .
create a create a.make(...) clone
S1 . : , ,

a.f(..). ,
.
,
: S1, S2, S3 .. , .
,
, .

, . ,
g, , , , ,
. , ,
, .
, - , ,
.

a.f(...), ,
, .
f(...), ,
. , ,
. , ,
.
, ,
:

Inv ,
:
1. , , ,
, , ,
Inv.
2. , , Inv
, , Inv.
, :
, ,
, .
(
).
.
, , (
old) , , , Result.
.
, .
.
,
? , () ,
- . , 2).

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

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

.
,
. , ,
. :
.
. ,
. body , pre - , post - ,
Inv - . :
{INV and pre} body {INV and post}
, body, , Inv pre,
, Inv post. , body,
"" "" , ? ,
, ! ,
, .
, . , body, :
: , ,
.
:
.
, .
, ,
. ,
.
BANK_ACCOUNT, , :
deposits_list.total - withdrawals_list.total = balance
. , deposits_list,
withdrawals_list, balance ,
. ,
. withdraw, ,
- balance.
, balance , , , , ,
: deposits_list.total - withdrawal_list.total. withdraw
.
( )
.

?
, ,

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

, ,
, .
, ,
, - . , ,
. : ,
, , ,
.
{P} A {Q} .
C , Inv - , r - . Bodyr - ,
prer (xr ), postr (xr ) - xr .
r , True.
, DefaultC , , C
, . , DefaultSTACK2 STACK2
:
representation = Void
capacity = 0
count = 0
:
:
C , :
1. xp p:
{DefaultC and prep (xp )} Bodyp {postp (xp ) and Inv}
2. r xr :
{prer (xr ) and Inv} Bodyr {postr (xr ) and Inv}
,
(. 11.4). (1) ,
(S1
), . (2) ,
r (f g ), (S1, S2, S3), ,
, ,
.
:
creation, ,
- nothing . (1) Bnothing ,
DefaultC Inv; ,
.
, ,
, .
, . ,
. .

( ),

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

ARRAY .
. , .
, , .
: .
, count, lower upper. count
, .
indexing
description: " %
% , - %"
class ARRAY [G] creation
make
feature - Initialization ()
make (minindex, maxindex: INTEGER) is
-- minindex maxindex
-- ( minindex > maxindex).
require
meaningful_bounds: maxindex >= minindex - 1
do
...
ensure
exact_bounds_if_non_empty: (maxindex >= minindex) implies
((lower = minindex) and (upper = maxindex))
conventions_if_empty: (maxindex < minindex) implies
((lower = 1) and (upper = 0))
end
feature -- Access ()
lower, upper, count: INTEGER
-- ; .
infix "@", item (i: INTEGER): G is
-- i
require
index_not_too_small: lower <= i
index_not_too_large: i <= upper
do ... end
feature -- Element change ( )
put (v: G; i: INTEGER) is
-- v i
require
index_not_too_small: lower <= i
index_not_too_large: i <= upper
do
...
ensure
element_replaced: item (i) = v
end
invariant
consistent_count: count = upper - lower + 1
non_negative_count: count >= 0
end

, , item put.
,
, .


, , ,
. , ,
, .
, .

, :
, ( TYPES);
( FUNCTIONS);
, ( AXIOMS);
( PRECONDITIONS).
. ,
, .
put, remove ,
, . , ,
. (
, - - put, remove, item, ,
- push, pop, top).
: ,
, .
, .

, ,
- .
: , . , , f
f : A B ...

, , T, A, B, ... X, :
, f ;
.
, f ,
. ;
, , .
, , f ,
. f
( ), , ,
.


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

STACK STACK4
( , STACK2).

.
, [Hoare
1972a], " ".

. 11.5.
- , - , . af
cf. , , af A
.
, , (abstraction function),
- - ( ).
, , .
, ( af cf) , ,
, :
-
(cf;a) = (a;af)
";" . , f g,
: f;g h, h(x) = g(f(x)) x.
( f;g : g f, .)
, CONC_1 ,
( , af cf, );
, , -
ABST_2. , :
cf, , a(cf(CONC_1)).
, - af, af(a(CONC_1)).

, .
, , , ,
. , STACK4:

count_non_negative: 0 <= count


count_bounded: count <= capacity
,
(implementation invariant). , ,
( count, capacity, representation) - .
. 11.5 .
, . .
, , ? , ( )
,
, .
( - ) .
(representation relation); , ,
. ,
<representation, count>, ,
. 11.6. count
representation 1 count, - capacity , count; , count
.
, ,
, (
, a). , ,
remove STACK4 , count
count := count - 1
. , count,
CS,
a(CS).
, . - ,
. <representation, count>
. count , , representation
1 count.

. 11.6.
, , ,
: 342, -133, 5. ,
.
, , . , ,
. (
).
:
. , <representation,
count> . representation
3 count = 4, . (,
), - , count 0
. .
,
. , , .
( , .)
, .
, . , -
- .


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

:
check
assertion_clause1
assertion_clause2
...
assertion_clausen
end
, , ,
, ( check end) .
, . ,
, .
. ,
- sqrt(x) x>=0. , ,
:
if x >= 0 then y := sqrt (x) end
, , :
x := a^2 + b^2
check :
x := a^2 + b^2
... ...
check
x >= 0
-- x .
end
y := sqrt (x)
if... then..., sqrt; check , .
,
. ; ,

.
,
, , .

s.remove
, , s , n ,
m, , n>m. : if (not s.empty) then ...; ,
, ,
" " , . ,
:
check not s.empty end
, x.f , x/=Void,
if (x/=Void) then ..., , , x
. put remove " "
STACK3. put:
if full then
error := Overflow
else
check representation /= Void end
representation.put (x); error := 0
end

, else : representation.put(x) ,
: (representation /=Void). , , ,
(full = false) capacity, , , ,
representation Void. ,
. ,
:
check
representation_exists: representation /= Void
-- representation_exists ,
-- full , .
end
,
, , , . ,
, , ,
, . , , ,
, , , ,
, . check
, .
, , ,
, , .
, check .
, , ,
, ,
. .
checking - .


.
.
-, .

, ,
- , -
. . , ,
- , -
, .
. , - .
:
"-" ( ).
, .
, , .
("") .
- " " (Computer Science 101)
- "" .
, t 1 n.
: x . ,
"", , "" ,
x. , , : x
, , , x
, , - .
. .
, .
, .
, t @ m t m. // ,
7 // 2 6 // 2 3. , .
from .

11.3. ()

BS1
from
i := 1; j := n
until i = j loop
m := (i + j) // 2
if t @ m <= x then
i := m
else
j := m
end
end
Result := (x = t @ i)

BS2
from
i := 1; j := n; found := false
until i = j and not found loop
m := (i + j) // 2
if t @ m < x then
i := m + 1
elseif t @ m = x then
found := true
else
j := m - 1
end
end
Result := found

BS3
from
i := 0; j := n
until i = j loop
m := (i + j + 1) // 2
if t @ m <= x then
i := m + 1
else
j := m
end
end
if i >= 1 and i <= n then
Result := (x = t @ i)
else
Result := false
end

BS4
from
i := 0; j := n + 1
until i = j loop
m := (i + j) // 2
if t @ m <= x then
i := m + 1
else
j := m
end
end
if i >= 1 and i <= n then
Result := (x = t @ i)
else
Result := false
end


.
, (loop invariant),
. (loop variant), , ,
. ,
.
, -
(successive approximations).
,
:
maxarray (t: ARRAY [INTEGER]): INTEGER is
-- t
require
t.capacity >= 1
local
i: INTEGER
do
from
i := t.lower
Result := t @ lower
until i = t.upper loop
i := i + 1
Result := Result.max (t @ i)
end
end
i , Result -
- .
. , ,

i 1, Result t @ i,
Result. max,
integer: a.max(b) a b.
.
: [lower, lower], [lower, lower+1], [lower, lower+2]
[lower, upper].
, Result
.
. , .
, .
, Result ,
.

. 11.7.

,
. , ,
n- POST. POST , . ,
" ". , , ,
m- INV, POST ( m>n). ,
POST. POST,
INV. :

. 11.8. ( [ 1990])
:
post, , .
: "Result ". post
POST.
inv, , , -
. : "Result ".
, : " , POST.
init, , INV,
.
body, INV, POST, POST,
INV. maxarray
.
body, INV POST.
, .
.
. , ,
, .
1/n 0, 0.
, ,
.
.
, , ,
.

- , :
.
.
,
. ,
body, POST. : t.upper
- i. :
t.capacity; ,
. ARRAY : capacity = upper - lower + 1.

, i <= t.upper i
t.lower.
i := i + 1, .

, , " For" " DO",
. ,
,
.
, ,
. ,
() post. , INV, POST
INV, exit , INV POST
, exit. , post inv :
post = inv and exit
, - inv, -
exit. , , post.

, .
, .
inv - .
exit, inv .
var - .
, , inv ,
var .
body, ( , , var
inv), var, ,
.
:
from
init
invariant
inv
variant
var
until
exit
loop
body
end
invariant variant . from ,
init .
: init, 0
, , exit false.
Pasal, C " while", "repeat ... until",
, , . ,
, .
Pascal :
init;
while not exit do body
maxarray :
from
i := t.lower; Result := t @ lower
invariant

-- Result t [t.lower,i].
variant
t.lower - i
until
i = t.upper
loop
i := i + 1
Result := Result.max (t @ i)
End
, , .
.
, .
- (gcd - greatest common divisor) a
b, :
gcd (a, b: INTEGER): INTEGER is
-- a b
require
a > 0; b > 0
local
x, y: INTEGER
do
from
x := a; y := b
until
x = y
loop
if x > y then x := x - y else y := y - x end
end
Result := x
ensure
-- Result a b
end
, gcd
a b? ,
:
x > 0; y > 0
-- <x, y> , <a, b>
inv. , inv .
inv x /= y, :
if x > y then x := x - y else y := y - x end
inv ,
gcd . :
x = y and <x, y> , <a, b>
, , , x . (x, x)
= x.
, ? . x y, x
x-y. y x, y y-x.
x, y, . ,
. x.max(y).
, . :
from
x := a; y := b
invariant

x > 0; y > 0
-- <x, y> , <a, b>
variant
x.max (y)
until
x = y
loop
if x > y then x := x - y else y := y - x end
end
, invariant variant . ,
.
; ,
.


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

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

, .
,
.
,
, $500 .
short ,
, . -
. , ,
, .
, , ,
.
STACK4:
indexing
description: ": Last-In, First-Out %
% - , "
class interface STACK4 [G] creation
make

feature -- Initialization ()
make (n: INTEGER) is
-- , n
require
non_negative_capacity: n >= 0
ensure
capacity_set: capacity = n
end
feature -- Access ()
capacity: INTEGER
--
count: INTEGER
--
item: G is
--
require
not_empty: not empty -- i.e. count > 0
end
feature -- Status report ( )
empty: BOOLEAN is
-- ?
ensure
empty_definition: Result = (count = 0)
end
full: BOOLEAN is
-- ?
ensure
full_definition: Result = (count = capacity)
end
feature -- Element change ( )
put (x: G) is
-- x
require
not_full: not full
ensure
not_empty: not empty
added_to_top: item = x
one_more_item: count = old count + 1
end
remove is
--
require
not_empty: not empty -- i.e. count > 0
ensure
not_full: not full
one_fewer: count = old count - 1
end
invariant
count_non_negative: 0 <= count
count_bounded: count <= capacity
empty_if_no_elements: empty = (count = 0)
end
,
class interface class.
, , .
ISE Class Tool;
, HTML, RTF, MML (FrameMaker), TEX .
.
, ,
, representation, .
:
, , .
, . ,
"", . , "", "",

. ,
indexing, ,
.
,
, ,
. , , - ,
. , .
, .
. ,
. , , " "
, .
Ada, ()
- . Java .
, :
, .
, .
: , , ,
. (
) , , ; ,
.
, - - (flat-short form),
, -. -
, ,
,
.
-, ,
, . :
. -
.

, : " ?".
, , .
, Ace .
, Ace Lace, .
, Lace , ;
.
.
Ace , :
system painting root
GRAPHICS
default
assertion (require)
cluster
base_library: "\library\base"
graphical_library: "\library\graphics"
option
assertion (all): BUTTON, color_BITMAP
end
painting_application: "\user\application"
option
assertion (no)
end
end -- system painting
default ,
(require). . graphical_library
(all) BUTTON color_BITMAP. painting_application
.
- , , .

, ,
assertion(...):
no - . ,
;
require - ;
ensure - ;
invariant -
(obj.f);
loop - ;
;
check - check, .
all check.
"no" . ,
, .
check all.

, .
false, , . ,
, , ,
. , , (exception history table)
:
Failure: object: O2 class: YOUR_CLASS routine: your_routine
Cause: precondition violation, clause: not_too_small
Called by: object: O2 class: YOUR_CLASS routine: his_routine
Called by: object: O1 class: HER_CLASS routine: her_routine
...
, , ,
- , , .
;
.
, , not_too_small
your_routine (x: INTEGER) is
require
not_too_small: x >= Minimum_value
...
, , .
?
? ,
: , ,
.
:

( ). -
, .
, . ,
, ,
.
, ,
, - .
, "
" . C. A. Hoare:
, ,
, .
, -
, [Hoare 1973].

, . ,
,
. ,
. , , ,
, , , ,
.
, , Ace .
.
. ,
. . ,
, ,
, , , ,
.
- .
, . ARRAY ,
put, item - @, - :
index_not_too_small: lower <= i
index_not_too_large: i <= upper
,
: , ,
, .
,
. ,
.
. ARRAY, assertion(require).
? :

. ,
, . ,
, - ,
. ,
.
.
, .
" ",
.
- . , , ,
, " "
, . - (fault),
- . ,
. , .
, ,
. , , .
, - ,
. ?
" ?".
.
10 , , ,
, .
, .
, - .
, , ? , , , ,
. ISE
( , , , ) 50%.
, - 75% ,
, , .
: , ,

, . ,
100% 200%.
- , ,
, , :
,
- . ,
, . ,
.
, , ,
. , , - ,
, , , ,
.
, - . , 12
. ,
, .
. , ,
. , - !
, . , 12
, , 6
, 12, 12 , , ?
, "
", "".
, ,
. .
, ,
. , ,
, .
, ,
. , -
. ,
.
, , ,
.
.
.
,
. , ,
.
,
, , . ,
, ,
, .

- ,
.

, , ,
.
?
, ? , ,
, :
, , ,
,
. m+n ( m
n ), .
, .
, .

, .
, , . IFL, ,
.
, ,
, .
- , .
- , .

, ,
, old. ,
, ,
.
, , .
, , 6,
. ,
A4. not empty (put (s, x))
not empty put.
. remove, ,
A2. remove (put (s, x)) = s
, , , ,
:
remove is
--
require
not_empty: not empty -- i.e. count > 0
do
count := count - 1
ensure
not_full: not full
one_fewer: count = old count - 1
LIFO_policy: -- item ,
-- , .
End
, ,
maxarray gcd.
, , ,
, , :
(, ). ,
, , .
, . , .
- , , , .
, , ,
. , ,
, . Z, VDM, Larch, OBJ-2;
Z, VDM -, , Object-Z. 6
.
.
, , , .
, C
Fortran.
, :
, ,

- , ,
.
. ,
.
, .

. , .

.
: put not full, full
full: BOOLEAN is
-- Is stack full? ( ?)
do
Result := (count = capacity)
ensure
full_definition: Result = (count = capacity)
end
, - ,
, . ,
, , .
full,
. .
. , -
,
index_not_too_small: lower <= i
index_not_too_large: i <= upper

index_in_bounds: correct_index (i)

correct_index (i: INTEGER): BOOLEAN is
-- i ?
do
Result := (i >= lower) and (i <= upper)
ensure
definition: Result = ((i >= lower) and (i <= upper))
end
,
, - .
maxarray
-- Result t [t.lower,i]

Result = (t.slice (lower, i)).max
, slice - lower i, - max
.
[M 1995a] ,
, - ,

. . -
, , ,
, . -
- IFL (Intermediate Functional Language),
, . IFL ,
, .
, :
() , , .
, : , .
.
,
.
, ,
.
, , , . , ,
, , - .
,
, , , " "
( ). r+
r = , r -
+
, . ,
, .
, cyclic,
true, .

.
.
, ,
"", , -
.
; IFL
, ,
, :
;
;
, IFL.
, ,
.
. f,
r, , full correct_index.
: r
, f, f?
, .
f. , " " ,
, r, , f.
, , ,
, . :

,
.
f r, ,
f . , f
, r.
f , .
, , .

-, , , :
, .
, ,
.
,
.
,
, . ,
m+n , ( INV,
, ):
1. m , INV.
2. n INV.
, , INV .
: INV ,
INV .
, ,
. , .
a.r INV , , b.s ( b,
,) INV . (1) (2) ,
INV .
. , , :
class A ... feature forward: B ... end
class B ... feature backward: A ... end
, . forward
, backward , ,
. :
round_trip: (forward /= Void) implies (forward.backward = Current)
, :

. 11.9. forward backward


round_trip . ,
PERSON, . forward
- HOUSE. backward .
- ,
. round_trip:
, , , backward.
- :
class A feature
forward: B
attach (b1: B) is
-- b1 .
do

forward := b1
-- backward b1 :
if b1 /= Void then
b1.attach (Current)
end
end
invariant
round_trip: (forward /= Void) implies (forward.backward = Current)
end
b1.attach forward.
attach:
class B feature
backward: B
attach (a1: A) is
-- a1 .
do
backward := a1
end
end
:
, forward void,
. :
a1: A; b1: B
...
create a1; create b1
a1.attach (b1)
b1.attach (Void)
:

. 11.10.
. , , - backward
void. b1.attach .
? .
, attach
. ,
, ,
.
, : (Indirect
Invariant Effect). ,
. ,
; forward - backward
, , , .
?
. , , ,
assertion (invariant) :

" ".
? ,
. ,
, ,
, .
,
, , ,
, .
, :
trip_round: (backward /= Void) implies (backward.forward = Current)
, , . ,
,
.

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


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


[Hoare 1981]:
, .
24 1950 . " ",

. " , ,
? ,
, ,
."
, , ,
[Floyd 1967], [Hoare 1969], [Dijkstra 1976],
[Gries 1981]. " " (Introduction to the Theory of
Programming Languages) [M 1990] .
[Hoare 1972a] .
[Jones 1980], [Jones 1986].
[Goguen 1978].
, Z, VDM, OBJ-2, Larch,
6. [Lano 1994] , , -
, Object Z, Z++, MooZ, OOZE, SmallVDM, VDM++.
, , IEEE Computer
Society [IEEE 1990], [IEEE1993]. Web- - http://www.computer.org
, .
(, ) AlgolW, [Hoare
1966], Pascal. Alphard [Shaw 1981] Euclid [Lampson
1977], . - ,
, CLU [Liskov 1981], .
, CLU [Liskov 1986]
, ,
" ", .
,
, [M 1987a], [M 1988], [M1989c], [M 1992a]. [M 1994a]
,
,
" ". - [McKim
1995], [McKim 1996], [McKim 1996a], [Henderson-Sellers],
.

11.1
COMPLEX,
. .
11.2
STACK, , ,
STACK4, , .
11.3
, body, ,
STACK .
.
11.4
capacity , STACK2?
11.5
STACK3.
11.6
, , correct_index
put item. ARRAY,

?
11.7 (bugs)
, , "",
. (: ,
, : ,
, , ,
).
11.8
, ,
. ,
.
11.9
, , :
ni = f(ni - 1 ), f , n0 .
. f , [Knuth 1981]
.
11.10 ""
, ( " - ", FIFO - "first in - first
out"). STACK .
11.11 ""
, :
, , , .
. ,
.

: 5
,
5, 4
1996 40 , 500 (
).
: . :
, 64 , 16-
. (horizontal bias) .
, ADA, .
, , ,
.
: . , -
4. 5,
, , .
5. :
require
horizontal_bias <= Maximum_horizontal_bias
, ,
, .
, , , , ,
, , .
: . , ,
, , , . ,
. , ,
.
, :

, :
.
.
.
1)

6; , ,
6.9.
2) 11.8. .
" " .

-
12. : :
, , ,
. ,
.


, .
, , PL/I Ada,
: , ,
goto, .
, , ,
.

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

, "".
- ( ,
), . .
:
- , .
. , ,
, ,
. - :
, .
(fault) , , (defect) , , (error) -
, . - ; , ,
, , ,
.

, .
:
r .
1. a.f , a = Void.
2. Void (expanded) .
3. ,
.
4. , .
5. r .
6. r .
7. .
8. from
.
9. .
10. check.
11. , .
(1) : a.f , a
, , a void. 8
.
(2) void . , "" (attachment)
, . " "
8 ,
. , void,
.
(3) , .
(4) , ,
. , ,
(4):

- .
(5)-(10) , :
assertion (require) (5), assertion (loop) (8) (9) .
(11) raise, ( ) .
.

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


, , - - ,
, - .
, . , -
?
,
. C, Unix, Ada.
- C-Unix

- C-Unix
( Unix,
, C) signal, :
signal (signal_code, your_routine)
- your_routine,
, (signal_code). - ,
, SIGILL ( - illegal instruction) SIGFPE ( floating-point exception). signal,
, .
,
. signal,
. , - your_routine,
. , , ,
, ( ). , ,
.
- ,
, . , ,
. , C, .
signal : setjmp, ,
, longjmp . setjmp-longjmp
. ,
-,
.
- Ada
, 1) Ada.
sqrt (x: REAL) return REAL is
begin
if x < 0.0 then
raise Negative
else
normal_square_root_computation
end
exception
when Negative =>
put ("Negative argument")
return
when others => ...
end -- sqrt
, , Ada,
(, , ).
, . ,
. Ada
, ,
.
.
? Ada , ,
.
raise Exc Exc.
exception, :
exception
when code_a1, code_a2, ...=> Instructions_a;
when code_b1, ... => Instructions_b;
...
, when,

. , , when others, ,
when.
when others, ,
, , main
.
,
Negative .
? :
put ("Negative argument")
return
- , ,
, , , .
Ada, ,
, ,
.
, , , C-Unix , , ,
, . when,
return, ; ,
, .
Ada-: when
return. "" ,
(false alarm), , .
.
, . Ada :
exception raise ,
, .
, .
Ada
raise,
.

.
.

, :
1. (Retrying) - , ,
, .
2. (Failure) - " " (organized panic):
, .
, ( (3) )
" ". , ,
.
- ,
C-Unix. . ,
. ,
, ,
. ,
, .
, .
- ,
.
, .
, , .

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

, ,
. Ada.

. 12.1.
r0 ( Ada main).
, .
, , .
(r0 , r0 r1 , r1 r2
) .
, , , ,
, . ,
r0 .


, -
.
. ,
, EXCEPTIONS.
(Rescue Retry)

, ,
. rescue,
, . rescue
, ,
:
routine is
require
precondition
local
... ...
do
body
ensure
postcondition
rescue
rescue_clause
end
rescue_clause .
, rescue.
,
.
retry, retry.
rescue. ,
. , , .
.
retry ; rescue, retry
.

.

rescue, retry, ,
.
, , ( (4) ),
, - rescue.
, rescue.
.
.
, , rescue :
routine is
do
body
end
, , , rescue
rescue, :
routine is
do
body
rescue
-- ( )
end
: ,
rescue, , .

rescue, ,
. ,
.

, - rescue, ,
retry, ,
(4) - .
: rescue, ,
. ,
, .
- .
:

12.1.

O4

Z_Function split (from E_FUNCTION)

O3

INTERVAL

integrate

O2

EQUATION

solve (from
GENERAL_EQUATION)

O2
O2

EQUATION
MATH

O1(root) INTERFACE

Feature interpolate: c
void

interval_big_enough:

filter

new_matrix (from
BASIC_MATH)

enough_memory: Check

make

, , , ,
, rescue - retry.
, , 100 .
, .
.
, .
; O1 ,
, ,
. , .
, . , ,
, , interval_big_enough,
.
, , , .
, . ,
, , . ,
, , .
, - , .
, ,
make, .

. 12.2. ,


, , , .

, ,
. - read_one_integer,
last_integer_read. , -
, , , . , ,
. ,
, .
:
get_integer is
--
-- last_integer_read.
-- , , ,
-- .
do
print (", : ")
read_one_integer
rescue
retry
end
.
- ,
. . , 5, .
:
Maximum_attempts: INTEGER is 5
-- , .
get_integer is
-- , Maximum_attempts .
-- integer_was_read true false
-- .
-- last_integer_read.
local
attempts: INTEGER
do
if attempts < Maximum_attempts then
print (", : ")

read_one_integer
integer_was_read := True
else
integer_was_read := False
end
rescue
attempts := attempts + 1
retry
end
, integer_was_read.
,
n:
get_integer
if integer_was_read then
n := last_integer_read
else
" , "
end
,
, , , ,
. : ,
-, , ,
(, break).
, . a+b
, , +
, , .
( ) -
. - , - , , -
. ,
. - , ,
, .
quasi_inverse, x
1/x 0, x .
, .
, x , .
, ,
, 0 .
invertible, invertible(x) true,
. quasi_inverse.
,
.
rescue-retry , , ,
:
quasi_inverse (x: REAL): REAL is
-- 1/x, , 0
local
division_tried: BOOLEAN
do
if not division_tried then
Result := 1/x
end
rescue
division_tried := True
retry
end

false division_tried .
else, Result 0.
,
, , ,
. .
, , , ,
. , (
), , ,
, . ,
.
, , , ,
:
from ... until exit loop
execute_one_command
end
execute_one_command :
" "
" , "
" ..." (, ,
). ,
, .
, .
. , ,
:
execute_one_command is
-- , ,
-- .
do
" "
" "
rescue
message (", ")
message (", ")
message (", ")
", "
retry
end
, : "
", " ". .
, "...", ,
. , ,
rescue, , .
N-
, , N-
- , .
N- , .
, ,
, -, ,
, .
.
. ( ,
-). N-
. ,
(). , , ,

.
; , , ,
. , , ,
. retry
, , , :
do_task is
-- , .
require
...
local
attempts: INTEGER
do
if attempts = 0 then
implementation_1
elseif attempts = 1 then
implementation_2
end
ensure
...
rescue
attempts := attempts + 1
if attempts < 2 then
", "
retry
end
end
, , .
retry. rescue
, , , . -
.
, ( n ) rescue ,
retry, , .
, , r.
() ; rescue.
:
rescue retry.
. ,
. , . ,
, . , ,
, rescue.
rescue retry, , end. (
, attempts >=2.)
; , .
,
, .
.
, .
. ,
, .
rescue, , .

rescue
,
rescue. .
rescue
. (1)
, - .
(2) , ,

,
. , , :

. 12.3.
(2) :
2. r xr
{prer (xr ) and INV} Bodyr {postr (xr ) and INV}
xr .
Rescuer rescue, , retry,
, rescue. (2)
- Bodyr . Rescuer ?
:
{ ? } Rescuer { ? }
. (,
.)
, , Rescuer .
! , , . Rescuer
, . !
, , - .
, , "break".
- Rescuer True.
, , Rescuer
.
Rescuer " ", - , " "!
Rescuer ? , rescue , ,
, .
.
, :
rescue
3.

{True} Rescuer {INV}

Retryr - rescue, ,

retry:
rescue
4.

{True} Retryr {INV and prer }


Rescuer :
{prer and INV} Bodyr {postr (xr ) INV}
{True} Rescuer {INV}
Bodyr - , Rescuer ,
( do) .
Bodyr .
Bodyr - , Rescuer
, Bodyr .
.
do rescue.
, . rescue , ,
. rescue .
rescue
rescue, ,
. , .
, rescue
(rescue end). . (3)
:
{True} Rescuer {INV}
Rescuer , True, .
. Any - .
default_rescue, - Any:
default_rescue is
-- , rescue.
-- ( : )
do
end
, rescue,
rescue :
rescue
default_rescue
default_rescue, ,
, ,
GENERAL. ,
.
, , , ,
INV. ,
default_rescue .

, ,
. :
, ,
-.
, .
, .
, ,
. , , . - ,
. - , , ,
. , , - ,
, , .
, .
EXCEPTIONS, . ,
, EXCEPTIONS.
.
EXCEPTIONS
EXCEPTIONS
. , :
exception: INTEGER
--
original_exception: INTEGER
-- -
exception original_exception " ".
oc, ,
rescue, , , exception,
" ".
- - oc,
original_exception.
.
, EXCEPTIONS (
EXCEPTIONS_CONSTANTS). :
Check_instruction: INTEGER is 7
-- check
Class_invariant: INTEGER is ...
--
Incorrect_inspect_value: INTEGER is ...
-- ,
-- , Else
Loop_invariant: INTEGER is ...
--
Loop_variant: INTEGER is ...
--
No_more_memory: INTEGER is ...
--
Postcondition: INTEGER is ...
--
Precondition: INTEGER is ...
--
Routine_failure: INTEGER is ...
--
Void_assigned_to_expanded: INTEGER is ...
, .
, .
:
meaning (except: INTEGER)

-- , except
is_assertion_violation: BOOLEAN
--
--
ensure
Result = (exception = Precondition) or (exception = Postcondition) or
(exception = Class_invariant) or
(exception = Loop_invariant) or (exception = Loop_variant)
is_system_exception: BOOLEAN
--
-- ( )?
is_signal: BOOLEAN
-- ?
tag_name: STRING
-- ,
original_tag_name: STRING
-- .
recipient_name: STRING
-- ,
class_name: STRING
-- ,
original_recipient_name: STRING
-- ,
--
original_class_name: STRING
-- ,
, rescue . ,
, EXCEPTIONS, rescue :
rescue
if is_assertion_violation then
", "
else if is_signal then
", "
else
...
end
EXCEPTIONS, quasi_inverse, retry
. , , "break"
retry. rescue :
if exception = Numerical_error then
division_tried := True; retry
end
else , , Numerical_error, -
, .
rescue , .
.
?
,
. , - ;
, - " !
, !". , , rescue
.
,
, , , fail,
retry.
, , , ,
EXCEPTIONS,
. , EXCEPTIONS ,

. :

, rescue,
- , ,
.

, , (
) ( ).
, .
. ,
, (), , ,
.
rescue.
trigger (code: INTEGER; message: STRING)
-- ,
-- code .
developer_exception_code: INTEGER
--
developer_exception_name: STRING
-- ,
is_developer_exception: BOOLEAN
-- ?
is_developer_exception_of_name (name: STRING): BOOLEAN
-- name?
ensure
Result := is_developer_exception and then
equal (name, developer_exception_name)
- ,
:
set_developer_exception_context (c: ANY)
-- c ,
-- ( trigger).
require
context_exists: c /= Void
developer_exception_context: ANY
-- ,
set_developer_exception_context
-- void, .
,
.
,
. , , ,
, .

, -,
. retry,
, . -
.
, ,
, .

, , ,
: , , void .

, -
, .
(, retry), .
Ada, CLU, PL/1 . Ada
Raise exc
,
, . ,
. ,
. ,
, .
raise goto, , , ,
. , .
. .
,
- .
, .
, ,
. ,
.
?
( , ,
?) ,
. ?
- Pascal Delphi .
. 4
" - ", , .
, .
, , EXCEPTIONS, , ,
. , ,
, . ;
, .
EXCEPTIONS
, .

. ,
, - .
, ,
,
.


- , ,
.
- .
: , ,
, .
, .
- (Retry)
. .
.
, retry,
, .
( do). , retry,
, .
, , ,
- . ,
, EXCEPTIONS,

.
.


[Liskov 1979] [Cristian 1985] . ,
, " " [Randell 1975].
, . "
" rescue, ,
, "" .
[Hoare 1981] Ada.
, , [M 1988e] [M 1988].

12.1
, , .
, ,
, .
12.2 Exception
, ""
, , EXCEPTION,
, , .
EXCEPTIONS, .
, , , .
1) Sommerville, Morrison "Software Development with Ada", Addison-Wesley, 1987.
.

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


, -.
-. ,
, , , Fortran Pascal. .
,
-.

- , (features), , ,
. (granularity)
?
- , -. . , -
:
--
create x l make (clone (a))
(struct A) *x = &y; /* A piece of C */
x.display
, , .
. ,
-. , .
- .
( ) , ,
- - .
.
: , , , ,
, . do external,
. , :
put (c: CHARACTER) is
-- c .
require
write_open: open_for_write
external
"C" alias "_char_write";
ensure
one_more: count = old count + 1
end
alias ,
, . , -,
, , ( ).

.
:

.
-, .
(, , "C:[macro]...").
" " (DLL),
Windows . DLL
.
. DLL ,
DYNAMIC_LIBRARY
DYNAMIC_ROUTINE. , ,
.
,
. ,
(callback mechanism), .
-, .
- .

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

. - . - ARRAY,
, :
make , item
, ..
- .
- . , _char_write
(feature) , put. ,
-, ,
- ,
" ". (" "
.)
- (re-architecturing)
. : , ,
, . , .
- , , - .
- , (wrap),
.
, , -
. ,
: , , , , .
. -
, Fortran C. -
? : , . - ,
. ,
, .
, - (object-oriented re-architecturing)
, .
:
, , ,

, , . -
. ,
- .
. -
, .
,
.
, , . ,
, .
Vision ( 14 " -
") ,

. , "" ,
. ,
.
, Math,
, , ,
, , , ,
. ,
NAG Nag Ltd., Oxford, -.
, ,
, : INTEGRATOR, BASIC_MATRIX, DISCRETE_FUNCTION,
EXPONENTIAL_DISTRIBUTION.
- NAG - .
- : , , ,
, ,
.
.
: ?
,
- . ,
.
- Objective-C, C++, Java, Object Pascal Ada 95 -
- -. (hybrid
languages) - . 17 " - ".
, , -.
: ,
.
, .
- .
, ,
, .
, , -.
Pascal -.
. , C++ ,
, ,
. , , .
, , -, ,
, .
,
. (Interfacing) (mixing)
- .
. ,
, ,
. , , .

- , ,
. : ,
, ,
.


: ,
?

r (a1 , a2 , ..., an )

r (x1 : T1 , x2 : T2 , ..., xn : Tn ) is ...
r , , , b.r
(...). a1 , a2 , ..., an , xi - .
(, "".)
: ?
?
?
: -
. (attachment).
, ,
:
x1 := a1 ; x2 := a2 ;... xn := an
: x .
, :
x x := ...
, x : create x.make (...)
, , , ,
:
, .
- ? - ,
.
(. 8) , . ,
:
( ) , - Void,
.
( INTEGER, REAL ..),
.
, ,
(reference) . ,
.

. 13.1.
xi - r, :
xi .p (...)
p - , xi , ( Ti xi ).
, xi , ,
ai .
q (a) a, a .
a , , , ,
.
,
. - . ,
, 1)
dont_I_look_innocuous (a, b: INTEGER) is --
-- , .
do
a := 0; b := 1
end
dont_I_look_innocuous (x, x). x : 0
1? , -
. , Fortran.
.
, , ,
(. 18).
Current, , a + b.
.
,
x: create x...; x := y; x ?= y,
. x x.
, , - ,
Result. :
, (,
).
, .
.
, . ,
, ,
BOOK, title publication_year. .

2).

-, , :
(commands), (instructions). (
() (statement), , ,
.)
.
, .
: , , , , , , ,
, .

, , .
. .
, .
.
.
:
r ( ),
r (x, y, ...) ( )
, . a -
, C - , - q C,
a.q. , q ; a
, p (m).q (n), p(m) - .
,
(vector1 + vector2).count.
: a.q1 q2 ...qn , a, ,
qi , .
. , f,
B, A ( ), feature, f,
feature ( ) feature {X, Y,... }, {X,
Y,...} A A. :

b.q1 . q2 .... qn , C ,
:
1. , , q1 , C.
2. , , , qi i > 1,
C.
, , a.q.r.s -
b:= a.q; c:=b.r; c.s
, q, r s C, .
, r q, s r.
. a + b, ,
: a.plus (b).
.
(Assignment)

:
x := e
x - , (writable), e - .
:
;
. Result.
, , , , .
(Creation)
3) : ,
create x, , create x.p (...). x ,
.
(Conditional)
.
:
if boolean_expression then
instruction; instruction; ...
else
instruction; instruction; ...
end
( ).
, boolean_expression , - .
else, , :
if boolean_expression then
instruction; instruction; ...
end
, (nesting)
else, elseif, :
if c1 then
instruction;
elseif c2 then
instruction;
elseif c3 then
instruction;
...
else
instruction;
end

instruction; ...
instruction; ...
instruction; ...
instruction; ...

else .
if c1 then
instruction; instruction; ...
else
if c2 then
instruction; instruction; ...
else
if c3 then
instruction; instruction; ...
...

else
instruction; instruction; ...
end
end
end
, inspect,
.
-, ,
, .
, ,
.
, , , .

( , Case) ,
: e = vi , e - , vi - . (if e
= v1 then ...elseif e = v2 then...) , ,
, : "
-, ". :
, ,
, "e =".
, -
(jump table), - .
( e vi ),
. ,
INTEGER, CHARACTER. :
inspect
e
when v1 then
instruction; instruction; ...
when v2 then
instruction; instruction; ...
...
else
instruction; instruction; ...
end
vi ; else ;
.
: e vi ( ),
; , else,
.
else, e vi ,
(" "). ,
.
. inspect vi , else,
, , e vi .
else, : " e vi ".
,
. - - ,
.
- ,
4):
inspect
first_input_letter

when 'D' then


" "
when 'I' then
" "
...
else
message (" ; H ")
end
vi , (unique values),
.
, , Do, Re, Mi, Fa, Sol, La, Si: INTEGER is unique,
: inspect note when Do then...when Re then...end.
,
, .

( 11):
from
initialization_instructions
invariant
invariant
variant
variant
until
exit_condition
loop
loop_instructions
end
invariant variant . from , .
. ,
. ,
initialization_instructions. " ", :
exit_condition , - (null instruction);
, - loop_instructions, ()
.

( 11). ,
:
check
assertion --
end

. :
debug instruction; instruction; ... end
(Ace-) debug.
, -
.
,
, , .


( 12).
rescue, ,
.

, , - .
:
() ;
(, , , Result);
;
( - );
Current.

,
, , 0. ,
.
, - True False. , :
453 -678 +66623
(real) . ,
. , :
52.5 -54.44 +45.01 .983 -897. 999.e12
, , 'A'.
STRING, .

, .
: .
, , , :
b.f
b.g(x, y, ...)
b.h(u, v).i.j(x, y, ...)
, , .

Current
. Current - , , .
Current, , Current := some_value .
( )
Current.f, f. Current , -,
. (, Smalltalk
, .) ,
Current :
, a.f (Current).
- (duplicate) , x: = clone (Current).
,- , x = Current.
Current " " like
Current ( 16).


.
+ -
.
, , :
= /= < > <= >=
/= " ". .
, .
:
+ - . / ^ // \\
// , \\ , ^ ( ).
: and, or, xor, and then, or else, implies.
; xor - .
, , "
". , ,
, .

and then or else ( Ada), implies
(non-strict) . :

a and then b , a , b.
a or else b , a , b.
a implies b , : (not a) or else b.
, , , and or.
, b . ,
, , : a , a
and then b b; a , a and then b b. ,
a implies b , a , b .
, , . :
(i /= 0) and then (j // i = k)
, , , i 0. and, and
then, - i 0 .
:
1. , ,
, .
2. , , , i
0 .
(2), and then. ,
(i = 0) or else (j // i /= k)
, i 0, or .
, -

and or , and then or else?


, , ,
. ,
, ALGOL, W C, .
.
, : a and b
, b and a, a and then b , b
and then a . ,
.
, ,
, ,
. , ,
.
, ,
. ,
b := ((i /= 0) and then (j // i = k))

if i = 0 then b := false else b := (j // i = k) end
, , . , :
from
i := a.lower
invariant
-- [a.lower .. i - 1], (a @ i) /= x
variant
a.upper - i
until
i > a.upper or else (a @ i = x)
loop
i := i + 1
end;
Result := (i <= a.upper)
- Result , x a. or
. ,
(i > a.upper) a
@(aupper+1), (
).
.
- , , , , l
, , :
l.empty or else l.first >= 0
or .
( ).
.
implies, , . implies ,
, , :
(not l.empty) implies (l.first >= 0)

STRING . ,

, STRING.
, ,
"ABcd Ef ~*_ 01"
%, .
STRING, make
,
text1, text2: STRING; n: INTEGER;
...
create text1.make (n)
text1, n . , n -
, .
.
STRING : , ,
.. ( , ,
.)
(sharing): text2 := text1, text1
text2, . , ,
text2 := clone (text1).
:
message: STRING is "Your message here"


KERNEL : FILE STD_FILES.
, f FILE, :
create f.make ("name") -- f name.
f.open_write -- f
f.open_read -- f
f.put_string ("A_STRING") -- f
- , ,
STD_FILES, input, output error.
io, io.put_string ("ABC"), .


- , ,
. ,
.
, Hi, hi, HI hI -
. ,
, Structure structure, .
, .
(. 26 " "): (INTEGER, POINT ...)
(G LIST [G]) ; (Result,
Current...) (Pi)

. ( , ,
) - . ,
,
.


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

13.1
,
, . ,
, .
" " .
13.2
x a, ,
.
1)

: . .
. 5 " - ", ",
".
3) . " " " ", 8.
" ", 14.
4) .
. 3 " - ".
2)

-
14. :
.
, - , .
. - .
. , ,
, : , ;
;
, , .
. , ,
(repetition) (variation), (. 4).
, , ,
, , - ,
, , - .
(extendibility)
, . , ,
, POINT () SEGMENT().

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


. ,
, .

, .
: , , , , , , , , . .
, . ,
. :
indexing
description: " "
class POLYGON creation
...
feature --
count: INTEGER
--
perimeter: REAL is
--
do ... end
feature --
display is
-- .
do ... end
rotate (center: POINT; angle: REAL) is
-- angle center.
do
... . ...
end
translate (a, b: REAL) is
-- a , b .
do ... end
... ...
feature {NONE} --
vertices: LINKED_LIST [POINT]
--
invariant
same_count_as_implementation: count = vertices.count
at_least_three: count >= 3
-- (. 14.2)
end

vertices , -
( ).
rotate.
. .
rotate (center: POINT; angle: REAL) is
-- center angle.
do
from
vertices.start
until
vertices.after
loop
vertices.item.rotate (center, angle)
vertices.forth
end
end
, item LINKED_LIST
. vertices LINKED_LIST [POINT], vertices.item ,
rotate, POINT .
- ( rotate),
, . ( -
.)
.
- .
perimeter:
perimeter: REAL is
--
local
this, previous: POINT
do
from
vertices.start; this := vertices.item
check not vertices.after end -- at_least_three
until
vertices.is_last
loop
previous := this
vertices.forth
this := vertices.item
Result := Result + this.distance (previous)
end
Result := Result + this.distance (vertices.first)
end
. distance
POINT. Result, ,
0. LINKED_LIST : first ,
start , , forth , item
, is_last , , after ,
. check at_least_three
. not after, vertices.item
. forth , , , ,
is_last.

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

(heir) POLYGON. POLYGON,


(parent) RECTANGLE, -.
RECTANGLE (inheritance clause):
class RECTANGLE inherit
POLYGON
feature
... , ...
end
feature - :
. , .
, diagonal, .
, ,
. perimeter.
: , . ,
, ,
redefine:
class RECTANGLE inherit
POLYGON
redefine perimeter end
feature
...
end
feature RECTANGLE perimeter,
POLYGON. redefine,
perimeter RECTANGLE , RECTANGLE
perimeter, POLYGON, .. .
RECTANGLE :
indexing
description: ", - "
class RECTANGLE inherit
POLYGON
redefine perimeter end
creation
make
feature --
make (center: POINT; s1, s2, angle: REAL) is
-- center,
-- s1 s2 angle.
do ... end
feature -- Access
side1, side2: REAL
--
diagonal: REAL
--
perimeter: REAL is
--
-- ( POLYGON)
do
Result := 2 S (side1 + side2)
end
invariant
four_sides: count = 4
first_side: (vertices.i_th (1)).distance (vertices.i_th (2)) = side1
second_side: (vertices.i_th (2)).distance (vertices.i_th (3)) = side2
third_side: (vertices.i_th (3)).distance (vertices.i_th (4)) = side1
fourth_side: (vertices.i_th (4)).distance (vertices.i_th (1)) = side2
end

i_th(i) i ( i- , ).
RECTANGLE POLYGON,
: vertices, rotate, translate, perimeter ( ) .
.
: , RECTANGLE, , SQUARE,
POLYGON.

"" "" :

C - , C , C. (,
C, , , C).
C - , C.
C - A, C . C - A,
C .
"" "", -
.
: (
), ( ).
-, ,
. "
", .

. 14.1.
++ ( Business Object Notation (B.O.N.)).
. -
" ". .
, , ,
, . -
, . :
, .
, . , ,
-, -, ""
.
,
, , , .


RECTANGLE, ,
side1, side2, side1 side2.
POLYGON , :

invariant
( ).
, :
.
: , B A - ,
B A.
, A, B.
(at_least_three) POLYGON ,
, four_sides RECTANGLE,
, .

() POLYGON
make_polygon (vl: LINKED_LIST [POINT]) is
-- vl.
require
vl.count >= 3
do
... vl ...
ensure
-- vertices vl (
)
end
, ,
.
make_polygon,
RECTANGLE, make.
, , POLYGON
make, RECTANGLE,
.
RECTANGLE : , ,
. , vertices ,
RECTANGLE vertices ( ,
).
,
, RECTANGLE. ,
, . :
. , .
, , ,
. :

.
, ,
. ,
creation .
.
creation:

class B inherit
A
creation
make
feature
...
make A, creation.

POLYGON-RECTANGLE
.

. 14.2.
.
, .
. "++" "", "+" "*"

.
RECTANGLE POLYGON.
, QUADRANGLE
, TRIANGLE, PENTAGON . . diagonal ()
QUADRANGLE.
, SQUARE, RECTANGLE, side1 = side2.
, , ,
CIRCLE: equal (focus1 = focus2).

,
. : -
, . .

"" . -
( ),
, .
, :
p: POLYGON; r: RECTANGLE; t: TRIANGLE
:
p := r
p := t
, , ,
, , - .
, ( ) ( ),
. , ( p)
.
( ):
, , . .
,
RECTANGLE TRIANGLE POLYGON. ,
. , ..
r := p. .
, , f (r) f
(t) f :
f (p: POLYGON) is do ... end
, ,
(attachment). ,
(polymorphic) .
?
, , :
p, r t , . p
:= r .

. 14.3.
,
. , .
, . ,
, - ,
.
, , ,
. - ,
. . 14.3 , RECTANGLE , POLYGON.
, , , .
p - , (, expanded POLYGON), p
, p .
.

:
poly_arr: ARRAY [POLYGON]
x ,
poly_arr.put (x, some_index)
( some_index), ARRAY ,
:
class ARRAY [G] creation
...
feature -
put (v: G; i: INTEGER) is
-- v i
...
end
v, x, G,
, G poly_arr, - POLYGON, x .
, x POLYGON, POLYGON.
, 1 4, :
p: POLYGON; r: RECTANGLE; s: SQUARE; t: TRIANGLE
, ,
poly_arr.put
poly_arr.put
poly_arr.put
poly_arr.put

(p,
(r,
(s,
(t,

1)
2)
3)
4)

. 14.4.
,
.
, , ,
. . -
, : , ..
, :
. . 10.1,
:

. 14.5.
, . 10.1 SET_OF_BOOKS . ., ,
, - SET [BOOK].
.
. ,
LIST [RECTANGLE]: , .

LIST [POLYGON]: , , , .
LIST [FIGURE]: FIGURE, .
LIST [ANY]: .
ANY, (
).
, , ,
, .


, , ,
,
.

. .
, :
p: POLYGON
r: RECTANGLE
(. 14.6).
:
p.perimeter: , perimeter ;
p.vertices, p.translate (...), p.rotate (...) ;
r.diagonal, r.side1, r.side2: RECTANGLE QUADRANGLE;
r.vertices, r.translate (...), r.rotate (...): POLYGON
, ;
r.perimeter: , .
RECTANGLE, POLYGON.

. 14.6.

, :
p.side1
p.side2
p.diagonal
:

x , x.f f
.
, . " x " ,
, , : LINKED_LIST [INTEGER].
- LINKED_LIST, .
, ,
, - , . (,
, ) , .
, , .
- - 1-
- .
, - .
Smalltalk,
, , : "
". , , .

.
.
, , p := r p := t,
-. , . , SQUARE
RECTANGLE POLYGON, TRIANGLE. ,
:
:
U T, U T;
U ( )
T.
? ,
, . ,
(, POLYGON ).
.
, LIST [POLYGON] LIST. , B
[Y] A [X], B A, Y - X.
, , .
:

y x (. . x:=y y
x) , y
x.
, , .
p := r , r := p .
. , ,
-- "Animal" (""). , : ,
-, . (, DOG
ANIMAL). ,

ANIMAL, , , MAMMAL ( ), ,
.
, --.

, . ,
- , .
, .
:
: ,
C - , C
create x ..., x C (, ,
C).
C - C.
, C C,
.
, :
p1, p2: POLYGON; r: RECTANGLE
...
create p1 ...; create r ...; p2 := r
POLYGON, (, p1).
, p2 r, RECTANGLE, ,
POLYGON RECTANGLE.
,
( ).
,
, . ,
:
-
T T.
,
" " " ". ,
, .
,
.
, p: POLYGON , p, POLYGON,
create p POLYGON, p := r,
r RECTANGLE , RECTANGLE.
, .
, : -
, ( ),
.
, .
.
, ,
( NONE, ).
.
, . - ,
: x: T, T.
- , .. , .

, x T, T
x.
?
. ,
:
1.

p:= r; r := p

2.

p := r; x := p.diagonal

(1) -, ,
( , - ,
""). (2) diagonal p ,
, , .
, .
, , , .
, ?
, (1) (2) . p:= r
, , , ,
. :
create r.make (...); ...
screen.display_icons
--
screen.wait_for_mouse_click
--
x := screen.mouse_position
--
chosen_icon := screen.icon_where_is (x)
-- ,
--
if chosen_icon = rectangle_icon then
p := r
elseif ...
p := " " ...
end
... p, , p.display, p.rotate, ...
p ,
POLYGON. , , , diagonal,
r (, if). p ,
if, ,
.
p :
some_routine (p: POLYGON) is ...
some_routine (r), .
. , some_routine (t) t
TRIANGLE POLYGON , , ,
p - . , p
POLYGON.
, , ,
( p) .
?
,
. ( , ,
).
p.diagonal p :=r (
(2)), . , .
, p - , ? ,
. , ,
RECTANGLE : p r.

. 14.7.
, , O2
r, p.diagonal? ,
r.diagonal,
. p,
, .
, : p :=r
O2 p, -
. ? - . ,
, , p if
some_condition then p:= r else p := something_else ... p
, .
p - POLYGON.
, , : " ?" :
", !". - :
"__" "_" . ,
, .
-- (" ,
__ (: _) ?")
: " , ?",
, , .

, , ,
. , , , -
, . , ,
, ,
, ,
.
"" "",
, , , , , ,
, .
- , r ?=
p ( ?= , := ),
" , r, r ".
, -, . (
, , ).

,
-.
, (-) :
create x
create x.make (...)
, T, x,
creation, make -. (,
, - make ).
T, , , x.
make

.
, T U. x
U, T.
U.
some_routine (...) is
local
u_temp: U
do
...; create u_temp.make (...); x := u_temp; ...
end
, , , x
. (u_temp )
, .
:
create {U} x
create {U} x.make (...)
, create, ,
U, T. : U
T, make ,
U, , .
, , T , - U.
:
f: FIGURE
...
" "
if chosen_icon = rectangle_icon then
create {RECTANGLE} f
elseif chosen_icon = circle_icon then
create {CIRCLE} f
else
...
end
,
:
create x ... x.
create {U} x ... U.


, ,
.

, , -. ,
perimeter () ,
perimeterPOL perimeterRECT. SQUARE ( 4
). : , , ,
?

create p.make (...); x := p.perimeter
, perimeterPOL.
create r.make (...); x := r.perimeter

perimeterRECT. , p
, ? , :
create r.make (...)
p := r
x := p.perimeter
,
. perimeterRECT.
, , ,
p . ,
--
p: POLYGON
...
if chosen_icon = rectangle_icon then
create {RECTANGLE} p.make (...)
elseif chosen_icon = triangle_icon then
create {TRIANGLE} p.make (...)
elseif
...
end
...
x := p.perimeter
if ... then p := r elseif ... then p := t ..., ;
p , p
POLYGON ,
?
p RECTANGLE, TRIANGLE, ..
, . , ,
: p, perimeter.
, ,
-,
. .
,
. , :
p := q some_routine (q), p ,
q, p.polygon_feature,
polygon_feature , q, .
, ,
, , , , - .

POLYGON p.perimeter, p,
perimeter . , ,
, -. RECTANGLE
,
, , , ?
. ,
. , . ,
:
, , ,
.
. ,
: , . , .

, - ,
, .

, .
, ( ) -.
, ,
.


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

, FIGURE.

. 14.8. FIGURE
FIGURE.

, :
transform (f: FIGURE) is
-- f.
do
f.rotate (...)
f.translate (...)
end
. :
transform (r)
-- r: RECTANGLE
transform (c)
-- c: CIRCLE
transform (figarray.item (i)) -- : ARRAY [POLYGON]
, rotate translate f
( RECTANGLE CIRCLE),
f, .
,
, , .
rotate translate .
- ! FIGURE - , .
, rotate translate, " ",
.
, , transform ,
, , rotate translate
FIGURE. f.rotate f.translate .
, , FIGURE rotate, .
, rotate (center, angle) "
" .

, rotate translate FIGURE,
.
"".
deferred. FIGURE :
rotate (center: POINT; angle: REAL) is
-- angle center.
deferred
end
translate. , ,
, - .
f.rotate transform .
. ,
, - (, ),
.

FIGURE .
,
class POLYGON inherit
CLOSED_FIGURE
feature
rotate (center: POINT; angle: REAL) is
-- angle center.
do
... ...
end
...

end
, POLYGON FIGURE , CLOSED_FIGURE,
rotate .
(effecting).
( - , .)
redefine , ,
.
, , ,
rotate.
, , ,
redefine, . .
:
- .
,
:
POLYGON RECTANGLE perimeter ,
RECTANGLE. . ,
SQUARE.
FIGURE POLYGON rotate,
POLYGON. . POLYGON , ,
.
,
. -
- ( ).
,
redefine.
:

14.1.

: -
. .

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

deferred class (
class ).
FIGURE :
deferred class FIGURE feature
rotate (...) is
... ...
... ...
end

, , .
, ,
, ,
. OPEN_FIGURE, ,
display, rotate , FIGURE,
, .

deferred class OPEN_FIGURE inherit
FIGURE
...
.
,
.
, POLYGON ELLIPSE, display, rotate.
, . ,
FIGURE, , . LIST (
, , ), LIST [INTEGER]
. : C [X] , C ,
, C , X.

, . 14.8.
:
FIGURE*
display*
perimeter* -- OPEN_FIGURE . 14.8
"" :
perimeter+ -- POLYGON . 14.8
, , +. ,
, class C deferred ,
.
, . ,
perimeter , , perimeter*
CLOSED_FIGURE. POLYGON
perimeter+ .
, :
perimeter++ -- RECTANGLE SQUARE .14.8
?
: " , rotate
FIGURE?" - "
?" : FIGURE -
.

.
, - x, create x, U create {U} x. ,
.
create f , f
: FIGURE, OPEN_FIGURE, CLOSED_FIGURE.

.
, , f , create{RECTANGLE} f, FIGURE - RECTANGLE.
, FIGURE,
, , RECTANGLE, CIRCLE .
, ,
. ,
. FIGURE, ,
, , :
f: FIGURE
...
f := " , CIRCLE POLYGON"
...
f.rotate (some_point, some_angle)
f.display
...
- , ,
, , , , ,
(, , ). , ,
, . ,
,
- , , ,
.

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

. 14.9.
:
indexing
description: " "
deferred class
LIST [G]
feature -- Access
count: INTEGER is
--
deferred
end
index: INTEGER is

--
deferred
end
item: G is
--
deferred
end
feature -
after: BOOLEAN is
-- ?
deferred
end
before: BOOLEAN is
-- ?
deferred
end
feature -
forth is
-- .
require
not after
deferred
ensure
index = old index + 1
end
... ...
invariant
non_negative_count: count >= 0
offleft_by_at_most_one: index >= 0
offright_by_at_most_one: index <= count + 1
after_definition: after = (index = count + 1)
before_definition: before = (index = 0)
end
. ,
.

. 14.10.
: ensure Result = (index
= count + 1) after ensure Result = (index = 0) before.
, .
, ,
.
forth , : .
"" ,
forth not after, , ,
index .
- . STACK [G],
, . ,
FIXED_STACK LINKED_STACK, .
STACK put:
put (x: G) is
-- x .
require
not full
deferred

ensure
not_empty: not empty
pushed_is_top: item = x
one_more: count = old count + 1
end
empty full ( STACK)
.
. (
), .
: .
, put STACK.
,
, .
-,
.


- -
. , :
.
.

-
(Uniform Access).
(. 3), ( ,
),
. ,
, - .
, , balance
, , ,
, . ( ,
, ).
,
.
. ACCOUNT1:
class ACCOUNT1 feature
balance: INTEGER is
--
do
Result := list_of_deposits.total - list_of_withdrawals.total
end
...
End
,
balance :
class ACCOUNT2 inherit
ACCOUNT1
redefine balance end
feature
balance: INTEGER
--
...
end
-, ACCOUNT2 , withdraw

deposit, , balance,
: balance = list_of_deposits.total - list_of_withdrawals.total.
.
. , LIST
count: INTEGER is
--
deferred
end
:
count: INTEGER
, ,
, ,
, ,
- . " "
" ".
, ,
.
a.service , ,
, - .
, , a.balance, a
.

, . .
- , - . , a C,
a := some_expression
C a , ,
.
( , ) ,
. ,
,
, .

, , .
, , ,
.
, BUTTON, WINDOW, display, ,
, :
class BUTTON inherit
WINDOW
redefine display end
feature --
display is
-- .
do
" "; -- .
draw_border
end
... ...
end
draw_border - . " ",
display, precursor () draw_border.

, .
Precursor
, .
, , ().
" "
Precursor
WINDOW,
- WINDOW. Precursor - , Result
Current, .
Precursor -
. :
some_query (n: INTEGER): INTEGER is
-- , ,
-- ,
do
Result := (Precursor (n)).max (0)
end
, ,
, .
, , Precursor {WINDOW}.
, Precursor -
, . ( ,
.) ,
.
, , ,
, , ,
, , .
.


. , ,
, ( ).

.

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

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

.
, .
. ,
, : " ".
.
. B A, () A
B, . B
. , B , A: ,
.
,
, .
- , ? - ,
, , .
-,
. ( .)
, , .
, ,
, ,
.
, , ,
.
, .
. , ,
-. ,
, ,
.
.
, !
, . ,
,
- - .
, - .
,
, . , , -

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

. ,
.

. 14.12.
,
. , , .
[M 1994a].
: ,
,
-.
, , (, .
14.12), , . ,
, ,
, .

, , ,
, .
.
- , ( ) . INTEGER
, POLYGON -
vertices, perimeter .

"", , "
", " ". ,
.
?
,
: , RECTANGLE
POLYGON. ( "" ,
, RECTANGLE POLYGON).
, , , B A, ,
, A B. ( B
, B , A.)
"", ,
, FIGURE. rotate display
, . , ,
search, insert, delete, ,
, .
"" ("is a"). - ,
, , -
" - ", SAN_FRANCISCO CITY. , , : CITY , , . ,
, "" "x A" (, "
(CITY)), .. , " B A"
(, " _"), .. ,
- . "
" " " [Gore 1996]. (
), , ,
"", ,
.

, ,
. -,
, .

type FIGURE =
record
" "
case figtype: (polygon, rectangle, triangle, circle,...) of
polygon: (vertices: LIST_OF_POINTS; count: INTEGER);
rectangle: (side1, side2: REAL;...);
...
end
. , ,
( ..) :
case f.figure_type of
polygon: ...
circle: ...
...
end
search . ,
: ,
.
.
Ne sutor ultra crepidam, ( ) - :
.
: .

. ,
. , ,

, , ,
, .
- . ,
.
. :
. Cultivez votre
jardin, - .
, , ,
.

:
, .. , ,
, .

present := has (x, t)
, t . t
, , - . . (
, ),
present := t.has (x)
has.
, :
, .
, , , ,
, : ,
, .
-
, .
, - .
, . ,
"", - : "" , "",
"" - "". ,
: B A, , B
A.
, , B A
. ,
. ,
"", "".
: ,
A, , B.
> , () ,
, , B
, A .
, .
-: , ,
.
- - "",
"". , ,
"" , .
: ,
: , .


,
.


. . put,
.
indexing
description:
" ( Last-in, First-Out), %
% "
deferred class
STACK [G]
feature --
count: INTEGER is
-- .
deferred
end
item: G is
-- .
require
not_empty: not empty
deferred
end
feature -
empty: BOOLEAN is
-- ?
do
Result := (count = 0)
end
full: BOOLEAN is
-- ?
deferred
end
feature -
put (x: G) is
-- x .
require
not full
deferred
ensure
not_empty: not empty
pushed_is_top: item = x
one_more: count = old count + 1
end
remove is
-- .
require
not empty
deferred
ensure
not_full: not full
one_less: count = old count - 1
end
change_top (x: T) is
-- x
require
not_empty: not empty
do
remove; put (x)
ensure
not_empty: not empty
new_top: item = x
same_number_of_items: count = old count
end
wipe_out is
-- .
deferred
ensure
no_more_elements: empty
end
invariant

non_negative_count: count >= 0


empty_count: empty = (count = 0)
end
, , : ,
change_top remove put. (
, , , ,
STACK .)
STACK , 6,
. , , ,
PRECONDITIONS .
.
change_top, count wipe_out ,
(. 6.8). new
, -
. .
- full, ,
, . ,
, . ,
,
. , (, )
full , .
, , ,
(), . ,
, (), put ,
, , .
, , .

x: G, s: STACK [G],
1.

item (put (s, x)) = x

2.

remove (put (s, x)) = s

3.

empty (new)

4.

not empty (put (s, x))

, (2), . ( , (3) empty).


- IFL.
:
STACK. ,
STACK, , , FIXED_STACK,
,
.
,
. , ,
.

. 14.13. ""
TABLE ,
, .
SEQUENTIAL_TABLE, ,
. , .
.
SEQUENTIAL_TABLE. ,
TABLE
ARRAY_TABLE. ,
, , :
has (x: G): BOOLEAN is
-- x ?
do
from start until after or else equal (item, x) loop
forth
end
Result := not after
end
, . start (
), forth ( ), item ( ), after
( ?) SEQUENTIAL_TABLE
-.
. ARRAY_TABLE
i, start i := 1, item t @ i ..
forth,
,
. ( LIST,
).
:
, TABLE, .
, ARRAY_TABLE, .
, SEQUENTIAL_TABLE, (,
, ) .
SEQUENTIAL_TABLE, , ,
(behavior class).
-.
,

SEQUENTIAL_TABLE , -, ,
4 " ".
,
. has.
, ,
. , ,
.
,
- .
. ,
[M 1994a], Lex Parse, . , Parse
, (
..), .
, post_action,
, .
.
. , - , ,
, - .
,
, , . ,
. ,
.
. ,
,
. ,
, . ,
,
(, , display FIGURE).
, " , ":
,
.
. IMS IBM
. ( X Unix) " ",
, .
(callback scheme).
, -, , ,
. , , ,
, , ,
.

- :
( ),
,
.

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

, . ,

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

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

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

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

, .
. ( ,
) .

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

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

, .

,
. ,
.
, .
(Pascal, Ada, C, ...)
1.

f (x, a, b, c...)

-
2.

x.f (a, b, c...)

,
. , , .
(1), f ,
, ,
. : f (2)
, x .
( ) ,
.
, .
. - .
x.f, ,
f. , , , . , . (
).
, ,
Smalltalk, , " ".

. , . ,
,
.
,
. ,
, .
.
Smalltalk.
, ( , )
. - , - , ,
.
, .
.
- x ,
x, , ,
.
: .
, , , ,
.
2 20, 100 10000,
. ,
.
1985. , .. ,
,
( ),
,
Simula 67, ( ,
),

, .

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

,
. ISE (
).
, , . . p1 is do end,
(, C)
30%.
, , , - .
, ,
, . p1
, ,
p2 (a, b, c: INTEGER) is
local
x, y
do
x := a; y := b + c + 1; x := x * y; p2
if x > y then x := x + 1 else x := x - 1 end
end
15%. , (,
) .

,
. , . x.f (a, b, c...)
:
1. f ( );
2. x , , ,
.
, , x.f (a, b, c...)
, , C, Pascal, Ada Fortran f (x, a, b,
c...). .
ISE, , , (1),
(2) ( (2) , , ,
).
(1) ,
(. ). , (1)
:
3. .
.
,
set_a (x: SOME_TYPE) is
-- x a.
do
a := x
end

s.set_a (some_value) , Pascal


s.a := some_value ( ,
). ,
.
, . Ada
( ) inline, C ++ .
. ,
, , .

.
, (1), -
, ,
(3). - ,
, ,
.
, ,
. ,
, , , (1)
(2). , -, , -,
,
. ,
(
, , , ).
, ,
, .
, , ,
.
:
.
. - , - 30%
60% . ,
. ISE 60%.

, .
( ), , -
, , (if ... then
... case ... of ...), ,
. , -, ,
C.
:
:

,
.
x.r. x A, B,
B r , r A -
, !
, r. ,
perimeter RECTANGLE, , r
B. , , BUTTON (),
WINDOW () ( ).
display,
(, ). , w WINDOW,
, , BUTTON, w.display
"" ! display WINDOW
.
, , ,
, ,
. ,
, - , , - -

. , ,
.
.
11 :
{prer (xr ) and INV} Bodyr {postr (xr ) and INV}.
, ,
, A:
[A-CORRECT]
{INVA } rA {INVA }
, r A .
, r B.
, :
[B-CORRECT]
{INVB } rB {INVB }
, , INVB INVA ,
, , .

. 14.14.
, , RECTANGLE POLYGON. ,
11, ACCOUNT1 withdrawals_list
deposits_list; ACCOUNT2 , , ,
balance .
:
consistent_balance: deposits_listltotal - withdrawals_listltotal = current_balance
- , , ACCOUNT1; ,
deposit, deposits_list,
balance. . ,
display WINDOW BUTTON.
, B, A,
. - , rA , ,
(, , depositACCOUNT1 ACCOUNT2 displayWINDOW
BUTTON), (, ACCOUNT2
balance BUTTON, ).
- , , .. ,
- ,
. ,
.

: , .
( (1) (2)), ,
. , .
++
++ , ,
.
, ++, . .
( ++ - ) ,
(virtual).
, :
1. .
2. .
- , : (1) , (2) .
(1) ,
( ), - ( , ). ,
. ++ C
, ,
. , -
, ,
. .
, , ,
: .
.
(1): ++ , , ,
, - , ,
. - , .
- (1).
: , .. .
-, ,
, - . , :
,
. ++, ,
, virtual. ,
. , ,
.
(1), , ,
-.
(2) - - .
. ,
, .
.
- , (..
, , ),
, - .
, -
.
, ( C),
. ,
(virtual),
static ( - ) ,
, ( C ++) ,
.
, , ,
. , , ++, , -
.
( , , , "
, "), ,
.

" - ",
++, (2), ,
.
, ++ , ,
Borland Delphi, , , , ++. ,
++ Java .
.
++ ? ,
,
- . ( ,
++ , ,
).
, ,
. , (1) (2)
++, , , : "
", !
, ++ " " .
(Walter Bright), ++, [Bright 1995]:
, ++ [] , .
, , . -,
[. . ],
[ ], .. - [...].
,
, , , .
: -. ( "
" -
, , , , ,
.)
: - ,
, .
,
, , ,
.


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

.
,
. ,
, .
, , .


() 67,
17 " - ".
- ( ( ) ).
"" , , [Brachman
1983].
[Cardelli 1984].
Business
Object Notation, Nerson' Walden' ( 9 " -
").
Precursor ( super Smalltalk, ,
)
Roger Browne, James McKim, Kim Walden Steve Tynor.

14.1
POLYGON RECTANGLE, .
.
14.2
POLYGON , , , ; ,
perimeter . ,
.
14.3
TWO_COORD, ,
POINT (), COMPLEX (_) VECTOR ().
.
14.4
: , -
, , "" (
). "" , - (
(Ada) -2 (Modula-2)) , .
. , .
-.
14.5
.
: . ?
, , ? (:
.)
14.6
. , ,
. ""
: ,
,
. ,
"", (
). .

14.7 ( )
,
, : -,
() , .
14.8
?
14.9
( 5- " ".) , ,
,
" ".
, , COMPLEX () CARTESIAN_COMPLEX
(___) POLAR_COMPLEX
(___).

-
15. :
. ,
-. , (multiple)
( (single) ), . , , , -
. , , :
, ; (repeated)
, - .


, , .
, .
, ,
, -
. , ,
, ,
.
,
. , (
) , , .
, ;
, .
TEACHER STUDENT,
, , TEACHING_ASSISTANT,
TEACHER STUDENT.

. 15.1.
, - ? . . ,
STUDENT TEACHER - , UNIVERSITY_PERSON.
, , , (repeated)
- , ,
:

. 15.2.
- .
. ,
, ,
, .
. , ,
.
- . , .
, .
- .
?
,
. , .
AIRPLANE .
(passenger_count), (altitude), (position), (speed); -
(take_off), (land), (set_speed).
ASSET, .
, (purchase_price), (resale_value),
(depreciate), (resell), (pay_installment).
, , : !
, , , . ,
( ) , ( ) ,
.
" " :

. 15.3.
class COMPANY_PLANE inherit
PLANE
ASSET

feature
... , ,
( ) ...
end
inherit. ( ,
, .) .
, COMPANY_PLANE.
- .
, . - .
(AMPHIBIOUS_VEHICLE). :
, - (HYDROPLANE). ( TEACHING_ASSISTANT,
, -
VEHICLE.)
; - - (EATING_CAR). :
(SLEEPING_CAR).
- (SOFA_BED), , .
" " (MOBILE_HOME) - (VEHICLE) (HOUSE) ; .
- ,
. ,
. ISE
.

-
Kernel.
Kernel, , ,
infix "+", infix "-", infix "*", prefix "-", zero (
"+") one ( "*").
Kernel: INTEGER, REAL DOUBLE. , , ,
, MATRIX, .
NUMERIC, Kernel:
deferred class NUMERIC feature
... infix "+", infix "-", infix "*", prefix "-", zero, one...
end
NUMERIC .
( , ,
, ).
.
Kernel, STRING, .
COMPARABLE:
deferred class COMPARABLE feature
... infix "<", infix "<=", infix ">", infix ">="...
end
- .
COMPARABLE NUMERIC. STRING ,
. , NUMERIC COMPARABLE. ,
, , , , ,
. COMPARABLE NUMERIC ,
.
, , . (
.) - REAL INTEGER.
, . :
expanded class REAL inherit
NUMERIC

COMPARABLE
feature
...
end

. 15.4.
-
:

. 15.5.
WINDOW :
, ( , , ,
, );
, (, , , , ).
, .

. WINDOW :
, TREE;
, RECTANGLE.
:
class WINDOW inherit
TREE [WINDOW]
RECTANGLE
feature
... ...
end
, TREE (generic) ,
, - WINDOW. ,
, - .
, , , .
, TEXT_WINDOW STRING,
text: STRING
, , , .
WINDOW STRING. ( ,
TREE, RECTANGLE STRING, " "
.)
-
TREE - .
, . :
" , , , (
) - ". : "
; ". ,
, .
, . ,
. TREE [G], , .
G . , , ,
TREE [INTEGER]:

. 15.6.
, LIST .
CELL .

. 15.7.

: ( ) , -
, ,
.
:
- .
, , :
deferred class TREE [G] inherit
LIST [G]
CELL [G]
feature
...
end
LIST (count), , . .
CELL , , :
, , .
,
. ,
. .
, feature ,
, , , ,
. TREE
, .
, :
.
.

, -
.
,
: FIGURE, OPEN_FIGURE, POLYGON, RECTANGLE, ELLIPSE ..
.

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

. 15.9.
, , , . .
, , , ,
, .
(COMPOSITE_FIGURE). , ,
FIGURE, " " . - ,
, .
(. 15.10).
COMPOSITE_FIGURE ,
- LINKED_LIST. :
class COMPOSITE_FIGURE inherit
FIGURE
LINKED_LIST [FIGURE]
feature
...
end

. 15.10. -
feature .
. , display :
display is
-- , .
do
from
start
until
after
loop
item.display
forth
end
end

, , ,
. start , (
after True), after , , item ,
, forth .
, , .
: , , (LINKED_LIST [FIGURE]),
( item.display display ,
), ( item
). : ,
!
. COMPOSITE_FIGURE - (rotate)
(translate). ,
display. - :
; - .
( .) , ,
"", COMPOSITE_FIGURE.
DISPLAY_ ITERATOR, . (.
15.4).

, , - .
(. 15.8), .

, .
.
,
, , . , .

. 15.11.
, .
( STACK ARRAY, . ).
ARRAYED_STACK (, ) - STACK ARRAY.
: - ( ) (
). :
indexing
description: ", "
class ARRAYED_STACK [G] inherit
STACK [G]
ARRAY [G]
... ...
feature
... STACK
ARRAY (. )...
end

ARRAYED_STACK , STACK, :
full, put, count ..., .
: full, count put. , , , :
full: BOOLEAN is
-- ( ) ?
do
Result := (count = capacity)
end
capacity ARRAY , .
count :
count: INTEGER
. ,
put (x: G) is
-- x .
require
not full
do
count := count + 1
array_put (x, count)
end
array_put ARRAY. -
.
capacity array_put ARRAY count put.
.
ARRAYED_STACK , " ". , , - , .
, (deferred) STACK, ARRAYED_STACK
. change_top, STACK
remove put, :
array_put (x, count)
:
class ARRAYED_STACK [G] inherit
STACK [G]
redefine change_top end
... , ...

invariant
non_negative_count: count >= 0
bounded: count <= capacity
. STACK
. .
. - capacity. - .
ARRAYED_STACK STACK2, ,
. ,
, " "
.

,
, , .
(
). "", ,
. Kernel STORABLE,
. , , STORABLE, , ,
, .
COMPARABLE NUMERIC.
, , , , - ABLE,
.
,
- , .
.

. "",
:
;
;
, ;
, .
, .
( , " " Unix Windows),
. .
, - .
( - , .)
, , .
TEST, :
, , , ..
,
X X_TEST, X TEST.
,
F , , ,
F, .

, , , .
, , .
, .
ISE, 19 " - ",
, "" .
" " (pick and throw), drag-and-drop.
; "",
. ,
, . , Class Tool,
, " ", ,
.

. 15.12. Pick and throw ( )


.
ARRAY, . ,
, Feature Tool, INTEGER.
"" Class Tool, ARRAY.
"" , . Class Tool
INTEGER.
, "" , "" ,
. "" ,
( ARRAY, INTEGER).
, , .
BUTTONHOLE.
, BUTTONHOLE BUTTON HOLE.
, ,
.

.
[M 1994a].
, ? ,
"" , ,
"" . ,
, .


(name clash). (feature renaming) - ,
.

. ,
, . inherit class C inherit A ... f C
f. : x C
x.f - A. "", ,
- : C A.
,
.

? ,
:
. . :
class SANTA_BARBARA inherit
LONDON
NEW_YORK
feature
...
end-- class SANTA_BARBARA
, LONDON NEW_YORK , , foo ()?
. , SANTA_
BARBARA , .
TREE, CELL LIST, item.
, , put. ,
, - .
? LONDON NEW_YORK ;
; , , , LONDON
, . , ,
- .
. .
.
, , ,
rename.
. :
class SANTA_BARBARA inherit
LONDON
rename foo as fog end
NEW_YORK
feature
...
end
SANTA_BARBARA, LONDON foo
fog, NEW_YORK - foo. LONDON, ,
foo.
( , LONDON NEW_YORK
fog). NEW_YORK:
class SANTA_BARBARA inherit
LONDON
rename foo as fog end
NEW_YORK
rename foo as zoo end
feature
...
end
rename redefine,
. , :
class TREE [G] inherit
CELL [G]
rename item as node_item, put as put_right end
CELL LIST. CELL item
node_item, put put_right.

, . SANTA_BARBARA (
foo ):

. 15.13.
( .) :
l: LONDON; n: NEW_YORK; s: SANTA_BARBARA
l.foo s.fog . l := s
, . , n.foo, s.zoo,
n := s .
, :
l.zoo, l.fog, n.zoo, n.fog, LONDON, NEW_YORK fog
zoo;
s.foo, SANTA_BARBARA foo.
. , ,
, " ". . . fog, zoo, , - . -
, , ,
. , , -
( ), ( ,
, , , ).

, . (,
,
.) .
, .
, .
,
, (
). - .
- , ,
.
:
class SANTA_BARBARA inherit
LONDON
rename
foo as fog
redefine
fog
end
...

, , l: LONDON; s: SANTA_BARBARA, l := s, l.foo,


s.fog fog,
feature .
: redefine . ,
. rename
(, redefine export, undefine, select). rename
, .

.
, ,
.
, , .
,
. ,
.
WINDOW, TREE.
, , , , ,
WINDOW .
:
class WINDOW inherit
TREE [WINDOW]
rename
child as subwindow, is_leaf as is_terminal, root as screen,
arity as child_count, ...
end
RECTANGLE
feature
... window ...
end
, TREE, CELL, right right_sibling ..
""
.

- , - - .
, - .
.
. ,
: count, put, item, remove, ... - ,
, . ,
, ,
WINDOW. ,
, .

.
ARRAYED_STACK, STACK ARRAY. ARRAY
:
make (minb, maxb: INTEGER) is
-- minb maxb
-- ( minb > maxb)
do ... end
, .
ARRAY:
class ARRAYED_STACK [G] inherit
STACK [G]

redefine change_top end


ARRAY [G]
rename
count as capacity, put as array_put, make as array_make
end
creation
make
feature -- Initialization
make (n: INTEGER) is
-- , n .
require
non_negative_size: n >= 0
do
array_make (1, n)
ensure
capacity_set: capacity = n
empty: count = 0
end
... ...
invariant
count >= 0; count <= capacity
end
, - make , , , ,
count put. .


- , ,
. .
: (undefinition), (join),
(select), (descendant hiding).
, ,
, - (flat form).

- , ;
. ,
, .
,
. ,
, , .
. .
, , (flat class_name)
.
C - , , - ,
, - , C, .
, .
:
inherit, ;
C;
,
-, inherit : , ,
, (select), ;
: from ANCESTOR,
, () ( -
);
(
, );
(and)
.
, ,
( ).
, , feature - Access, .

. .
LINKED_TREE Base.
Class Tool ISE. Class Tool LINKED_TREE
Flat.

. 15.14.

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

. ,
, , .
.
, ( short
).
(flat-short form). ,
, ,
, , do. ,
- , .
,
. ( ,
). Base [M 1994a].

: , , ? , .
, ""
(repeated inheritance) ,
. , .
.
,
.

, , , D B C,
A. .

. 15.15.
B C A, ( 1), . A, B C -
( 2), - , :
class D inherit
A
A
...
feature
...
end


. DRIVER :
age: INTEGER
address: STRING
violation_count: INTEGER

--

:
pass_birthday is do age := age + 1 end
pay_fee is
-- .
do ... end
, US_DRIVER , , FRENCH_DRIVER, -
.
, .
, .
FRENCH_US_DRIVER US_DRIVER FRENCH_DRIVER. .

. 15.16.

:
(FRENCH_US_DRIVER), (DRIVER)?
age. DRIVER, , ,
, . ,
- age DRIVER, ,
( ).
pass_birthday.
:
, , .
age ( pass_birthday), FRENCH_US_DRIVER ,
"", . ,
. ,
, , .
,
.
(sharing).
? . address, pay_fee,
violation_count. ,
- . ,
. , .
(replication).
, , , ,
.
.
,
. ? :
.
,
. .

, ,

. , , ,
.
, , , :
.
, - , -
.
, ,
: ,
.
.
FRENCH_US_DRIVER:
class FRENCH_US_DRIVER inherit
FRENCH_DRIVER
rename
address as french_address,
violation_count as french_violation_count,
pay_fee as pay_french_fee
end
US_DRIVER
rename
address as us_address,
violation_count as us_violation_count,
pay_fee as pay_us_fee
end
feature
...
end
- ,
- US_DRIVER FRENCH_DRIVER. , , .
age pass_birthday , , ,
.
, , address, FRENCH_US_ DRIVER
. , ,
. 15.18.

. 15.17.

. 15.18.
( FRENCH_DRIVER US_DRIVER DRIVER, . .)

, age FRENCH_US_DRIVER. ,
. ,
"" ,
. (,
.)
, , ,
, - (shared)
(shared) . -
. ,
, :
;
, , (
).
, ,
.
++ . , ,
, - . ,
. Java , .

, "" ,
, . . ,
.
" ", ,
.

. 15.19.
( ): D
B, A, B A. ,
:
class D ... inherit

B
A
...
. . ,
( ) ,
, . B ,
.
: , B A,
D. , , ,
D .
, , A - ,
, -, B D. D B.
D A, .
, .
"" ANY
GENERAL, .

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

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

. 15.20.
class A feature
this_one_OK: INTEGER
end
class B inherit A feature
portends_trouble: REAL
end
class C inherit A feature
portends_trouble: CHARACTER
end
class D inherit
-- !
B
C
end
D this_one_OK , B, - C. ,
. , - A.
portend_trouble (" ") . ,
D , . ( ,
.)
, D :
class D inherit
-- .
B
rename portends_trouble as does_not_portend_trouble_any_more end
C
end

. , , , B C (.
), ?
D.
: (undefinition) (selection). ,
,
.
:

. 15.21. -
B f. D :
B A, C. ( , C f,
.) ,
, , .
? , D
. ?
.
:
, .
. . .
1. , - , ,
. , :
.
2. , D redefine.
, , .
3. , , . D
, .
(3) : , .
,
, .
, (3). ,
" " . - (1),
.
f ,
, C', - C, -
f . D C, C'. .
: undefine.
:
class D inherit
B
C
undefine f end
feature
...
end
undefine rename (
), redefine (, - ,
).
, ,
(, , ).

:
( - ) . :

. 15.22.
, D f g . ,
( , ). ,
, f. ,
:
class D inherit
B
C
rename
g as f
undefine
f
end
feature
...
end
B C, D , .
: , - ;
, D.
, "" ,
. redefine,
, (, , rename).
( (2)), .
:
, .
,
, .

. 15.23.
B f bf .
, C f, .
, , B f ,
D. , (

).
, . D
, , ,
.
. ,
. a1 A ( )
D ( ). a1.f?
: f - D.
: D ,
f bf, f A.
, , , -
.
.
- select. ,
f A C:
class D inherit
B
C
select f end
feature
...
end
B:
class D inherit
B
select bf end
C
feature
...
end
select rename, undefine redefine,
( ).
:

,
, select.
select . ( )
.

select. , ,
, , , " " ()
. , , " " (, ARRAYED_STACK
- STACK ARRAY), - . ( Base
(distant) CONTAINER.)
(STACK) , , , , ()
.
,
. inherit ( ) :
SOME_PARENT
select all end
: , - ,
select, - SOME_PARENT. , -
.


( , .)
, Precursor,
.
( "") ,
, .
BUTTON - WINDOW, display:
display is
-- .
do
window_display
special_button_actions
end
window_display , special_button_actions ,
, , , . window_display
WINDOW- display.
, window_display, Precursor. display
, :
Precursor {WINDOW}. , ,
Button Window:
indexing
WARNING: " - !"
class BUTTON inherit
WINDOW
redefine display end
WINDOW
rename display as window_display end
feature
...
end
display, , BUTTON,
. , ;
, window_display.
, select. , ,
, :
indexing
note: " (!) ,%
% "
class BUTTON inherit
WINDOW
redefine
display
select
display
end
WINDOW
rename
display as window_display
export
{NONE} window_display
end
feature
...
end
, .
.
select all.

export (. 16) . , WINDOW


display, BUTTON window_display (
).
, .
, " " , export
{NONE} all.

, .
( ).

? , Precursor.
, ,
.

.
, , C++
[Stroustrup 1991].
WINDOW display : WINDOW_WITH_BORDER
WINDOW_WITH_MENU. , ,
. display, ,
( ) ( ).
. WINDOW_WITH_BORDER_AND_MENU.

. 15.24.
display ; , ,
. WINDOW :
class WINDOW feature
display is
-- ( )
do
...
end
... ...
end
WINDOW_WITH_BORDER display .
, Precursor:
class WINDOW_WITH_BORDER inherit

WINDOW
redefine display end
feature -- Output
display is
-- .
do
Precursor
draw_border
end
feature {NONE} -- Implementation
draw_border is do ... end
...
end
draw_border, .
WINDOW_WITH_BORDER ( NONE), draw_border .
WINDOW_WITH_MENU :
class WINDOW_WITH_MENU inherit
WINDOW
redefine display end
feature -- Output
display is
-- .
do
Precursor
draw_menu
end
feature {NONE} -- Implementation
draw_menu is do ... end
...
end
WINDOW_WITH_BORDER_AND_MENU ,
WINDOW. :
indexing
WARNING: " - !"
class WINDOW_WITH_BORDER_AND_MENU inherit
WINDOW_WITH_BORDER
redefine display end
WINDOW_WITH_MENU
redefine display end
feature
display is
-- , .
do
Precursor {WINDOW_WITH_BORDER}
Precursor {WINDOW_WITH_MENU}
end
...
end
: Precursor .
display, .
, , :
display WINDOW, "" .
, WINDOW:
indexing
note: " "
class WINDOW_WITH_BORDER_AND_MENU inherit
WINDOW_WITH_BORDER
redefine
display
export {NONE}
draw_border
end

WINDOW_WITH_MENU
redefine
display
export {NONE}
draw_menu
end
WINDOW
redefine display end
feature
display is
-- , .
do
Precursor {WINDOW}
draw_border
draw_menu
end
...
end
, draw_border draw_menu ,
, WINDOW_WITH_BORDER_AND_MENU .
,
display, select .
Precursor .

Precursor, . , , select
(. 15.10).
, .
: WINDOW id (, ),
. "", id
, . ,
WINDOW_WITH_BORDER_AND_MENU id - "".
id ( ):
indexing
note: " id."
class WINDOW_WITH_BORDER_AND_MENU inherit
WINDOW_WITH_BORDER
rename
id as border_id
redefine
display
export {NONE}
draw_border
end
WINDOW_WITH_MENU
rename
id as menu_id
redefine
display
export {NONE}
draw_menu
end
WINDOW
rename
id as window_id
redefine
display
select
window_id
end
feature
.... , ...
end
(select) id.


. ,
. (
, ):
class A [G] feature
f: G;...
end
class B inherit
A [INTEGER]
A [REAL]
end
B f . -
, - - real integer?
, f G.
. :

, ,
,
.
.

( , .)
, ,
.
, :
, :
:
, , ,
, , .
:
1. ,
.
2. , , ,
.
3. .
(1) .
(2) " " :
, ,
(undefine).
(2) (3) , , -
(join). n (n >= 2), , (2) (3) ,
n .
, , :
n , ;
.
;
. .
, ,
.
, , Precursor.
Precursor, - , , .
, Precursor {PARENT} (...), PARENT -
. .


, .

, , - .
,
, , :
;
.
, C, f A B, ,
, . , C
:
x: C
... x.f ...
f, , , : x.f | A, x.f | B,
.
, , , :
, ,
. f C, , C
A B.
, x.f . .
, , , C .
.
Lisp .
,
.
.
"" .
-
, , (in-class
name overloading).
, , Ada 83 Ada 95, -
. , :
infix "+" (a, b: VECTOR) is...
infix "+" (a, b: MATRIX) is...
Java C++ .
. - .
, , x + y, x y,
.
( ) .
, VECTOR MATRIX NUMERIC
infix "+" (a: T) is...
, , + x + y,
. -
,
, , NUMERIC. ,
, , ,
.
?

. , Ada 83, , . -
- .
, ,
- . x.f (a).
x := y a := b, ,
y.f (b), b y a x. ! f
: - a, - b.
: ? , y
. , , .
, , .
, "" ,
, .
, ? .
,
. .
, ,
STRING. , , ,
: s1.add_string (s2) s1.add_character ('A'),
s := s1++ s2 s := s1 + 'A'. .
? CHARACTER STRING .
1. ( )
. , ,
, .
, , ,
, .
, . -
: make_cartesian make_polar.
, - REAL, , -.
. , ,
.
("") Java C++ . ,
, . ,
, .
() - ,
. ( , Java, C++ Ada 95,
, , , .)
, : ,
.


, ,
. .

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

select.
,
.
- , , ,
.

,
. (Michael Schweitzer), (John Potter).
[M 1988c].

15.1
WINDOW TREE [WINDOW]. . ,
.
15.2 ?
, text STRING.
WINDOW STRING?
15.3
WINDOW, ,
?
15.4
COMPOSITE_FIGURE
. . (: [M 1994a]
, .)
15.5
STACK LINKED_LIST, LINKED_STACK,
.
15.6
, LIST . (:
, .)
CHAIN, LIST,
CIRCULAR. LIST , , . ,
.
15.7
, - , .
TREE LINKED_LIST LINKABLE

class TREE [G] inherit


LIST [TREE [G]]
feature ...end
. ,
.
15.8 "" (walking)
, MENU , ,
, .. ,
MENU_ENTRY , parent_menu operation (,
) , execute ( operation).
, (walking menu),
(submenu). Open Windows,
Sun:

. 15.25.
SUBMENU. (: ,
.)
?
15.9 precursor ()
, Precursor?
15.10
WINDOW_WITH_BORDER_AND_MENU Precursor.
. ,
select .

-
16. :
- - .
, ,
. . ,
. , -.
: . : .
. ,
. .
: 17,
- 6 " - ".
: , ,
, . -
, .


, . ,
""
.
: . ,

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

:

.
. and then. (
, True .)
, , .
, (
: a and then a , a).

(. 15).

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

. 16.1. ,
. 16.1 C A. , C, ,
:
a1: A
...
a1.r
, r, , r
, .
, . , C
, , , , a1.r
:
if a1.

then
a1.r
check a1. end
--
... , a1.. ...

end
( , : , if
, a r. if-,
else.)
, C a1.
r.
:
,
.
, ?

. 16.2. , ,

A' A r. , ,

, -

, . a1.r a1 - A'. C ! a1
a1: A
A, A'. C A',
. r , , C :
some_routine_of_C (a1: A) is
do
...; a1.r;...
end
some_routine_of_C
A', C A' .
, r A'.
, , C, A,
A'. ( , C - " " A', C
.)
C? - , , .
C , .
,
if a1.

then a1.r end

a1 A', ,
,
. .

, ,
, . , .
, C,
? :
, . ,
, , ,
.
, .
, .
, :
(" "),
- false ( " ").
, A , B, A B,
: , x >= 5 , x >= 0. A B,
, B A.

, . ? ,
, :
;
.

: ,
. , .
, , . ,
.
, :
(1) (Assertion Redeclaration)

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

, MATRIX, .
.
: invert , inverse
inverse_valid. inverse
, inverse_valid ;
, .
.
,
, , ,
10-6. , :
invert (epsilon: REAL) is
-- epsilon
require
epsilon >= 10 ^ (-6)
do
" "
ensure
((Current * inverse) |-| One) <= epsilon
end
, infix "|-|" , m1 |-| m2
|m1 - m2| ( m1 m2), infix "*",
. One - .
, , invert,
,
epsilon ( , :
require
epsilon >= 10 ^ (-20)
...
ensure
((Current * inverse) |-| One) <= (epsilon / 2)

, MATRIX .
. MATRIX NEW_MATRIX.
, ,
. .
, , :
epsilon >= 10 ^ (-20) epsilon >= 10 ^ (-6),
.
. MATRIX
, - - NEW_MATRIX.

some_client_routine (m1: MATRIX; precision: REAL) is
do
... ; m1.invert (precision); ...
-- MATRIX, NEW_MATRIX
end
NEW_MATRIX.
NEW_MATRIX , .
,
MATRIX , .
invert, , epsilon >= 10 ^ (-5), ,
MATRIX, . ,
MATRIX.

.

. 16.3. ,

, , ,

( - , - ). A,
A' ,
, A.
A'
( 16.3), :

a1: A'
...
if a1. then a1.r end
check a1.

end

--

, , a1 A', A, .
, A.
. MATRIX ( )
, ( ) .
NEW_MATRIX,
- - .
NEW_MATRIX, ,
MATRIX ,
NEW_MATRIX.

.
, ,
, ;
.

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

,
, . , ,
.
BOUNDED_STACK (STACK).
(put) count <= capacity,
count - , capacity - .
. ,
BOUNDED_STACK ( ).
, ?
, . ,
, ,
( ), , . put
STACK :
put (x: G) is
-- x .
require
not full

deferred
ensure
...
end
full , ,
.
full: BOOLEAN is
-- ?
-- ( , )
do Result := False end
BOUNDED_STACK full:
full: BOOLEAN is
-- ?
-- (, )
do Result := (count = capacity) end
, not full, , ,
(abstract) .

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

if not s.full then s.put (a) end


STACK, s.
, ,
-. STACK
. , STACK
. . :
;
.
BOUNDED_STACK STACK,
,
put, full.
full STACK Result =
False ( , ) not full. -
, .

, , .
?
, , , - ,
. ,
(
). .
, .
, , a b:

and

or ;

, , , or .
, , and .
:
(2)
require ensure.
, :
require else, or
ensure then, and.
.
, and then or else, and or,
.
, .
,
invert (epsilon: REAL) is
-- epsilon
require
epsilon >= 10 ^ (-6)
...
ensure
((Current * inverse) |-| One) <= epsilon
require ensure,

...
require else
epsilon >= 10 ^ (-20)
...
ensure then
((Current * inverse) |-| One) <= (epsilon / 2)
, : (epsilon >= 10 ^ (-20)) or else (epsilon >=
10 ^ (-6)).
. ,
. ,

or else

, . , and then , .
: epsilon >= 10 ^ (-20), : ((Current *
inverse) |-| One) <= (epsilon / 2), ( , ,
) .


. ,
?
, , True.
, , , .
. , ,
. ( ) ,
.
.
, , ,
. .
,
.


, : "
, ". , ,
.
r,
I O.
r .
DOM r ( I, r
).
x DOM RESULTS(x) O, , r (x)
RESULTS (x). ,
.
,
. ', ,
:
DOM'

DOM

RESULTS' (x)

RESULTS (x) x DOM

, , ,
(DOM), . ,
, , , ,
RESULTS(x), ,
.
()
. , ( I)
. .
[M 1990].


(universal) GENERAL ANY,
(objectless) NONE. .

:

, , :
inherit ANY,
ANY Kernel.
,
. , : , ,
, .
GENERAL, ANY.
ANY , : class ANY inherit GENERAL end.
,
ANY, GENERAL .
ANY . , ANY
HOUSE_STYLE ,
: HOUSE_STYLE
GENERAL. . 16.4 " "
, GENERAL .

. 16.4.

. 16.4 NONE, ANY, ,

( ). NONE , - ,
, :
Void - , , NONE.
(, Void - GENERAL.)
, NONE.
feature {NONE}( feature {}, )
export {NONE}( , export {}),
, , NONE
. , NONE .
, Void
. Void , , Void NONE,
, : NONE
, Void
, .

, , feature
, , feature {ANY}.
, ,
export {ANY} export.
ANY NONE : (
) .

, GENERAL, ,
. :
clone () , "" deep_clone
;
copy ;
equal (--), "" deep_equal;
print print_line - (default
representation);
tagged_out - , ,
(tag) ( );
same_type conforms_to - , ;
generator - (generating) , ,
.


- - ,
-, , .
?

.
"" - ,
. ,
, .
,
, .
"" - .
:
frozen feature_name ... is... - ...
redefine
undefine , ( , , - ).
, ,
.
copy, clone equality
(frozen) , ,
GENERAL. , :
copy, frozen standard_copy (other: ...) is
-- other .
require
other_not_void: other /= Void
do
...
ensure
equal (Current, other)
end

(copy standard_copy) .
, . ,
, - .
copy, , ARRAY STRING, ,
.
- standard_copy.
clone, GENERAL, "" standard_clone,
. clone?
, copy clone, ,
, . clone :
frozen clone (other:...): ... is
-- Void other ; ,
other.
do
if other /= Void then
Result := " , other"
Result.copy (other)
end
ensure
equal (Result, other)
end
" , other" ,
, other. (Result Void, other - ""
.)
clone, ,
copy, ARRAY STRING. ( copy-clone
copy) ( clone , , ).
clone ( ), copy
. copy clone,
. equal, , ,
clone, , :
frozen equal (some, other: ...): BOOLEAN is
-- some other
-- , ?
do
Result := ((some = Void) and (other = Void)) or else some.is_equal (other)
ensure
Result = ((some = Void) and (other = Void)) or else some.is_equal (other)
end
equal (a, b) - a.is_ equal (b),
, , a b . is_equal
, copy. ,
copy-clone, copy clone
- .

- ,
.
. (
, C++ Smalltalk, ,
.)
, frozen, .
, - ,
, .
, ,
(routine inlining). - , . frozen
, , (

), .


, (genericity)
"". :
- , SOME_CONTAINER_TYPE [T] T T, T.
,
.
,
, ,
.
.
, VECTOR,
. . :
indexing
description: " "
class
VECTOR [G]
feature --
count: INTEGER
--
item, infix "@" (i: INTEGER): G is
-- i ( 1)
require ... do
...
end
feature --
infix "+" (other: VECTOR [G]): VECTOR is
-- other
require ... do
...
end
... ...
invariant
non_negative_count: count >= 0
end
.
i- : v.item (i) v @ i.
"+".
. :
infix "+" (other: VECTOR [G]): VECTOR is
-- other
require
count = other.count
local
i: INTEGER
do
" Result count "
from i := 1 until i > count loop
Result.put(item (i) + other.item (i), i)
i := i + 1
end
end
- i- i- other.
put i- Result, VECTOR,
, , .

. 16.5.
! +, (VECTOR),
(G), . ,
- , ,
.
(generic derivation).
INTEGER (), infix "+" ,
. ELLIPSE, STACK, EMPLOYEE
?
: STACK, LIST ARRAY - ,
( G ) -
(, ) . ,
, , ,
.
. .
, , sort,
.
, infix
"<=", .

-, ,
. , ,
-, .
-
, , , -.
Ada , .
, , . :
VECTOR_PROCESSING VECTOR infix "+".
Ada , ,
. , , .
:
generic
type G is private;
with function "+" (a, b: G) return G is <>;
with function "*" (a, b: G) return G is <>;
zero: G; unity: G;
package VECTOR_HANDLING is
... ...
end VECTOR_HANDLING
, G zero -
. :

package BOOLEAN_VECTOR_HANDLING is
new VECTOR_HANDLING (BOOLEAN, "or", "and", false, true);
or , and - ,
zero unity.
.
Ada, . - -
,
. , .
, " " , , infix "+",
, INTEGER BOOLEAN. , zero
unity, - - .

. .
, , VECTOR (
), , : infix "+", zero ..
, , , -
, , .
:
class C [G -> CONSTRAINING_TYPE] ... ...
CONSTRAINING_TYPE - , (generic constraint).
-> . , :
,
CONSTRAINING_TYPE;
C G ,
CONSTRAINING_TYPE, ,
.
VECTOR? ,
NUMERIC - , :
( ).
, . ,
:
indexing
description: ", "
class
VECTOR [G -> NUMERIC]
... - ( !) ...

Result.put(item (i) + other.item (i), i)
, item (i) other.item (i) G, ,
NUMERIC, , "+".
, , ,
, NUMERIC:
VECTOR [NUMERIC]
VECTOR [REAL]
VECTOR [COMPLEX]

EMPLOYEE NUMERIC, VECTOR [EMPLOYEE]


.
NUMERIC .
( ), (VECTOR [NUMERIC_COMPARABLE]),
NUMERIC.
, :
class DICTIONARY [G, H -> HASHABLE] ...
class SORTABLE [G -> COMPARABLE] ...

: , ? VECTOR
[VECTOR [INTEGER]]?
: NUMERIC.
- VECTOR NUMERIC (. 16.2):
indexing
description: ", "
class
VECTOR [G -> NUMERIC]
inherit
NUMERIC
... - ...
, , "".
, (zero) G-, (unity) - G. - , , infix "+",
.
VECTOR [VECTOR [VECTOR [INTEGER]]] -
.

, . - STACK [G] ARRAY [G] - -
. DICTIONARY [G, H -> HASHABLE]
, ,
.
. , ,
, class C [G] class C [G -> ANY]. G (, STACK), x - , G,
, x: , (=, /=),
clone, equal .


,
, .

, ,
, , ,
.
, ( 14).
: x.f , x
f.
: a

, a , ,
.
- -
. , , ,
.
.
, . , , - , , ,
. .
,
; ,
.
- - ,
.
.
, :
figlist: LIST [FIGURE]
.
( -1, ).
. item (i).diagonal, item (i) - i- ,
: item (i) FIGURE, , RECTANGLE,
diagonal. , ,
, - , . ,
.
.
, STORABLE, .
:
my_last_book: BOOK
...
my_last_book := retrieved (my_book_file)
, retrieved, STORABLE Kernel,
ANY. STORABLE ANY, - BOOK.
my_last_book .
retrieved,
, . ,
,
. EMPLOYEE
BOOK, , .

: .
, , ,
- . , ,
:
if "f RECTANGLE" then
...
elseif "f CIRCLE" then
...
..
-.
.
.

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

.
, (assignment attempt):
target ?= source
. target T,
:
source T , target ,
;
( source void ) target
void.
, : target (T)
.
, ,
:
maxdiag (figlist: LIST [FIGURE]): REAL is
-- ;
-- , -1.
require
list_exists: figlist /= Void
local
r: RECTANGLE
do
from
figlist.start; Result := -1.0
until
figlist.after
loop
r ?= figlist.item
if r /= Void then
Result := Result.max (r.diagonal)
end
figlist.forth
end
end

( 5 " - "). start
( ), after - , ,
forth - , item (, not after) -
.
r RECTANGLE.
r Void. r Void, r
r.diagonal. .
, : r.diagonal
: - , , diagonal RECTANGLE,
- , r Void, .
- RECTANGLE, SQUARE (), r

, .
retrieval :
my_last_book: BOOK
... :=
my_last_book ?= retrieved (my_book_file)
if my_last_book /= Void then
... " my_last_book" ...
else
... " " ...
end

, , ,
, " ".
, .
, ,
(case-by-case).
, , .
, f.display, -
, , - , - :
display (f: FIGURE) is
-- f, ,
-- .
local
r: RECTANGLE; t: TRIANGLE; p: POLYGON; s: SQUARE
sg: SEGMENT; e: ELLIPSE; c: CIRCLE;?
do
r ?= f; if r /= Void then " " end
t ?= f; if t /= Void then " " end
c ?= f; if c /= Void then " " end
... .. ...
end
, , ,
, .
-
-.
.
"" (narrowing) Java.
. ,
- , . instanceof Java
.
- Java . ,
Java NONE,
Void .


.
- - ,
.
, , ,
, . .

. , ,

, , -
:
class DEVICE feature
alternate: DEVICE
set_alternate (a: DEVICE) is
-- a - .
do
alternate := a
end
... ...
end
, .
, - , -
:

. 16.6.
class PRINTER inherit
DEVICE
redefine alternate, set_alternate
feature
alternate: PRINTER
set_alternate (a: PRINTER) is
-- a - .
... DEVICE ...
... ...
end
.
-
.
LINKABLE, , LINKED_LIST -
. :
indexing
description: " "
class LINKABLE [G] feature
item: G
right: LINKABLE [G]
put_right (other: LINKABLE [G]) is
-- other .
do right := other end
... ...
end

. 16.7.
. TWO_WAY_LIST - LINKED_LIST
BI_LINKABLE, LINKABLE.

. 16.8.
:

. 16.9.
( ,
, ). right
put_right, .
indexing
description: " "
class BI_LINKABLE [G] inherit
LINKABLE [G]
redefine right, put_right end
feature
left, right: BI_LINKABLE [G]
put_right (other: BI_LINKABLE [G]) is
-- other .
do
right := other
if other /= Void then other.put_left (Current) end
end
put_left (other: BI_LINKABLE [G]) is
-- other .
... ...
... ...
invariant
right = Void or else right.left = Current
left = Void or else left.right = Current
end
( put_left. ! . A.)


, , ,
. ,
, , , a
set_alternate other put_right; - alternate right.
:

( )
( ) .
. "", , ,
,
.
, , , . ,
BI_LINKABLE.
, , -
(covariant typing), ""
.
, ,
.


.
?

LINKED_LIST.
, .
, new
LINKABLE, , .

. 16.10.
put_right (v: G) is
-- v .
-- .
require
not after
local
new: LINKABLE [T]
do
create new.make (v)
put_linkable_right (new)
...
ensure
... . A ...
end

, v,
LINKABLE [G]. put_linkable_right, LINKABLE
( , put_right LINKABLE).
.
LINKED_LIST, TWO_WAY_LIST LINKED_TREE, put_right
. ! , new
- BI_LINKABLE LINKED_TREE.
, , ,
new! ,
, .

, ,
, LINKED_LIST.
some_attribute: SOME_TYPE
set_attribute (a: SOME_TYPE) is do ... end
some_attribute set_attribute.
put_right BI_LINKABLE ( LINKED_LIST)
, . (
, set_alternate) .
, ( set_xxx,
). POINT ,
, , - :

. 16.11.
conjugate: POINT is
-- ,
do
Result := clone (Current) --
Result.move (0, -2*y) --
end
, POINT, PARTICLE. ,
, , , . , conjugate PARTICLE
y. ,
- :
p1, p2: PARTICLE; create p1.make (...); ...
p2 := p1.conjugate
POINT, - PARTICLE.
. conjugate PARTICLE .

, , p2 .

LINKED_LIST A, , .
LINKABLE [G],
. ,
:
first_element, previous, active, next: LINKABLE [G]
TWO_WAY_LIST .
. , put_right, ""
. TWO_WAY_LIST
.

, ,
, .
,
.
: , .
. - ,
.
(anchored).
like anchor
anchor, (anchor) , - ( )
, Current. my_entity: like anchor A,
anchor - , , anchor, ,
anchor my_entity.
anchor T, my_entity A ,
T. A, :
my_entity: like anchor
my_entity: T
A. (like) anchor, my_entity
anchor, .
, , ,
, , "" (like)
. .
LINKED_LIST. first_element
LINKABLE [G]:
first_element: LINKABLE [G]
previous, active, next: like first_element
new put_right LINKED_LIST like
first_element, - .
first_element BI_LINKABLE TWO_WAY_LIST, LINKED_TREE LINKED_TREE ..
, like, redefine.
put_right.
,
.

Current
Current, (
. 7). , A like Current,
A, B, A, - B.
.
conjugate, POINT:
conjugate: like Current is
... - , ...
conjugate . ,
PARTICLE PARTICLE.
LINKABLE,
right: LINKABLE [G]
put_right (other: LINKABLE [G]) is...
LINKABLE [G] like Current. left BI_LINKABLE .
set_attribute. DEVICE :
class DEVICE feature
alternate: like Current
set_alternate (a: like Current) is
-- a - .
do
alternate := a
end
... ...
end

.
, - -, - ,
, , .
. ,
,
, . , , LIST [INTEGER]
LIST. ; :
expanded SOME_CLASS [...] - SOME_CLASS.
- , , ,
. like anchor
anchor . anchor Current, ,
.

like anchor anchor
. , .
(anchored anchor) , ,
.
T - anchor ( , anchor Current). like anchor
, T.
: , like anchor, - .
, T. :

anchor, other: T; x: like anchor


...
create other
x := other -- :
, anchor U, T, ,
x T, U U- , .
, x - y, x y like z, z y. : x := anchor, anchor := x, -
(anchor-equivalent) , , .
,
r (other: like Current)
, , b a.r(b), - a.

x: A A x: like Current
, - .
-
. , : like anchor,
(
, ). ,
: x T, , U.
. ,
,
. " ". ( -
like .)
first_child ,
. ( first_element
, CELL [G] LINKABLE [G].)
. , :
first_child: like Current
. ,
( ): UNARY_TREE ( ), BINARY_TREE (
) BOUNDED_ARITY_TREE ( ).
first_child .
,
. :
first_child: TREE [G]
- , ,
TREE , HOMOGENEOUS_TREE,
first_child
first_child: like Current
.

:
, .
.

,
. ,
.


, ,
.
.
: ,
, .
-
?
- . , . B
f, A. :
f
f
f
f

A B ( );
A B;
A, B;
A, B.

: f , A.
, export . :
class B inherit
A
export {NONE} f end
-- f (, A)
...

class B inherit
A
export {ANY} f end
-- f (, A)
...

class B inherit
A
export {X, Y, Z} f end
-- f
...

.
GENERAL_ACCOUNT - ,
: open, withdraw, deposit, code ( ),
change_code ..,- ,
. :
. open deposit, ,
, - withdraw code, . .

. 16.12.
(. 6 " -
") (facility inheritance).
(view) ,
, , .
, , .
right CELL , , LIST.
CELL, .
( TREE), CELL, LIST, right
.
?
, ,
, .
. , ,
, , .
. :
, ,
, . ,
, . ( : ,
, : , ,
; .)
, Simula .,
.
.
-: ,
20 , , ,
.
, , -
.
CELL TREE : CELL
LIST, right put_right .
- TREE. ,
.
,
, .
- .
- , .
- , - .

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

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

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

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

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

16.1.

, , ,
.


, .
A, f B:
class A feature {B, ...}
f...
...
f B. B, ,
, B ,
, f.
. , ,
. B
A .
, -, A ,
f B, , B. ,
:

, .


.
,
.
( )
, .
require else (
"") ensure then ( "").
require/ensure .
.
GENERAL
,
. NONE .
, .

.
, .
.
(, ,
). -
, .
(like anchor) - ,
.
- .
.
, , .


. [Snyder 1986].

16.1 :
, STACK3 ,
STACK, . (: .
.)

16.2
VECTOR, ()
. , .
, NUMERIC (
[M 1994a]).
16.3 ?
, x1 X, y1 Y, Y X, y1 := x1
. extract, ,
y1.extract (x1) x1 y1 ,
Void.
, extract . (: ,
, .) , ,
- .

-
17. :
,
. , (static typing), : ,
, ;
, : , ;
, .
, , ,
, , ,
, - - .


- : ,
.

- . ,
, - - (feature call):
x.f (arg)
f , x, arg (
). Smalltalk " x
f arg", - , .
, (Basic Construct), -.
, :
:
, , (type violation)
x.f (arg), x OBJ, :
, f OBJ,
, , arg .
- :
-
, - ?
. , . ,
" " " " .
, .

, :
: .
: ,
. , .
:
(), ( ).
(typed/untyped)
(statically/dynamically typed).
.
, , , .
:
:
- , , ,
, .

" " (strong). ,


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

- .
.
, , acc: ACCOUNT.
0 , , : put (x:
G; i: INTEGER).
x := y , y -
x, y x.
: B A, , -
( 14).
x.f (arg) , f x, f
, (. 14.3).

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

"" . ,
, , .
, , Pascal- REAL INTEGER. n:
INTEGER; r: Real n := r , . ,
:
n
n
n
n

:=
:=
:=
:=

0.0
1.0
-3.67
3.67 - 3.67

[A]
[B]
[C]
[D]

, , [A] ,
0,0, 0 . [B]
. [C] (
?). [D] , :
if n ^ 2 < 0 then n := 3.67 end

[E]

(n ^ 2 - n). n ^ 2 n
. n , ,
.

( , , )
.
, , , .
: ,
, .
, . , , round truncate, n := r ,
, .

:
, .

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

. 17.1. ([Boehm 1981], )


(readability) .
.
.
, ,
. , , , ,
.
(type inference). , , -
, .
, .
x.f (arg) . ,
, f x, ,
. , . Self
, .
- .

, ,
x.f (arg), x. -
f. , ,
f , -
. (static binding)
(inlining) - , ,
.

, , , Smalltalk. , . ,
, ,
" ".
, ,
. , , ,
- , , ,
, .
:
? ,
.
.
. ,
INTEGER, , . (
"" Object Pascal, Java C++,
, .)
, , , ,
.

. , ,
Pascal Ada, x := y , x y . :
, (SAVINGS_ACCOUNT
CHECKING_ACCOUNT). y x, , x
ACCOUNT, y - SAVINGS_ACCOUNT, - .
.
, -
. , DOCUMENT () , ,
MESSAGE ( ). ,
.

. 17.2.
, , ,
( class LIST [G] ...). ,
, .
, ,
. SORTABLE_LIST ,
G, G - , . G ,
, - COMPARABLE:
class SORTABLE_LIST [G -> COMPARABLE] ...
SORTABLE_LIST COMPARABLE,
.

- - ,
. y - , , x ?= y x
y, y , , , x Void.
, , ,
, , ,
. , Pascal Ada, -,
, , 10 20, , , ,
i , j. ,
, .
, . y:
like x, , y x .
,
.
- - ,
.
, , (fast incremental) . ,
.
. (
), , .
, Lisp Smalltalk,
, . .
, ,
.
" "?
- . "
", , , .
,
. C " " (cast).
(OTHER_TYPE) x , x , OTHER_TYPE,
.
.
C, ANSI C. C++ , ,
, , .
, .
, .
, , - . : ,
, - , .

, ,
. Smalltalk,
,
. ( ,
.)
, x.f (arg),
:

: , ,
f, , x ( arg)?
: , ?
, .
:
, , : x
, , , f,

, , , f,
;
:
, , , f
.
, .
.
, , Pascal Ada, ,
. , .
, .
Smalltalk - .
.
. (scripting languages).
, .
C++, ,
, ( ),
(virtual) .
. : "
?" - : " , ", :
. : " ?" : ",
", - , .
, .
:

. 17.3.
:
my_aircraft.lower_landing_gear
: , lower_landing_gear (" "),
( COPTER ) :
.
,
. , Boeing 747-400, ,
747, 747-400. , ,
.
, ,
my_aircraft , ,
lower_landing_gear. : my_aircraft
, . my_aircraft

AIRCRAFT, lower_landing_gear ; ,
, . PLANE, - ,
, - .
Smalltalk ,
. ,
- , .


, .
, , ,
, .
.
, . :
(covariance) - , (descendant hiding) -
.

? ,
: , - . . (. 16.6, 16.7).
, . ,
. , ,
.
. GIRL ,
, BOY - . ,
. , ,
. ( , ,
,
.) , : RANKED_GIRL RANKED_BOY.

. 17.4.
: , , . : ROOM, GIRL_ROOM
RANKED_GIRL_ROOM.
SKIER:
class SKIER feature
roommate: SKIER
-- .
share (other: SKIER) is
-- other.
require
other /= Void
do
roommate := other
end
... , ...
end

: roommate share, " "


:
s1, s2: SKIER
...
s1.share (s2)
other SKIER like roommate ( like
Current roommate other ). (
) .
? ,
. roommate,
( ).
class GIRL inherit
SKIER
redefine roommate end
feature
roommate: GIRL
-- .
end
, , share. :
class GIRL inherit
SKIER
redefine roommate, share end
feature
roommate: GIRL
-- .
share (other: GIRL) is
-- other.
require
other /= Void
do
roommate := other
end
end
SKIER ( ).
:

. 17.5.
, ,
, roommate, .
other share. , , , ""
.

.
.
LINKABLE ,
BI_LINKABLE - . put_right.
LINKED_LIST LINKABLE TWO_WAY_LIST
BI_LINKABLE.
set_alternate DEVICE- DEVICE PRINTER- -
PRINTER.
,

set_attrib (v: SOME_TYPE) is
-- attrib v.
...
attrib SOME_TYPE. , , , ,
, set_attrib.
, . , ,
, (LINKED_LIST).
(TWO_ WAY_LIST). infix "+"
NUMERIC- NUMERIC, REAL - REAL INTEGER - INTEGER.
start PHONE_SERVICE ADDRESS,
, ( ),
CORPORATE_SERVICE CORPORATE_ADDRESS.

. 17.6.
? , ,
RANKED_GIRL, roommate RANKED_GIRL,
share GIRL SKIER. ,
, - RANKED_GIRL! ,
.

, SKIER .
, : TWO_ WAY_LIST > LINKED_LIST
BI_LINKABLE > LINKABLE; PHONE_SERVICE.
ROOM, GIRL_ROOM ( BOY ):

. 17.7.
roommate share
accommodation () accommodate ():
indexing
description: " "
class SKIER1 feature
accommodation: ROOM
accommodate (r: ROOM) is ... require ... do
accommodation:= r
end
end
: GIRL1 accommodation,
accommodate GIRL_ROOM, BOY1 - BOY_ROOM .. (
: - .) ,
.

, ? -
, , (
)? , ,
. , , ,
:
s: SKIER; b: BOY; g: GIRL
...
create b; create g;-- BOY GIRL.
s := b; -- .
s.share (g)
, , - ,
. share , BOY, b
s SKIER, GIRL, g.
, , ,
share - SKIER, GIRL, g, SKIER,
share.
: SKIER SKIER1, share -
s.accommodate (gr), gr - GIRL_ROOM. - .
: ( s)
.
: - - . ,
. , ,
, .
,
. - , - .

, ,
.

, ,
. (descendant hiding) -
, .

. 17.8.
add_vertex ( ), POLYGON,
RECTANGLE ( -
):
class RECTANGLE inherit
POLYGON
export {NONE} add_vertex end
feature
...
invariant
vertex_count = 4
end
: "" "", "".
, , ,
. , , - ,
- . , , ,
:
p: POLYGON; r: RECTANGLE
...
create r;
-- RECTANGLE.
p := r;
-- .
p.add_vertex (...)
r p POLYGON, add_vertex POLYGON,
p . , ,
.

.
- (class-valid) , ,
. : ;
, ;
, .
- (system-valid), .
. , -
, -.
(system validity error).

: ,
,
, .
,
.
.
, . , 1-11 " -
", , 6 " ", .

:
, .
, .

, .
,
.
C++ , (novariance),
! C++ ,
. , C++
(, ), - ,
. . , ,
, , ,
.

, (Franz Weber).
SKIER1, ROOM:
class SKIER1 [G -> ROOM] feature
accommodation: G
accommodate (r: G) is ... require ... do accommodation := r end
end
GIRL1 SKIER1 [GIRL_ROOM] . . ,
, : class SKIER [G -> SKIER].
.
ROOM GIRL_ROOM, .
,
.
, ,
, . ,
, , , ,
, , , .

, (Kim Bruce), (David Shang) (Tony Simons),
(type variables), .
:
, ;
;
( ) ;
.
,
(Cardelli), (Castagna), (Weber) . ,
. , .
,
. .
.

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

,
.
SKIER SKIER1 ,
, . - .
( ):
class SKIER feature
roommate: like Current
share (other: like Current) is ... require ... do
roommate := other
end
...
end
class SKIER1 feature
accommodation: ROOM
accommodate (r: like accommodation) is ... require ... do
accommodation := r
end
end
SKIER , SKIER1
accommodation. : roommate share accommodate -
. ,
( , , ) -
.
? ! , , ,
, .
, . :
s: SKIER; b: BOY; g: GIRL
...
create b;create g;-- BOY GIRL.
s := b;
-- .
sl share (g)
g, share, , like s, GIRL
, like s,
.
, . , like s s.
, s, g, :
s: SKIER; b: BOY; g: like s; actual_g: GIRL;
...
create b; create actual_g
-- BOY GIRL.
s := actual_g; g := s
-- s g GIRL.
s := b
-- .
s.share (g)
.
.
, ,
. : anchor (
, ):

anchor s: SKIER
like s , s anchor. ,
: s like s ( )
.
- . , ,
.
.
, , .
, , .
, . ,
D :
r (u: Y) ...
C - D
r (u: X) ...
Y X, r :
r (u: like your_anchor) ...
D your_anchor.
- (Anchoring).
: " ". :
(,
, ) . , anchor like some_anchor
; -. ,
, . , ,
.
.
.
,
. ( , -, ,
, .)
, - ,
, - .
( , ): ,
. ,
, , ,
.
, . ?
, . ,
, .
, - . ,
, ,
:
: (
) , .
.
, ,
.
? -
- , ,
, , ,
.
- " ",
, :
, ,

. .
. ,
RECTANGLE, , POLYGON, .
,
, .
, .
? , ,
. -, . -,
, , .
,
, . , .


. 17.
, ,
. ,
s := b ...
s.share (g)
-: - , . s. :
p := r ...
p.add_vertex (...)
.
. BOY
s, g share, GIRL.
r RECTANGLE, add_vertex .
: - ,
- (typeset) , ,
. , , ,
.
s := b , BOY s (
create b b). GIRL,
create g, g. share s BOY
g GIRL. RECTANGLE p,
, , add_vertex p RECTANGLE .
:

x.f (arg) -, - x, arg,
.
-, ,
: C x, f C, arg
f. (: ,
, , .)
,
, .
:
1. .
2. create {SOME_TYPE} a, SOME_TYPE a. (
, create a create {ATYPE} a,
ATYPE - a.)
3. a := b, a b.
4. a , , b,
a b.
5. (3) (4) , .
,
. (5) ( b a, c b . .).

. (5) ( b a, c b . .).
, .
; n,
xi+1 xi i=1, 2, ... n-1. (3) (4)
" ".
, , , .
create {TYPE1} t; s := t; create {TYPE2} t
s TYPE1, TYPE2, s, ,
.
, .
: :
create b
s := b
s.share (g)
-, ,
.
( ) 22- [M 1992].
, .
, : ,
. (4),
.
[M 1989b],
. , , ,
. ()
, .
, - , C lint ,
, - .
, , . (
, , .)
, , , ,
. ,
.
, , ,
( ). .

!
:
. ,
. , , .
,
(Catcall), - , -
, ( - ),
.
, .
: s := b, : s.share (g). ,
, g . , SKIER
, s share.
other SKIER SKIER, s.share (other)
, , s
b.
, s :
. (
p ,
add_vertex.)
, , :
. , ,

, , ,
. ,
, .

:

.
- . , :
:
x ( ) , :
1. x := y, y .
2. create {OTHER_TYPE} x, OTHER_TYPE ,
x.
3. .
4. .
- (" ") ,
.
, .
s p - (1). BOY
b, - RECTANGLE r.
, ,
, .
, :
? (3),
( , . .). .
, , ,
. -
, - ,
.
, .
. ( )
, .
, ,
.
,
.
, , :
:
, .
: s.share (g) s, p.add_ vertex (...)
p. , . (
f (...) Current.f (...), ,
Current, , .)
, CAT. (CAT - Changing Availability or
Type - ). CAT ,
, , ,
: () .
: CAT-
CAT-,
.
- :
CAT-. : CAT, .

:
, -
.
: .
,
. , , ,
(usefulness), - (usability).
share add_vertex, , -.
. RECTANGLE,
POLYGON. , .
.

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


, ,
. -,
.
, , -
. share,
, , - . .
, .
fitted ():
fitted (other: GENERAL): like other is
-- (Current), ,
-- other, void.
do
if other /= Void and then conforms_to (other) then
Result ?= Current

end
end
fitted , , .
, , Void.
. conforms_to GENERAL,
.
conforms_to GENERAL same_type perfect_fitted
( ), Void, .
fitted - .
, SKIER share, (
).
safe_share (other: SKIER) is
-- , , other .
-- gender_ascertained -
local
gender_ascertained_other: like Current
do
gender_ascertained_other := other .fitted (Current)
if gender_ascertained_other /= Void then
share (gender_ascertained_other)
else
": other "
end
end
other SKIER ( like Current) gender_ascertained_other,
, Current. perfect_ fitted.
, :
occupant1, occupant2: LIST [SKIER]
, :
occupant1.item.safe_share (occupant2.item)
, .


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


OOPSLA 95 TOOLS PACIFIC 95,
[M 1996a]. [M 1989e].
[Milner 1989],
ML. [Cardelli 1984a].
Self
[Ungar 1992].
,
, (Luca Cardelli) (Peter Wegner) [Cardelli 1985]. ,
- (. [M 1990]), .
[Cardelli 1984].

ISE ,
[M 1988a].
( (Philippe Elinck)
"De la Conception-Programmation par Objets", Memoire de licence, Universite Libre de Bruxelles (Belgium), 1988),
[Cook 1989] [America 1989a]. ,
, .
TOOLS EUROPE 1992 [Weber 1992].
, , [M 1992],
. [M 1996a]; . [M-Web].
TOOLS EUROPE 1994. , ,
anchor- . (Paul
Dubois) (Amiram Yehudai) ,
. , (Reinhardt Budde), - (Karl-Heinz Sylla), (Kim
Walden) - (James McKim) ,
, .
. [Castagna 1995] [Castagna 1996]
, .
Web- . (Laurent Dami) [Dami-Web].
.
, 80-
., 80- .
[Simons 1995], [Shang 1996], [Bruce 1997].
Sather. [Szypersky 1993].

-
18. :
- : ,
, .
. - , .
(shared) - . - -,
, . ,
. . , ,
, , ?
, .
, .
, ,
. . Pi, , ?
, .


.
- - , (,
) . ,
, (symbolic constant), , (manifest constant).
. .
: US_states_count, 50;
: , .
, ,
"" , from i = 1 until i > n ( n, ,
).
, .
-
, .
, .
is, ,
, .
INTEGER, BOOLEAN, REAL CHARACTER:
Zero: INTEGER is 0
Ok: BOOLEAN is True
Pi: REAL is 3.1415926524
Backslash: CHARACTER is '\'
, - ,
.
-.
, . , C - ,
, x C,
x.Backslash '\'.
-, .
, , .


, , , :
class FILE feature
error_code: INTEGER;

-- -

Ok: INTEGER is 0
Open_error: INTEGER is 1
...
open (file_name: STRING) is
-- file_name
--
do
error_code := Ok
...
if "- " then
error_code := Open_error
end
end
... ...
end
open :
f: FILE; ...
f.open
if f.error_code = f.Open_error then
" "
else
...
end
, . , ,
, , .
:
class EDITOR_CONSTANTS
feature
Insert: CHARACTER is 'i'
Delete: CHARACTER is 'd'; -- ..
...
end
class SOME_CLASS_FOR_THE_EDITOR
inherit
EDITOR_CONSTANTS
... ...
feature ...
... , EDITOR_CONSTANTS ...
end
, EDITOR_CONSTANTS, ,
" " ( - ) ,
. .
, SOME_CLASS_FOR_THE_EDITOR
.


, INTEGER.
, , .
.

, :
class COMPLEX creation
make_cartesian, make_polar
feature
x, y: REAL
--

make_cartesian (a, b: REAL) is


-- a, - b.
do
x := a; y := b
end
... ( x y, ) ...
end
- i, 0,
1. , , -
i: COMPLEX is ", (0, 1)"
is?
.
:
i: COMPLEX is COMPLEX (0, 1)
, -, -
. , , COMPLEX
, .
, ,
?
. ,
.
( clone) .
, .

- . , i ( )
COMPLEX
i: COMPLEX is
-- , re= 0, im= 1
do
create Result.make_cartesian (0, 1)
end
, .
, , -
, .
: i ,
, - . ,
. (once function).
once,
do :
i: COMPLEX is
-- , re= 0, im= 1
once
create Result.make_cartesian (0, 1)
end
,
, .
, . , i
, .. , .

, ,
, , .
( ) . , COMPLEX1,
COMPLEX, i, i COMPLEX1
, i COMPLEX ,
COMPLEX1, , ,
.


, ,
, .

, COMPLEX, ,
. , ,
, ,
.
, , ,
, . ,
, .
, .
- .
:
Message_window.put_text (" ")
Message_window WINDOW, :
class WINDOW
creation
make
feature
make (...) is
-- ; .
do ... end
text: STRING
--
put_text (s: STRING) is
-- s .
do
text := s
end
... ...
end -- WINDOW
, Message_window .
:
Message_window: WINDOW is
--
once
create Result.make ("... ...")
end
,
. put_text ,
. Message_window ,
, .
, , (, i),
i.some_procedure, . , , COMPLEX

i.x = 0 i.y = 1.

- "
", , .
. :
,
;

. .
,
. :
Const_value: T is
--
local
envir_param: T ' -- (T )
once
" envir_param "
Result := ", envir_param"
end
.
, ENVIR. ,
Const_value, , ENVIR .
, ,
, .
,
, : ,
. , , ENVIR, ,
.
, , Const_value, ,
. Const_value ,
, .
, , .
.
, , .
.

close .
.
C
.
, ,
.
, , ,
, . , ,
, . ,
, - , ,
. "", - ,
.
:
check_setup is
-- , .
once

terminal_setup -- .
end
check_setup,
, . , check_setup
.
- ,
.

, , ,
.
,
,
.
, ,
.
. EXAMPLE [G] ,
:
f: G is once ... end
:
character_example: EXAMPLE [CHARACTER]
...
print (character_example.f)
. :
integer_example: EXAMPLE [INTEGER]
...
print (integer_example.f + 1)
. , f, ,
, f - , , .
.
,
, .
. B,
A:
class B inherit A feature
attribute_of_B: INTEGER
end
A f, :
f: like Current is once create Resultl make end
f :
a2 := a1.f
a1 a2 . f A a2. .

, :
b2 := b1.f
b1 b2 B. f , . f
B . ,
. - A, B. :
print (b2.attribute_of_B)
A.
, . f
, B
f: B is once create Resultl make end
, f A A ( like Current),
: A f A, B - f B.
, .
- (
) .
, , ,

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

.


, . :
Backslash: CHARACTER is '\'
, , ,
:
[S1]
Message: STRING is "Syntax error" -- " "
, STRING - . - , ,
Message , , STRING.
, :
[S2]
Message: STRING is
-- 12
once
create Result.make (12)
Result.put ('S', 1)
Result.put ('y', 2)
...
Result.put ('r', 12)
end

, . ,
Message, .
:
Message_window.display (" ")
greeting := "!"

Unique-
, ,
. , ,
, .
:
code: INTEGER

[U1]
Successful: INTEGER is 1
Open_error: INTEGER is 2
Read_error: INTEGER is 3

[U2]
if code = Successful then ...

[U3]
inspect
code
when Successful then
...
when ...
end
. , [U1]:
[U4]
Successful, Open_error, Read_error: INTEGER is unique
unique, -
, , , .
[U2] [U3] - .
unique- . , [U4],
, .
code ,
code >= Successful; code <= Read_error
, , ,
, , code, , ,
.
, unique,
. ,
, [U3].
unique-, - .
.

: green, yellow, red: INTEGER is unique; : do, re, mi, ...: INTEGER
is unique. savings, checking, money_market: INTEGER is unique ,
, ,
. , ,
.
:

unique .
.
unique- (enumerated type)
Pascal Ada, , .
.

" " ,
, .
:
, , - :
, ,
?
,
, ,
.
:
? p ,
, , , ready, ,
. p
if not ready then
" p"
ready := True
end
ready - ,
False.
?
. - , Algol Pascal,
ready ;
. .
Fortran, (
), (common block),
. , , :
COMMON /common_block_name/ data_item_names
:
,
, , .
.
, ready? -
, , (block data unit).
Fortran 77 ,
.
.

C Fortran 77. ready


"" , "" ( ).
, ,
extern, COMMON Fortran 77, .
"" (header) .h-,
Fortran. , make,
.
, Ada Modula 2,
. Ada
"" (package). , ,
, ready
. ( C Fortran 77)
. ,
, . Ada Modula
.
"" , , -
.

( , )
. ,
STRING. -
"" .
STRING , .
: , ,
, .
, ,
.
STRING , .
[S1] ,
[S2]. , ,
.
STRING, ARRAY, " ",
, ,
.
Unique-
Pascal
code: ERROR
ERROR - " ":
type ERROR = (Normal, Open_error, Read_error)
code ERROR. ,
-: , Pascal-
. unique
. , , .
, .
, .
.
.
(, Orange FRUIT COLOR)?
?
,
, , C Fortran, . ,
unique, - , .
. ,

next,
. , ().

.
Pascal Ada :
type FIGURE_SORT = (Circle, Rectangle, Square, ...)
:
FIGURE =
record
perimeter: INTEGER;
... , ...
case fs: FIGURE_SORT of
Circle: (radius: REAL; center: POINT);
Rectangle:... ...;
...
end
end
case:
procedure rotate (f: FIGURE)
begin case f of
Circle:... ...;
Rectangle:...;
...
,
, - , rotate
, .
, ,
, - .
, ,
, , Circle +1, ,
Circle integer. unique- ,
, .


,
,
, - .
. ,
, ,
. ,
.
,
.
, , , ,
.
once,
do. ( ).
, ,
.
.
.
,
, ,
.
.
, ,

, .
Pascal .
unique
. .


[Welsh 1977] [Moffat 1981]. ,
, [M 1988b].

18.1
, unique- Pascal
type ERROR = (Normal, Open_error, Read_error)
.
18.2 unique-
, unique- ,
value: INTEGER is unique
,
value: INTEGER is once...end
, .
18.3
, , , ,
.
18.4 ?
" ", ?
? ?
? , ,
. .

-
1. : - :
:
.


1- 11-, ,
. , -: ,
, -,
(""), , . , ,
, -,
" - ".
, .
,
, . ,
. ,
.

:
. " " -
.
, -,
. ,
.
, , .
, - ,
. ,
, .
, .
, .
, .
, -,
, , . ,
.
. ,
, ,
, .
, . ,
, , .
,
. ,
.
, ,
.
, , , - .
19-29 ,
, .
- , - .
:
"", , . - ,
, - ,
. ""
- ,
, .

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

.
"Go To Statement Considered Harmful" ( Go To)
.
.
,
, . ,
, .

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

- . , ,
. :
:
.
, - - ,
. ,
, .
, -
.
, , ,
, .
, , , -
.
: , , ,
, ( , , ,
, ).
. ,
, ,
- .
;
, . " "
(seamlessness) (reversibility),
, ,
. ,
.

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

. ?
(advisory) - ,
(absolute) - .
(positive) - , , (negative)
- . :

: " a".
: " b".
: " c, ".
: " d, ".
.

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

.

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

, , .
(platitude), :
, . ,
: " , ", ,
. ,
. , , ,
, - ,
.
, , ,
", "
: " ", -
.
, :
:
( ), ,
. , .
, (casts)
C++:
. ,
, ,
.
, , " ".
(type casts), ,
" ", ,
, , .
, , . , -
, , ,
, .

. ,
, .
: , ,
.

:
, (. ), ,
. ,
:
, .
,
.
,
, - ?
, ?
, ( )
" X A" " Y
A" " B, C D".
: ,
A, A B, C D. ("
" - ?).
, , ,
, :

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

,
.
, , .
, ,
, : -1, -2, -3.
. . ,
, ,
.
,
C++, , ,
:
.
;
, , - .
,
.
" , ",
, , - .
, ,
.
, :
... , .
... .
... .
...
, ...
...
C/C++/Java . "
, " C++,
-.
. ?

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

, - - .
() Java ("
"), a.x := y
. ; , ,
, ,
.
, , . x x.f (...),
r C: r; C; (
u create u) , r. , ,
. , .
, , my_stack.item.some_routine,
some_routine .
, ,
,
. , , .
:
, :
:
L , ,
.
L , .
L , .


: .
: . .
, , I

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

,
.
. - , ,
- .
.
.
, .
(" ") :
A B
B p
-----------------------------------------Ergo: A p
. , B A, A B
. , :
" - , ,
". , , , .
, p .
, , , , ,
. - .
, ,
A B.
[Bachelard 1960] " ", , 18-
, , ,
.
, , ,
.
, , .
,
, .
, ! ,
.
, , , , .
.
, , , ...
: " .
".

, .
,
.


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

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


" " [M 1995b].
[Joseph Gurvet,
TOOLS EUROPE 1992].
.

1.1

.
1.2

[M 1994a] : ,
. .
1.3


.
1.4

. ,
, , "
".

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


- , .
,
.
.
. , .
, ( ,
); , .
,
, .
, ,
User Identification ( ), Enquiry on Flights (
), Enquiry on Seats ( ), Reservation ().
Enquiry on Flights ( ) . 2.1 (
). ,
, ,
( ) .

. 2.1. " "


Initial Final.

, .
,
. . 2.2 .
, ,
. :
G1 . ,
.
G2 , , .
. ,
.
G3 .
.
,
, , ,
.

. 2.2.


, .
: BEnquiry , BReservation , BCancellation .
. ( - , ,
), :
BEnquiry :
" Enquiry on flights"
repeat
" C "
if " " then
" " end
until not " " end
" "
case C in
C0 : goto Exit,
C1 : goto BHelp ,

C2 : goto BReservation ,
...
end
.
? , .
.
goto (
switch C " Goto" Fortran), -
" " .
goto - , . - .
. -
, . - ,
. , ,
- G3 , ,
.
, "
" " ". , ,
. .
, , .
.
, , .

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


. - , ,
. , ,
goto. , ,
, .
? transition, . transition (s, c) ,
c s. "" .
transition ,
, . transition
.
transition initial, - ,
, is_final.
, .
transition , , ,
:

2.1.

0 123

1 (Initial)

-1 0 5 2

2 (Flights)

-1 0 1 3

3 (Seats)

024

4 (Reserv.)

035

5 (Confirm)

041

0 (Help)

Return

-1 (Final)
, : Help 0
Return, , , -1.
, .

, "" -
. , , execute_session,
.

. 2.3. -
( 2) , :
, execute_state, ,
. 1 , execute_state:
. , , -, , " ",
.
- , ,
.
execute_session .
( . repeat until Pascal.)
execute_session is
--
local
state, next: INTEGER
do
state := initial
repeat
execute_state (state, >next)
-- execute_state next
state := transition (state, next)
until is_final (state) end
end
. (, , .)
state, initial; ,
is_final. , , execute_state,
next , .
transition .
, execute_state, ,

-, . ,
"" "out" - next .
execute_state, ,
. goto-.
execute_state (in s: INTEGER; out c: INTEGER) is
-- , s,
-- c ,
local
a: ANSWER; ok: BOOLEAN
do
repeat
display (s)
read (s, a)
ok := correct (s, a)
if not ok then message (s, a) end
until ok end
process (s, a)
c := next_choice (a)
end
1 :
display (s) , s;
read (s, a) a , s;
correct (s, a) true, a ; , process
(s, a) a, , ,
, message (s, a) .
ANSWER , , . a
, (ANSWER
, .)
1: display, read,
correct, message process.


? . , ,
.

, , ,
,
. , .
( ) :

. 2.4.
, , , . s
, execute_session, state.
, . 2.3, ,
, .
. .
() .
, .

. , , - ,
( - perestroik),
.

. 2.5.
- . 1
, s: ,
, , -
. :
inspect
s...
when Initial then
...
when Enquiry_on_flights then
...
....
end
, , , -
. .
- ,
.
, , .
, - -
. , display,
, ! transition
- .

-
, , .

, ?
. -,
:

, .
( execute_session execute_state)

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

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

"" . ,
, -,
( ).
,
, - ,
, . , .
. STATE ,
-.
, :
(display), (read), (correct),
(message), (process).
execute_state, , ,
( , STATE,
execute).
, , ,
STATE.

. 2.6. STATE
:
...class STATE feature
input: ANSWER
choice: INTEGER

execute is do ... end


display is ...
read is ...
correct: BOOLEAN is ...
message is ...
process is ...
end
input choice , - ( ).
,
, , s.execute.
execute ( execute_state)
. . execute
. " ?" choice.
, ANSWER 1 input.
: ,
.

STATE , . execute -
, .
.
STATE execute .
1 (display .) , . , STATE,
, , .
:
indexing
description: " , "
deferred class
STATE
feature -- Access
choice: INTEGER
--
input: ANSWER
--
feature -- Status report
correct: BOOLEAN is
-- input ?
deferred
end
feature -- Basic operations
display is
-- ,
deferred
end
execute is
-- , ,
-- choice -
local
ok: BOOLEAN
do
from ok := False until ok loop
display; read; ok := correct
if not ok then message end
end
process
ensure
ok
end
message is
-- , input
require
not correct
deferred
end
read is
-- input choice
deferred

end
process is
-- input
require
correct
deferred
end
end
STATE,
.

. 2.7. State
:
class ENQUIRY_ON_FLIGHTS inherit
STATE
feature
display is
do
... ...
end
... read, correct, message process ...
end
: , , ,
. , execute,
STATE , ENQUIRY_ON_FLIGHTS. : STATE , , ,
, .
STATE (behavior classes, . 14
" - ") - ,
, , (execute)
, .
.

.
execute_session - . , .
(. 5 " - ")
, , - .
.
. ,
(services).
- STATE.
? : APPLICATION,
, .
.

. 2.8. State Application


, STATE
APPLICATION:
Execute_session - , ,
execute, .
Initial is_final - , . ,
APPLICATION, STATE,
, ,
, . ,
.
Transition - .
-: STATE,
APPLICATION. . , ,
,
. , , ,
. : , ,
, , ,
, .
, , :
(execute_session, execute), (read),
(is_final). , ,
. ? - , .
, , . ,
- execute
- . ,
:
;
;
( );
, ;
, ;
(, ,
);
.
APPLICATION.
, " ", - execute,
, , . ,
.


APPLICATION :
1 n. ,
, , STATE "
". , associated_state, APPLICATION,
, .
transition - n *
m, m - .
initial
choose_initial. , 0
.
APPLICATION ARRAY
ARRAY2. ARRAY;
make , create a.make (1, 25, 1, 10), item
put - a.put (x, 1, 2). a ,
a.lower1 .
, :
indexing
description: " , "
class APPLICATION creation
make
feature -- Initialization
make (n, m: INTEGER) is
-- n m
do
create transition.make (1, n, 1, m)
create associated_state.make (1, n)
end
feature -- Access
initial: INTEGER
--
feature -- Basic operations
execute is
--
local
st: STATE; st_number: INTEGER
do
from
st_number := initial
invariant
0<= st_number; st_number <= n
until st_number = 0 loop
st := associated_state.item (st_number)
st.execute
-- execute STATE.
-- ( .)
st_number := transition.item (st_number, st.choice)
end
end
feature -- Element change
put_state (st: STATE; sn: INTEGER) is
-- st sn
require
1 <= sn; sn <= associated_state.upper
do
associated_state.put (st, sn)
end
choose_initial (sn: INTEGER) is
-- sn
require
1 <= sn; sn <= associated_state.upper
do
initial := sn
end
put_transition (source, target, label: INTEGER) is
-- , label,
-- source target
require

1 <= source; source <= associated_state.upper


0 <= target; target <= associated_state.upper
1 <= label; label <= transition.upper2
do
transition.put (source, label, target)
end
feature {NONE} -- Implementation
transition: ARRAY2 [STATE]
associated_state: ARRAY [STATE]
... ...
invariant
transition.upper1 = associated_state.upper
end -- class APPLICATION
st.execute. execute STATE
( ) ,
: read, message, correct, display, process,
STATE, , RESERVATION.
st.execute execute APPLICATION, ,
st, , .
st ,
RESERVATION, - read, message
.
st, associated_state, (polymorphic data
structure), , ( ) STATE.
st_number .

. 2.9.
. ,
air_reservation, APPLICATION. :
create air_reservation.make (number_of_states, number_of_possible_choices)
, - STATE,
, . s
i :
air_reservation.put_state (s, i).
:
air_reservation.choose_initial (i0)
sn tn, l :
air_reservation.enter_transition (sn, tn, l)
, tn 0.
:
air_reservation.execute_session.

.
, APPLICATION, ,

- , .

, , , -
. , ,
. , , , ,
, ,
.
.
,
, " ?". ,
- , , -
, -
.
, ,
, .
- .
,
, - " ".
, ,
.
, .
, goto , , - ,
,
. .
- - : STATE, APPLICATION,
ANSWER - , , ,
. , , ,
, , .
, ,
, .
-, - ,
, . .


, , - [M 1983] [M
1987].

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


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

Undo,
.
- (
, ). .
- , "-", -
, ,
, , .
. (
Undo, .
, .)
: undo redo
. ,
. , .
. ,
, . , ,
, ,
, ,
20. , .
. Redo,
, .

undo-redo -,
.
command, , .
undo-redo .
. ,
: Undo Redo. ( ,
control-U control-R.) Undo ; Redo
, .
, , , , -
. (
, undo-redo. ,
.)
, , .
: " " ( , ,
) " " .
, . ,
, , Save,
. ,
. ,
.

, ,
, , .
, - , - ,
Undo, " ".
: , ,
, , " ".
- Continue anyway Cancel - :
, , .
, "Undo, Skip, Redo",
Undo Redo. ,
, , :
.
.
, :
(1) .
(2) .

(skip (1) redo (2)). , (2) ,
. , : " "
, (1), ,
(1), .

undo-redo, , :
U1
.
U2 .
U3 .
U4 , .
, .
-
, ( Notepad Vi), ,
: INSERT_LINE, DELETE_LINE, GLOBAL_REPLACEMENT ( ) .
, , ,
.
, Undo Redo
. Undo ,
:
If " INSERT_LINE" then
"Undo INSERT_LINE"
elseif " DELETE_LINE" then
"Undo DELETE_LINE"
..
(. 3 " - "),
, .
. ,
, , ,
INSERT_LINE. .
. , undo-redo
Undo: , DELETE_LINE,
, -
. , .
,
. ,
STORABLE (. 8 " - "),
, . - .
.


.
. , ,
, .


- .
.
Command
COMMAND,
, Undo Redo. ,
, - , .
:
deferred class COMMAND feature
execute is deferred end
undo is deferred end
end
COMMAND .
, :
class LINE_DELETION inherit
COMMAND
feature
deleted_line_index: INTEGER
deleted_line: STRING
set_deleted_line_index (n: INTEGER) is
-- n
do
deleted_line_index := n
end
execute is
--
do
" deleted_line_index"
" deleted_line"
end
undo is
--
do
" deleted_line deleted_line_index"
end
end
.
? LINE_DELETION, ,
, , : ,
, (deleted_line) (deleted_line_index).
undo, , redo.

. 3.1. command
, deleted_line deleted_line_index, ,
execute undo. ,
:
, U3 - ,
.
:

. 3.2. COMMAND
( COMMAND ),
, , .
, .
Undo Redo; , Undo (
Redo). (operation) Undo Redo
(command) , , .
, , , Undo,
- .
" ",
" ", , .
command operation ; ,
- .
.

, .
.
, ,
:
basic_interactive_step is
--
do
", "
" ( )"
end
, , :
from start until quit_has_been_requested_and_confirmed loop
basic_interactive_step
end
- ,
.
basic_interactive_step.
:
" "
" "
if " ( Undo)" then
" "
" "
elseif " Undo" then
if " " then
"Undo "
elseif " " then

elseif " " then


"Redo "
end
else
" "
end
, Undo Undo, Redo. Undo Redo
, .
, " " , ,
control-I ( , control-D ) .
, .

command, , :
requested: COMMAND
--,
, , .
:
" "
if " ( Undo)" then
" command requested"
-- requested
-- COMMAND, LINE_DELETION.
-- ( .)
else
requested.execute; undoing_mode := False
elseif " Undo" and requested /= Void then
if undoing_mode then
" Redo; "
else
requested.undo; undoing_mode := True
end
else
" : "
end
undoing_mode , Undo .
Undo Redo,
, ( 3.2); Redo
.
, ,
COMMAND, LINE_DELETION. , , ,
U3 : ,
.
- -
. requested : COMMAND
, LINE_INSERTION. requested.execute requested.undo
- : ,
, , , LINE_INSERTION, LINE_DELETION
, , requested .

.
, , , ,
, - - .
?
execute undo command,
. , execute LINE_DELETION
, , ,
, .

, ,
, .
- , CAD-CAM - . ,
, , ,
.
command
command. ,
" command requested",
, :
if " LINE INSERTION" then
create {LINE_INSERTION} requested.make (input_text, cursor_index)
elseif " LINE DELETION" then
create {LINE_DELETION} requested.make (current_line, line_index)
elseif
...
create {SOME_TYPE} x SOME_TYPE
x. SOME_TYPE x.
, requested COMMAND COMMAND.
unique,
inspect:
inspect
request_code
when Line_insertion then
create {LINE_INSERTION} requested.make (input_text, cursor_position)
..
,
. , ,
. .
.
, ;
.
.
.

: UNDO-REDO

.

? - COMMAND, requested.
, .
- requested,
, ,
. . ,
, (. 9
" - "),
. ,
.
requested ,
, - :
history: SOME_LIST [COMMAND]
SOME_LIST , - ,
SOME_LIST, ,

(Base library) . ,
, :

. 3.3.
Put - ( ).
, put .
Empty - .
Before, is_first is_last - .
Back, forth - , , .
Item - , . : (not empty)
and (not before), on_item.
( )
is_last . ,
before, . ,
.
. 3.3 , . ,
, , . , Undo Redo (
). (
Undo, Redo) . ,
, Redo.
, Skip (. 3.4).
, SOME_LIST - remove_all_right,
.
Undo , on_item.
Redo , ,
Redo, - : (not empty) and (not is_last),
not_last.
Undo
, Undo:
if on_item then
history.item.undo
history.back
else
message (" - undo")
end
. history
:

. 3.4. command
history.item
command. ,
history.item.undo undo.
Redo
Redo :
if not_last then
history.forth
history.item.redo
else
message (" - undo")
end
, COMMAND redo. , redo
- , execute. ,
. ,
, - redo COMMAND:
redo is
-- , ,
-- .
do
execute
end
COMMAND , (. 4
" - "). execute undo
redo. redo,
, .

- requested.
, , .
:
if not is_last then remove_all_right end
history.put (requested)
-- , put ,
--
requested.execute
.
.


, .

. , LINE_INSERTION .
COMMAND:

argument: ANY
set_argument (a: like argument) is
do argument := a end
- - argument, .
, .
, , .
. , COMMAND ISE
, , : argument,
execute :
execute (command_argument: ANY) is ...
,
. ,
,
, .
,
COMMAND - COMMAND_INSTANCE :
command_type: COMMAND
argument: ANY
.
, .
.
(. 3.4).

, .
" requested"
:
inspect
request_code
when Line_insertion then
create {LINE_INSERTION} requested.make (...)
.. ( )
, : , , .
if inspect, .
, .
,
(precomputing a polymorphic instance set).
- ,
, , ,
.
, , ARRAY
[COMMAND], 1 command_count . :
commands: ARRAY [COMMAND]
, i- (1 <= i <= n)
COMMAND, i; , LINE_DELETION,
, 1.

. 3.5.
associated_state, , .
commands . :
create commands.make (1, command_count)
create {LINE_INSERTION} requested.make; commands.put (requested, 1)
create {STRING_REPLACE} requested.make; commands.put (requested, 2)
... ...
, ;
, ,
li.make (input_text, cursor_position), li LINE_INSERTION.
if inspect.
.
" requested" :
requested := clone (commands @ code)
code . ,
, , " ",
.
requested (clone) ,
( ,
LINE_DELETION).
, , ,
( COMMAND_INSTANCE, COMMAND),
,
:
requested:= commands @ code
.

SOME_LIST, : put, empty, before,
is_first, is_last, back, forth, item remove_all_right. ( on_item,
empty before, not_last, empty is_last.)
SOME_LIST;
, TWO_WAY_LIST CIRCULAR_LIST.
BOUNDED_LIST.
, TWO_WAY_LIST, ,
. remembered .
, (

): ,
. 20.
BOUNDED_LIST ,
, remembered.
. :

. 3.6. ,
capacity remembered + 1;
( capacity),
. : oldest -
, next - ( ). index
.
. put(c), c , :
representation.put (x, next);
-- representation
next:= (next\\ remembered) + 1
index:= next
\\ . empty ,
next = oldest; is_first , index = oldest; before ,
(index\\ remembered) + 1 = oldest. forth :
index:= (index\\ remembered) + 1
back:
index:= ((index + remembered - 2) \\ remembered) + 1
+remembered , -
.
item - representation @ index, -
index. , remove_all_right, ,
:
next:= (index remembered) + 1


, , undo-redo.
ISE, .
Undo Redo, (history
window). history. ,
. :

. 3.7.
. , .
( ) , "change relation
label".
(Alt-U).
( - back) Undo,
, . 3.8.
:
Undo - .
Redo,

, forth.

. 3.8.
. , ,
, ;
remove_all_right; .

, , ,
.
, ,
.


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

, . : ,
! " " " "
, , ,
"". , ,
. -
- .
, .
, , , , . ,
, , , ,
.
, .
- : ,
. .
, .
, ,
. , , ,
, .
.
(. 10;),
. ,
.
, . ,
, , ,
, .

, ,
, . , , ,
. ,
, - .
- , ,
. -
, - ()
, - .
, , , COMMAND,
execute.
, ,
, . ,
, ,
, .
COMMAND ,
(execute and undo). , ,
, :
argument: ANY - (
);
help: STRING - ;
, .
.
. , f ,
. f , - ,

" " .
C, Fortran
. , ,
. , , - INTEGRABLE_FUNCTION -
.
item (a: REAL): REAL, a.
, , .


undo-redo, ,
Cepage, - 1982 [M 1982]
ISE ( ArchiText [ISE 1996], Cepage).
OOPSLA 1986 Larry Tesler , ,
Apple's MacApp.
[Dubois 1997] , ,
"Integrable function".

3.1 ( )

.
, ,
:
p: ;
: , ( l, );
:
i:
d:
u:

, ( h, );
.
;
, Undo; Undo, redo.

,
, . (, ,
.)
3.2 Redo

u:
u: , Undo Redo.
Redo:
r: , .
3.3 Undo-redo Pascal

, -, Pascal, Ada (
) C ( union ). -.
3.4 Undo, Skip Redo

, , , ,
, Undo, Skip Redo, ,
. ,
.
3.5

.
, .
3.6

,
. COMPOSITE_COMMAND,
COMMAND, ,
.
: , (. 15
" - ").
3.7

(" "),
, .
, .
, .
: UNDOABLE NON_UNDOABLE COMMAND.
3.8 ( )

,
undo-redo. ,
: , ,
. "Undo, Skip Redo".
, ,
, , .
3.9

, - ,
, , ,
. Unix, , C-shell,
. !-2, , ,
. ^yes^no^ " yes no".
.
, , . Unix
, C-shell, Vi ,
, .
,
.
, ,
, ,
. (, .)
USER_INTERFACE.
3.10

, , :
, , , .
, TEST, . (
, .)
3.11

( , .)
.
INTEGRABLE_FUNCTION, INTEGRATOR, ,
, RATIONAL_FIXED_INTEGRATOR.

-
4. :
- - ,
. . , . -
- .
, . ,
, .
- -
, ,
. , , , ,
,
,
. , "" (know -how ). , ,
. .
, .
, , . .
, , , , -
, , .
, - .

" "
, ,
.

, -
" " (, - , ). , . , . :
, (The elevator
will close its door before it moves to another floor)
- "move", : ELEVATOR, DOOR and FLOOR,
. ?!
, !
, " ".
,
.
, . ,
, , ,
,
. , ,
.
" " . -
ELEVATOR.
. ,
- .
,
, , .

,
" " - , ,
.
door , DOOR? ,
, - . ,
.

ELEVATOR:
door_open: BOOLEAN;
close_door is
...
ensure
not door_open
end;
open_door is
...
ensure
door_open
end
.
. , :
"door"
, , , ELEVATOR?
.
. ,
.
(. 3)
. commands operation, ,
Undo. , , COMMAND
- .
?
floor.
, , ,
FLOOR.
:
- ,
.
, , , , FLOOR.
, ,
, FLOOR :
rights: SET [AUTHORIZATION]
. . ,
:
floor_rights: ARRAY [SET [AUTHORIZATION]]
AUTHORIZATION , (.
4.1).
FLOOR
.
, .
INTEGER.
. ""
. - ,
.
- . -
, , ,
.
" " . ,
" ", - . ,
, ,

, . - ,
, , - (. 6
" - ") .
, ,
. PERSON , mother
father, , ,
.

, .

, ,
, . , ,
.
, " "
.
-
, -
.
. , :
,
(A database record must be created every time the elevator moves from one floor to another).
"record" DATABASE_RECORD;
: move, .
MOVE, , :
class MOVE feature
initial, final: FLOOR;
record (d: DATABASE) is ...
... ...
end

-- INTEGER, FLOOR

. ,
:
(A database record must be created
for every move of the elevator from one floor to another).
"move" ,
. , ,
, . , ,
, .
,
. .
, , , (.
2) (State, Application),
. ,
. :
. ,
, , : " " (the
system must support line insertion and deletion), ,
insertion deletion.
:
(The
editor must allow its users to insert or delete a line at the current cursor position).
,
: .

,
, .
, - (. 9)
, . ,
.
.
- ,
-
.
, , , ,
, ,
, . , ,
, .
COMMAND HISTORY_LOG , ,
. ,
.
("", ), - ,
. ,
, , ,
.

- , . ,
, , ,
. , ,
, , ,
.
( [Hadamard 1945])
.
: ,
.
. ,
, (rejecting) .
, .
(. 5).
- , ,
. , -,
, , , .
. , (
) . .
, .
, . "
?" : , ,
. , . , -
.

- : , .
.


.
, .
, - ,

, .
" ", " " -
, ,
.

, , ,
- , .
- , .
, .
, ,
(). class... feature ... end,
, , .
(Grand Mistake) , .
: , .
, , , ,
, ,
-.
...

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

, , PARSE ()
PRINT () - . ,
, , .
, , , . "
" :

:
c , ;
( , ).
, , ,
: .
- - .
, TREE, - LINKED_LIST,
, LINE_DELETION, .
- , , ,
, COMPARABLE, .
, ( ) ABLE.
, , , PLAYER
COMPARABLE.
(. 6).
, , ,
undo-redo, .

, : LINE_DELETION
WORD_CHANGE, DELETE_LINE REPLACE_WORD (_, _).
, , , , .
.
IMPORT , , .
, IMPORTATION.
: IMPORT - ", ",
, .
" ",
.
- , .
.

, ,
, , .
- , , -.
, ,
(. 3), , ,
. ,
, ,
. , ,
item, .
, .
, , , ,
.
: ,
, , . ,
,
, . , ,
(taxomania), (. 6).

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

. , ;
.
,
, , ,
.
, SAN_FRANCISCO HOUSTON
CITY, CITY
- .

, (
), (, ).

Pascal Cobol C. -
, , , ,
.
, ,
:
, , .
, ,
, , - .
-
.
(facility inheritance) (. 6).
, - , .
, , . ,
INTEGER, REAL DOUBLE -
, , x y, : x + y.
.
,
, .
. ,
- .
(checklist) (. 5).
. ,
, , ,
- . , ,
, Pascal Ada, .
.
, ,
, . , ,
. ,
, ,
. , , ,
.
ISE .
, .
. ,
.
CLASS_IDENTIFIER .
, .

,
.
NeXT .
, , , . - ,
, -
. : NSAttributedString,
, NSTextView, .
([Page-Jones 1995]) (connascence),
. ,
,
. , , ,
,
.
, "" :

, .

.
:
( ).
, .
- .
, .
.
. ,
, , .
, .
, ( ),
(),
().
, .
. ,
, - LIST QUEUE BUFFER, ACCOUNT, COMMAND, STATE, INTEGER, FIGURE,
POLYGON , - .


-
.

: , , .
, (, -
, LIST ),
.
, .
PLANE , PARAGRAPH
, PART .
, ,
, LINKED_LIST ARRAY.
. COMMAND
, , STATE , .
, ,
.
.
, ,
, . ,
, .
, .
:
, .
,
, .
, ,
, .
" ", ,
, - . , ,
, , , .
.

.
, ,
, . ,
.
(simulation). ,
- Simula 67 Simula 1 -
. Simula 67 ,
.
.
- - ,
,
.
.
, - ,
,
: , , , , , .
. ([Walden 1995])
B.O.N: ", , , ,
"
-
: SENIORITY_RULE , MARKET_TENDENCY
, SENATOR STOCK_EXCHANGE. -
, .
, , ,
. .
,
. , , , -
, ,
. ,
.
- -
, , , .

, ,
.
, , ,
, .
- . - .
, . ,
. " ", CS 2,
.
-, .
.
- CS
2.
, , ,
.
, ,
, ,
, . ,
- - - ,
.

.


( ) .
, ,
, - , .
, QUEUE,
.
" " - (oxymoron). , QUEUE, ,
,
.
([M 1993]) ""
, ,
, .

,
. : STATE, APPLICATION,
COMMAND, HISTORY_LIST, .
, ("handles").
, , ,
- , .
. ,
, . ,
"- " ([M 1993]) ,
.
, , , ,
, .
([Gamma 1995]) ,
.
"", ""
.
, , .
,
.


.

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

,
.
, ,
, -.
, ()
.

(. 10),
(variation inheritance), , ,
. ,
reuse-redo - .

, .
. ,
,
, 3 " - ", , ?
, , ,
, - ,
.
(. 2) , , - .
, ,
. , ,
, ,
, .
STATE, .
, . ,
, ,
.


. :
-, .
. , ,
, , .
,
, ,
.
,
.
Fortran (common blocks) - ,
.
. , Fortran ,
, ,
. , , -
"" , .
.
Pascal C , C .
. ,
.
Cobol (Data Division) .
, " -", ("entities")
.
(dataflow) , " " (stores) .

" " .
, .
Unix :

, : passwd , printcap
, termcap terminfo .
- ("
printcap , ,
" . .). ,
. -
.
, .
, , - Fortran -
-. , ,
, .
, , , . ,
, ,
. : ,
-,
.

([Jacobson 1992]) . ,
(scenario) ,
, ,
.
, ", ",
: ,
, .
.
:
. (.
7 " - ").
, .
: " a, b";
: " A,
?" - ,
, . , pop
push, ,
.
. .
.
. , ,
, .
, . ,
.
,
(). ,
. -,
. ,
, , ,
, . .
:

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

. , ,
. , , .
-
.
, ,
. [Jacobson 1992] ,
.
- -
.
. , ,
.
(CRC)
, .
(, , ) CRC (Class, Responsibility, Collaboration)
, ,
. , -
CASE . .


, -
. ,
.

, . ,
( case-)
, ,
. ,
, , ,
. .
, , (devising).

(finding) .

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

? ".


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

4.1.

,
.
, ,
.

.
, .
, ,
.
(
.)

.
.
, , "
", ,
.

( )
,

.
.
.

,
.
(Common
FORTRAN).
.
(COBOL).
(Pascal, C, C++).
ER-.

,
.

,
.

, , ,
.

4.2.

(
)

, .

, " "

, .
,
.

,
(
)

"".

,
.


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

.
,
.
Case-
,
.
.



[Booch 1986],
[Abbot ACM, 26, 1983]. [Wirfs-Brock 1990].
[M 1985a] ,
. ,
, : , ,
, , . ,
.
[Walden 1995] .
B [Page-Jones 1995] "" ,
, , .
[Ong 1993] -, Fortran
-. .
, , COMMON-.
Simula 1 [Dahl 1966]. Simula 17.
,
[Knuth 1981, Knuth 1973], [Aho 1974, Aho 1983].
[Gore 1996] -.

[Gamma 1995], ,
[M1994], " " "
". [Krief 1996] Smalltalk MVC.

4.1 Floors integers

FLOOR INTEGER, .
4.2

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

-
5. :
, .
: " ,
...", " , ?.." .
, .
- , ,
. , -
. ,
, , , ,
, , .
: , ,
(option), ,
, , , ? ,
, ,
, .
, , ,
. .
, Formula 1,
.
, - ,
.


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

. , .
, . ,
-
, - , .
.
, . - ,
.
, . , ,
(side effect). -
, , , .
?

, . , ,
: a := b, a = b, create a. a
, ,
.
, a ; a -
, ,
a - Result, , .
, , , -
. ,
obj.attr := b, obj.set_attr (b),
set_attr (x:...) attr := x (. 7 " ").
, ,
- , . :
:
, :

, , ;
.
"" .
" , () ".
, , .
, , :
,
, , .
: , ,
. ,
.
, f, g
. , f
. , , ,
,
.
,
. , , ,
,


?
.
, , ,
. (. 6 " "), ,
( |21/2| 2).
.
- Lisp ""
, , FP, ,
. .
,
(referential transparency) :
:
e -,
e.
x 3, x 3, , - .
( " " , -
, .) "
".
. ,
:
attr: INTEGER
sneaky: INTEGER is do attr := attr + 1 end
sneaky 0; 0 sneaky , :
attr := 0; if attr /= 0 then print (" !") end
, " !" 0 sneaky.
,
. .
([Dijkstra 1968]). (
), .
, . ,
, . , n + n
2* n, n , sneaky:

n: INTEGER is do attr := attr + 1; Result := attr end


attr , 2* n 2, n + n 3.

. , ,
, , , .
: " ".

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

. 5.1. list list-


,
- , ,
, . "", , .
, , ,
. ( ) , .
, ,
. :
, true, - false. ,
, (
).
, , . ,
.
list,
. start ( ),
forth ( ), search (
, ). item (
), index ( ). "",
, , , item index,
, .

,
? - ,
a, create a . - ,
. - create Result create
Result.make (...)? ,
.
, ,
,
. , ,
.
- make,
, .

, ,
, , .
, ,
C, .
- C- ( , C-
, , - ). ,
, x++, x, 1;
++x, x ;
: y = x++ y = x; x := x+1. .
. ,
, C . ,
, ,
, , -
. , , ,
, , .
.

,
.
,
. , , , .
. ,
remove, (
), item, . , - .
() pop,
. , , ,
.
. ,
getint, - C, .
, , :
getint (), ;
getint () + getint () 2 * getint () (
" " ,
, ).
, -
,
.
. , ,
, , ,
. input FILE; input
:
input.advance
n := input.last_integer

last_integer , getint, .
, , ,
.
, x++, -, ,
.
(, APL PERL).
, ,
( ), , .
,
. .
:
,
, .
:
random_seed (seed)
seed , .
:
xx := next_random ()
/. ,
. -?
, - :
?
" " " "
- , , , , .
, " ",
. , ,
, .
" " . ,
. - ,
. ,
, .
,
.
- , , , .
! ,
. :
: make - seed; forth -
;
: item - .

. 5.2.
rand create rand.make (seed),
- rand.forth, - xx := rand.item.
,

seed . start, (
make ),
COUNTABLE_SEQUENCE, .
, , , PRIMES -
COUNTABLE_SEQUENCE, . .
,
. -
, ( - start, forth, item) ,
. ,
.
COUNTABLE_SEQUENCE , PRIMES, ([M 1994])
.
,
, ,
. , ,
.
, .
, . ,
, . .
, .
, , , , .
, ,
:
max is
--
require
not empty
local
original_index: INTEGER
do
original_index := index
from
start; Result := item
until is_last loop
forth; Result := Result.max (item)
end
go (original_index)
end
, ,
, start, forth go, , ,
original_index, ,
go. ,
, .
,
.
, 11 " -
", , .
, ()
. ,
. count
count. ,
count.
a, c1

c2 a(c1) = a(c2).

, , , ,
. , , :
representation.put (some_value, count + 1)
( , , , count + 1).
, , .

, c,
, , , a(c) (
, , ).
- .
, ,
, . , , . ,
. .
- , "" , " ".
.
,
. .
, (, , ).
, - ,
. :
:
,
.
, - ,
.
"", . ,
"" () "" .
"" - - NONE, - ,
.

, , . ,
, -
. , , max
. ,
.
,
. .
- .
. ISE . , ,
C, , , .
- ,
, .

, , .
. ,
, .
. -
, , :
target.some_operation (...)
how_did_it_go := target.status
, .
, , , -
? , ;
, , ,
, , .
, , ,
. ( -
-, , , - - , ).
, get .

item, remove. ,
. get-
. - ,
. ,
, :
x := buffer.item; buffer.remove
, , ,
. , . ,
, :
buffer.remove; buffer.remove
, , .
(. 12) ,
,
, .
:
- ,
, , .
.
. , ,
- ( x y) ( r q).
? . , , , - ,
, - x, y, r q
( , -
).
, ,
, .
.
. , .
, x y,
.
, .
- , ,
, .
:
class COMPLEX feature
... :
infix "+", infix "-", infix "*", infix "/",
add, subtract, multiply, divide,
x, y, rho, theta, ...
end
x, y, rho theta , .
( theta 0). "+"
add . : z1 + z2 , z1.add (z2)
z1. .
() :
cartesian_ready: BOOLEAN
polar_ready: BOOLEAN
private_x, private_y, private_rho, private_theta: REAL
, .
, :
invariant
cartesian_ready or polar_ready
polar_ready implies (0 <= private_theta and private_theta <= Two_pi)
-- cartesian_ready implies (private_x and private_y )
-- polar_ready implies (private_rho and private_theta )

.
. ,
, , ,
.
.
:
prepare_cartesian is
--
do
if not cartesian_ready then
check polar_ready end
-- ,
--
private_x := private_rho * cos (private_theta)
private_y := private_rho * sin (private_theta)
cartesian_ready := True
-- cartesian_ready polar_ready true:
--
end
ensure
cartesian_ready
end
prepare_polar is
--
do
if not polar_ready then
check cartesian_ready end
private_rho := sqrt (private_x ^ 2 + private_y ^ 2)
private_theta := atan2 (private_y, private_x)
polar_ready := True
-- cartesian_ready polar_ready true:
--
end
ensure
polar_ready
end
cos, sin, sqrt atan2 , atan2(y, x)
arctangent(y/x).
- make_cartesian make_polar:
make_cartesian (a, b: REAL) is
-- : abscissa a, ordinate b
do
private_x := a; private_y := b
cartesian_ready := True; polar_ready := False
ensure
cartesian_ready; not polar_ready
end
make_polar.
, , , ,
:
add (other: COMPLEX) is
-- other
do
prepare_cartesian; polar_ready := False
private_x := x + other.x; private_y = y + other.y
ensure
x = old x + other.x; y = old y + other.y
cartesian_ready; not polar_ready
end
, x y, private_x private_y,
.
divide (z: COMPLEX) is
-- Divide by z.

require
z.rho /= 0
--
do
prepare_polar; cartesian_ready := False
private_rho := rho / other.rho
private_theta = (theta - other.theta) \\ Two_pi
-- \\ -
ensure
rho = old rho / other.rho
theta = (old theta - other.theta) \\ Two_pi
polar_ready; not cartesian_ready
end
- subtract multiply. (
.) :
infix "+" (other: COMPLEX): COMPLEX is
-- other
do
create Result.make_cartesian (x + other.x, y + other.y)
ensure
Result.x = x + other.x; Result.y = y + other.y
Result.cartesian_ready
end
infix "/" (z: COMPLEX): COMPLEX is
-- z
require
z.rho /= 0
do
create Result.make_polar (rho / other.rho, (theta - other.theta) \\ Two_pi)
ensure
Result.rho = rho / other.rho
Result.theta = (old theta - other.theta) \\ Two_pi
Result.polar_ready
end
infix "-" infix "**".
- cartesian_ready polar_ready
, feature {COMPLEX};
.
? . x, y, rho
theta - . x y
( prepare_cartesian), .
rho theta. x theta:
x: REAL is
-- Abscissa
do
prepare_cartesian; Result := private_x
end
theta: REAL is
-- Angle
do
prepare_polar; Result := private_theta
end
y rho . , .
add , , ,
. , x cartesian_ready,
( ) . ,
, .
: z.x ,
z, c1 c2 , ,
a(c1 ) = a(c2 )
a - . c1 c2 ,
- .

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

?
, , ,
. ,
, ,
.

, .
. , ,
, :
. , .
. ,
, , ,
.
.
, .
, (,
-!).
nonlinear_ode
(equation_count: in INTEGER;
epsilon: in out DOUBLE;
func: procedure
(eq_count: INTEGER; a: DOUBLE; eps: DOUBLE;
b: ARRAY [DOUBLE]; cm: pointer Libtype)
left_count, coupled_count: in INTEGER;
...)
[ . 19 , :
- 4 in out ;
- 3 , ;
- 6 , 6 - 7 ,
2 3 !]
,
, , .
:
in out,
. , epsilon ,
(, 0, 0 1, ,
epsilon < vprecision . .). .
, , , ,
.
(
, , ...)
,
, . ,
, nonlinear_ode, .
, , . . - Math ([Dubois 1997]) - ,
. ,
- . , ,
, . nonlinear_ode
:
solve
-- , x y
! GENERAL_BOUNDARY_VALUE_PROBLEM,

, , , .
, , .
solve . x y .
, - . ,
ISE, , 0,4
Base 0,7 Vision. -
, x.f (a, b)
- f (x, a, b). ,
, , 19 5, 10
15.
, , .
, .
()
: .
DOCUMENT print. -
, - Postscript.
, . :
my_document.print (printer_name, paper_size, color_or_not,
postscript_level, print_resolution)
? , , Postscript ,
, , .
:
:
, , .
, .
. :

, , ,
.
,
.
print . , , my_document, , . ,
, .
, , ,
, . -
. , . - ,
, . ,
, . , ,
. .

:

, .
, , .
, , ,
, :
my_document.set_printing_size ("A4")

my_document.set_color
my_document.print

--

, , .

, .
, Boolean, , ,
, set_printing_size.
set_property_name. ,
. , , , , print,
set_printing_size.
, - True or
False. , , True,
set_property_name set_no_property_name,
, set_color set_no_color,
set_black_and_white.
:
, .
, , .
, ,
.
, , -.
, ,
.
, .
. ,
: . .
, , .
, .
, .
, ,
. , , ,
,
.
,
, ,
. , ,
. ,
. , ,
.
. ( ISE.)
, , ,
. solve Math. , ,
19 .
?
. , ,
.
-, .
, create x.make_specific (argument, ...),
make_specific - . ,
, , .
:
, , , ;
( make
),
.
. ,
, , :

my_document.set_printing_size ("...")
my_document.set_printer_name ("...")
my_document.print
,
, , :
print_with_size_and_printer (printer_name: STRING; size: SIZE_SPECIFICATION)
, , (print )
, ,
.
,
, , .

, , ,
. ,
. DOCUMENT ,
:

5.1.
Option
Initialized
Queried
Set
set_size
Paper size default:A4 (international) size
make_LTR: LTR (US)

set_LTR
set_A4

: ,
, , .
:
Initialized , . (, ,
, Black_and_white_only
false.)
Queried . , , ,
, . ,
.
Set .
, , . ,
, .
.

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

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

(immediate) - ,
, - (flat) , . ,
, ,
, ,
(incremental) ?
. . , ,
, .
, . ,
, , .

, ([Johnson 1995]) :
.
,
. , .
ISE . , .
( ),
( 60 80 , ), ,
.
, (shopping list).
, . ,
, . , ,
- . :
:
:
S1 , .
S2 .
S3 .
S4 .
(. 4), ,
.
string NEXTSTEP, , ,
, . , .
, - string - ISE,
- .
, - . , ,
, - ,
,
.
STRING , .
. ([Walden 1995]):
, , 100 ,
, <...>
,
.
.
, , , .
, ,
- .
, -, (behavior classes),
,
.
, .
COMPLEX, , .
:
infix "+", infix "-", infix "*", infix "/"

z1 + z2 , z1 z2,
. , ,
z1.add(z2) z1. ,
. : ,
, .

, ,
. , , , ,
S3 . ,
. :
,
. .
, , - S3.
obsolete,
.
, .
, , - ,
, . ,
obsolete.
,
. ISE ,
, :
my_array.item (some_index) my_array @ some_index.
. . , ,
.
, . ,
, . ,
. , ,
,
.
,
. -
- .
, , .
, .
.
, . ,
.
, , ,
, .
: " n m ", -
.
, :
, , .


,
" ", , .
.
.

. ,
, .
- .
LINKED_LIST.
, , , -
.

. ,
(linkables). :

. 5.3. - (linkable)
(: , ),
. , item,
G - . ,
, , , . right
LINKABLE[G] .
- , first_element , ,
, , count - .
:

. 5.4. (linked list)


, ,
. ,
:

. 5.5.
, ,
, . , ,
(), .
, .
, ,
.
: LINKED_LIST first_element,
. first_element, count.
, .
, .
- , .

, : LINKED_LIST ( , ), LINKABLE
- . .
LINKABLE , .
, ,
. , ,

:
indexing
description: ", "
note: " , "
class
LINKABLE1 [G]
feature {LINKED_LIST}
item: G
--
right: LINKABLE [G]
--
end
right like Current,
, , LINKABLE.
.
? item right. ,
, . :
indexing
description: ", "
class LINKABLE [G] creation
make
feature {LINKED_LIST}
item: G
--
right: LINKABLE [G]
--
make (initial: G) is
-- item initial
do put (initial) end
put (new: G) is
-- new
do item := new end
put_right (other: LINKABLE [G]) is
-- other
do right := other end
end
( ensure item = initial make).
.
, LINKABLE. , .
: (count), (empty),
i(item), (put),
i- (replace), (occurrence).
, (void, ), .
. .
indexing
description: " "
note: " , "
class
LINKED_LIST1 [G]
feature -- Access
count: G
empty: BOOLEAN is
-- ?
do
Result := (count = 0)
ensure
empty_if_no_element: Result = (count = 0)
end
item (i: INTEGER): G is
-- i-
require
1 <= i; i <= count
local
elem: LINKABLE [G]; j: INTEGER
do

from
j := 1; elem := first_element
invariant j <= i; elem /= Void variant i - j until
j = i
loop
j := j + 1; elem := elem.right
end
Result := elem.item
end
occurrence (v: G): INTEGER is
-- v (0, )
do ... end
feature -- Element change
put (v: G; i: INTEGER) is
-- v,
-- i-
require
1 <= i; i <= count + 1
local
previous, new: LINKABLE [G]; j: INTEGER
do
--
create new.make (v)
if i = 1 then
--
new.put (first_element); first_element := new
else
from
j := 1; previous := first_element
invariant
j >= 1; j <= i - 1; previous /= Void
-- previous - j-
variant
i - j - 1
until j = i - 1 loop
j := j + 1; previous := previous.right
end
previous
previous.put_right (new)
new.put_right (previous.right)
end
count := count + 1
ensure
one_more: count = old count + 1
not_empty: not empty
inserted: item (i) = v
-- For 1 <= j < i,
-- j
-- For i < j <= count,
-- j
-- , j - 1
--
end
replace (i: INTEGER; v: G) is
-- v i-
require
1 <= i; i <= count
do
...
ensure
replaced: item (i) = v
end
feature -- Removal
prune (i: INTEGER) is
-- i-
require
1 <= i; i <= count
do
...
ensure
one_less: count = old count - 1
end

... ...
feature {LINKED_LIST} -- Implementation
first_element: LINKABLE [G]
invariant
empty_definition: empty = (count = 0)
empty_iff_no_first_element: empty = (first_element = Void)
end

occurrence, replace prune .


, .

.
LINKED_LIST1 , -
, .
( put ),
, -.
; count empty
, .
.
put , - .
.

LINKED_LIST1? .
- : item put .
, (occurrence, replace, remove).
. .
, - .
- .
occurrence. , , 0
. , . ,
? . , ,
.
!
, .
,
, .
,
? :
occurrence , LINKABLE,
, void .
. (, put LINKABLE
; .)
, :
, .
, , , -

, . ,
, ,
. .
ISE.
search :
insert_before_by_value (v: G; v1: G) is
-- v
-- v1 ,
--
do
...
end
, .
, . :
search_and_replace, insert_before_by_value, insert_ after_by_value, insert_after_by_position,
insert_after_by_position, delete_before_by_value, insert_at_ end_if_absent .
. ,
, , . ,
, , . 5.6.
, ,
. . ,
, .5.6.

. 5.6.

, . , , .
.
, , "" .
,
, , .
, , put and remove; ,
, , .
,
.

. 5.7.
, , ,
- before true, - after
true.
, , search, occurrence.
l.search(v) v ,
after, . , ,
, - , .
search_back.
:
start finish, , ;
forth back, ;
go(i), i.
before after index, ,
1 , is_first is_last.
- , , - ,
, , . ! ,
remove l.remove (i), l.remove.
, :
Remove, , ,
index .
Put_right (v: G) v , ,
index .
Put_left (v: G) v , ,
index .
Replace (v: G) .
item, , .
:
.
. . :
start , ; , ?
remove, ?
, .
, .
.
, , ,
. , , - .
:
0 <= index; index <= count + 1
? . ,
, , , before

after . , : if after and not


empty.
- (sentinel), .

. 5.8.
, .
, ,
, , .
, - .
:
on_item (i: INTEGER): BOOLEAN is
-- i?
do
Result := ((i >= 1) and (i <= count))
ensure
within_bounds: Result = ((i >= 1) and (i <= count))
no_elements_if_empty: Result implies (not empty)
end
, , readable,
on_item (index). ,
readable , ,
, ,
.
: not (after and before).
:

. 5.9.
, : empty and before empty and after,
. ,
empty = (before and after), empty
implies (before or after).
: , ,
, , . ,
:
0 <= index; index <= count + 1
before = (index = 0); after = (index = count + 1)
is_first = ((not empty) and (index = 1));
is_last = ((not empty) and (index = count))
empty = (count = 0)

-- ,
-- :
empty implies (before or after)
not (before and after)
empty implies ((not is_first) and (not is_last))
, -
.
, , .
(. 5.6).
, , ,
. (. 6 " - "), ,
, , .
, .
, ,
, .
. .

. , ",
", , :
l: LINKED_LIST [INTEGER]; m, n: INTEGER
...
l.search (m)
if not after then l.put_right (n) end
search (m) m after,
. ( , , ,
l.start.)
:
l.start; l.search (m); l.search (m); l.search (m)
if not after then l.remove end
i:
l.go (i); l.put_left (i)
. , ,
.

, . ,
, .
, .
.
(back, forth, go, search), (go search).

. 5.10. ( )
first_element
active - previous.
.
, , count index
: before, after, is_first, is_last, item. :
after: BOOLEAN is
-- ?
do Result := (index = count + 1) end
is_first: BOOLEAN is
-- ?
do Result := (index = 1) end
( before is_last.) after "
?" , after ,
. , ; (. 8).
item , :
item: G is
--
require
readable: readable
do
Result := active.item
end
, readable , (index 1 count).
, item active.item LINKABLE, LINKED_LIST.
. ,
, - start, forth, put_right, put_left remove, . start forth. start
, . , start
.
start1 is
-- .
-- ( .)
do
index := 1
previous := Void
active := first_element
ensure
moved_to_first: index = 1
empty_convention: empty implies after
end
forth1 is
-- .
-- ( .)
require
not_after: not after
do
index := index + 1
if before then
active := first_element; previous := Void
else
check active /= Void end
previous := active; active := active.right
end
ensure
moved_by_one: index = old index + 1
end

! . forth
, from start until after loop
...; forth end. ?
, .
( make LINKED_LIST .) first_element
zeroth_element :

. 5.11. ( )
zeroth_element /= Void previous /= Void (, ,
, ). ,
.
forth, start, ( !):
start is
--
do
index := 1
previous := zeroth_element
active := previous.right
ensure
moved_to_first: index = 1
empty_convention: empty implies after
previous_is_zeroth: previous = zeroth_element
end
forth is
-- .
-- ( . !)
require
not_after: not after
do
index := index + 1

previous := active
active := active.right
ensure
moved_by_one: index = old index + 1
end

go_before, :
go_before is
-- before
do
index := 0
previous := zeroth_element
active := zeroth_element
ensure
before: before
previous_is_zeroth: previous = zeroth_element
previous_is_active: active = previous
end

go go_before forth:
go (i: INTEGER) is
-- i-
require
not_offleft: i >= 0
not_offright: i <= count + 1
do
from
if i < index then go_before end
invariant index <= i variant i - index until index = i loop
forth
end
ensure
moved_there: index = i
end
. go, , .
finish, , go
(count + 1).
, ( ) go_before.

go_after, go (count + 1), .


back, , go:
back is
--
require
not_before: not before
do
check index - 1 >= 0 end
go (index - 1)
ensure
index = old index - 1
end
back forth, ,
back, , , index - 1 forth.
, ,
,
. LINKED_LIST (
, ).
(. 5.7). ,
.
. ,
:
empty = (zeroth_element.right = Void)
zeroth_element /= Void; previous /= Void
(active = Void) = after; (active = previous) = before
(not before) implies (previous.right = active)
(previous = zeroth_element) = (before or is_first)
is_last = ((active /= Void) and then (active.right = Void))
- before (index = 0)
after - (index = count + 1). :
item: G is
--
require
readable: readable
do
Result := active.item
end
search go . i_th (i: INTEGER),
i. ,
.
:
remove is
-- .
-- ( , after).
require
readable: readable
do
active := active.right
previous.put_right (active)
count := count - 1
ensure
same_index: index = old index
one_less_element: count = old count - 1
empty_implies_after: empty implies after
end

, ,
previous /= Void first_element /= Void.
, . : !
active := active.right
if previous /= Void then previou.sput_right (active) end
count := count - 1
if count = 0 then
first_element := Void
elseif index = 1 then
first_element := active
-- first_element
end
. ,
put_left put_right.

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

. ,
previous, active index, . CURSOR, ,
. ,
(zeroth_element, count), , , .
, .
,
.

( .)
,
ISE. ,
. , ,
. , .
?
, , ,
forth :
index := index + 1
previous := active
active := active.right

. , , active Void,
after. (active = Void) =
after; , - , active, .
, forth, . forth, , -
, " " , . -
:
from your_list.start until your_list.after loop ...; your_list.forth end
, , , , ,
forth. ,
, .
, , , -
, .
, . :
, , ,
BI_LINKABLE , . TWO_WAY_LIST
(, , LINKED_LIST,
) , .
(. 15 " - ")
. TWO_WAY_TREE,
( ). ,
, ,
TWO_WAY_LIST BI_LINKABLE. ,
.
- -
.
.

. 5.12.
, ?
, .
- .
, ,
, , .
? , . , LINKABLE -
item right. , , ,
, , first_element
. , , , first_element void
, if before then ...
. , ,

. 5.13. ( )
, , zeroth_element
. , zeroth_element.right,

first_element.

. 5.14. ( )
first_element . , first_element
void - , .
.
:
previous /= Void
(active = Void) = after; (active = previous) = before
(not before) implies (previous.right = active)
is_last = ((active /= Void) and then (active.right = Void))
, zeroth_element:
zeroth_element /= Void
empty = (zeroth_element.right = Void)
(previous = zeroth_element) = (before or is_first)
:
first_element /= Void
empty = (first_element = Current)
(previous = Current) = (before or is_first)
, ( , )
LINKED_LIST LINKABLE:
class LINKED_LIST [G] inherit
LINKABLE [G]
rename right as first_element, put_right as set_first_element end
... zeroth_element...
- LINKED_LIST LINKABLE? ! ,
,
. "is-a" ("") .
LINKED_LIST LINKABLE, . ,
" " - , ,
!
, , - ,
. BI_LINKABLE LINKABLE. TWO_WAY_LIST
LINKED_LIST ( , , ) ,
, BI_LINKABLE. ,
- . ,
, .
- TWO_WAY_TREE, TWO_WAY_LIST BI_LINKABLE.
, -
. , , ,
forth, back , ,
.
Base. ,
:
,
, , .
, .
(. 15 " "). , ,
,
,
.
: , ,
, .

. ,
. ,
.


LINKABLE LINKED_LIST
- ( ) ().
LINKABLE - item, right, make, put, put_right - ,
,
. , LINKED_LIST,
, active.right, forth LINKED_LIST,
.
, LINKABLE ,
:
class
LINKABLE [G]
feature {LINKED_LIST}
item: G
right: LINKABLE [G]
-- ..
end
, LINKED_LIST,
, .
, , .
, BI_LINKABLE, LINKABLE, left,
:
(left /= Void) implies (left.right = Current)
, right feature {... ..., BI_LINKABLE};
left.right .
, , LINKABLE
LINKED_LIST, ,
.
: ,
-.


,
: , , ?
- , ,
, -
. -
.
.
, ,
, .
. Ada, , :
if some_abnormal_situation_detected then
raise some_exception;
end;
" - "
raise "
", , . , ,
. ,
: ? , , ,
? , , ?
12 " - ",
-,

. .
, , , ,
" " ("low-tech").
. ,
.

, , . ,
, .
11 " - ",
. , , , ,
. , - .
, .
, , .
operation (x:...) is
require
precondition (x)
do
... , ...
end
, , ,
. . -
:
if precondition (y) then
operation (y)
else
... ...
end
( , , ,
: z.operation (y).) if...then...else, ,
:
... , , , ...
check precondition (y) end
operation (y)
check, :
, , ,
, . (
check, 11 " - ".)
, - ,
, - :
.

- , , .
:
A1 .
A2 ,
.
A3 ,
.
1 . ,
a x = b, a - , x b - ,
MATRIX:
inverse (b: VECTOR): VECTOR
: x := a.inverse(b). ,
"". ( ,

0 .)
inverse, , :
if a.singular then
... ...
else
x := a.inverse (b)
end
, , , ,
, . -
.
A2 ,
, , .
. , ,
1 - , ,
.
, A3 , ,
- , .

, . ,
, , . ,
.
- .
:
a.invert (b)
if a.inverted then
x := a.inverse
else
... ...
end
inverse invert, attempt_to_invert.
inverted, ,
. inverse. (
: inverted = (inverse /= Void).)
, , ,
, , , .
(. 18 " ").
, . , "read"
, - ,
, , .
, , . ,
, .
() , .
, .
, . ,
, "next integer", "next
string", . ,
.
, , , .
, " ": ,
.

, ,
. ,
.
, , , . :

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

.
. , ,
- , , , .
, ( ) . ,
, , , ,
? , :
: ,
.
(upward compatibility). ,
, (, ).
Unix Make
,
. ,
, , .
, Make Bell
Laboratories.
: ,
, .
- - .
(obsolete features) (obsolete classes). :
enter (i: INTEGER; v: G) is
obsolete " put (value, index)"
require
correct_index (i)
do
put (v, i)
ensure
entry (i) = v
end
, . Base
( , 8,
). put enter item entry , ,
.
. , enter
, put. ,

.
, ? .
,
. , , , ,
obsolete, " put (value, index)" . . ,
, .
.
. , ,
, . , ,
, ,
. , .

. ( )
.
. enter entry
. , .
. ,
,
. ,
. - ,
, , .
, : ,
, ,
. -
, .


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

, ,
:
, (, ,
);
, do...
, , , - , ,
.
, , .
, . ,
, .
, , Ada, Modula-2 and
Java, .
. ,
. ,
.
, ,
. .
, , , .
,
:

, , ,
.
,
. , :
, ;
, ;
.
8, , .

short flat-short, (,
, , ,
) .
- . ,
, . ,
.
Case ISE, BON (Business Object Notation),
. .5.15 , - (reverse-engineering)
Base.
(. [M 1995c]), ,
, ,
(),
.

. 5.15.
, ,
.
.


,
.
.

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

.
,
, .
, - ,
.


([Parnas 1972], [Parnas 1972a]) .
[M1982a].

, . ,
, , . , ,
, ,
, . [Liskov 1981], [Liskov
1986] , CLU.
,
[M 1994a].
[M1979], Simula.
(Literate programming) [Knuth 1984] , ,
. , ,
. .
- [Bielak 1993], [McKim 1992a]
, .

5.1

(. 9 " -
") fresh, remove ,
, . , .
5.2

,
- .
5.3

, Ada, ,
. , . ,
, .
5.4

LINKED_LIST [G] , count , ,


.
5.5

search (x: G) LINKED_LIST, x.


5.6

LINKED_LIST,
(. 5).
5.7

, LINKED_LIST,
, back, go finish.
5.8

, ,
after before. ( .)
.
5.9

remove, put_left put_right


.
5.10

, LINKED_LIST . (: ,
.) CIRCULAR_LINKED, .
5.11 ,

, .
do,
.
5.12

, , ,
. ,
.
5.13

, ,
. " "
, .
. , ,
.

-
6. :
7-18 " -
" . -
, .
, . ,
, , , -
, . , , - ,
. , ,
. ,
( ), - .
, .


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

( [M1988]).
"", .
:

(, !)
, .
(, .) :
, CAR, , PERSON,
.
( ?)
CAR-OWNER, CAR PERSON.
( .) CAR-OWNER ,
. , , .
, , , ,
(is) , (has) .

. 6.1.
:
class CAR_OWNER inherit
PERSON

feature
my_car: CAR
...
end
.
, :
,
.
, - , , ,
. , , ,
, .

. 6.2. ( )
,
, -
:
: "Is-a" ()
B A, , B
A.
, , B is an A ( : "is-a").
, , , :
" ". , B
A. . ,
" " (savings account) " " (checking account)?
- . ,
SAVINGS_ ACCOUNT BANK_ACCOUNT -
. . , ,
, . : ,
, CAR_OWNER CAR, .
, "", . , ,
- , .
, "Is-a".
, .
- , , ,
.


- : , . ?
(To have and to be)
, , .
, - .
- :
, , .
?
:
- .

[A]

, . , - - ,
, . :
- . [B]
:
- . [C]
- , [C] [A]! :
, .
, :

. 6.3. "-"
SOFTWARE_ENGINEER -.
, :

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

, , - .
"" "",
. , ,
, .
, ,
. " B A" " B
A". , -
. , .
. B A ( , )
- .
,
. , . ,
:

. 6.5.
class SOFTWARE_ENGINEER_1 inherit

ENGINEER
feature
...
end

:
class SOFTWARE_ENGINEER_2 feature
the_engineer_in_me: ENGINEER
...
end
:
class SOFTWARE_ENGINEER_3 feature
the_truly_important_part_of_me: VOCATION
...
end

ENGINEER VOCATION.
, . ,
, "software
engineer" "engineer", .6.4. , ,
.
, , ,
: .
: "software engineer"
( the_engineer_in_me the_truly_important_part_of_me).
SOFTWARE_ENGINEER_2 ENGINEER ;
SOFTWARE_ENGINEER_3 , VOCATION ().
-, ,
, . (" .
- . ".)
:

, "",
.

.
, .
.
SOFTWARE_ENGINEER_3. SOFTWARE_ENGINEER_2
, . SOFTWARE_ENGINEER_3
VOCATION , , , (
) , VOCATION.
, , ,
. ,
(handle).

, . :
. , :
x: C
x (, C ) .
, x C, C.
-, - -
, LIST [C],
C.
, , SOFTWARE_ENGINEER_1 - ,
ENGINEER, :
eng: ENGINEER
SOFTWARE_ENGINEER_1.
, , -, - .
: , , ,
, .
, , "a software engineer",
SOFTWARE_ENGINEER_1.
: SOFTWARE_ENGINEER_2 SOFTWARE_ENGINEER_3
ENGINEER "software engineer".
, , ,
:

, "",
.

, ,
.

, B A, :
CI1 B A,
, B A.
CI2 , A B ,
A, B, B A.

:
, .
- (handles).
Vision - ,

.
: , , - , ,
, , .
class WINDOW inherit
GENERAL_WINDOW
PLATFORM_WINDOW
feature
...
end
GENERAL_WINDOW , GENERAL_BUTTON, : ,

. , PLATFORM_WINDOW, ,
Windows, OS/2 Presentation-Manager Unix Motif; ,
( , WEL MEL).
, WINDOW, ,
GENERAL_WINDOW , PLATFORM_WINDOW.
PLATFORM_WINDOW ( ) -
. ; Ace
.
, , WINDOW
. , : , Motif,
. , , ,
, Unix OS/2.
- , Postscript HTML;
, , Web-.
GUI- ,
. WINDOW GENERAL_WINDOW,
TOOLKIT,
. , . 6.6:

. 6.6.
, (toolkit) ,
TOOLKIT. , MOTIF
MS_WINDOWS TOOLKIT.
. , , WINDOW, ,

:
handle: TOOLKIT
. :
set_handle (new: TOOLKIT) is
-- new
do
handle := new
end
, GENERAL_WINDOW ,
:
display is
--
do
handle.window_display (Current)
end
, . ,
window_display, TOOLKIT , ,
MOTIF.
, , , : "! ,
, ".
, , , .
, , .
TOOLKIT, handle ,
window_display, . ,
.
, .
Vision Store,
SQL , Oracle, Ingres, Sybase ODBC.

, , -
( ) , ,
. , .
, ,
:
( )
, ,
.
, , -, -
( , "
"). .
, , .
.
, - . , . ,
, .
, ,
, .
,
( (restriction inheritance) - ).
: ,
, ,
. , ,
. ,
.
. , PERSON,
- MALE FEMALE. ? .
, , ,

, .
, , ,
, , PERSON :
female: BOOLEAN

Female: INTEGER is unique


Male: INTEGER is unique
, , , ,
.
, .
, unique,
:
if female then
...
else
...
inspect . , , :
,
, , .
if ,
this_person.some_operation, MALE FEMALE -
some_operation. , ,
- . ,
.
. ,
, (
). , ,
?
FEMALE_EMPLOYEE, ,
. (multi-criteria classification),
.

:
- . , ,
. , ,
,
.
:
(subtype inheritance);
(view inheritance);
(restriction inheritance);
(extension inheritance);
(functional variation inheritance);
(type variation inheritance);
(reification inheritance);
(structure inheritance);
(implementation inheritance);
(facility inheritance) :
( ) (constant inheritance machine inheritance).
(, , , , ) ,
.

, , , " ".
,
. , , CAR_OWNER.
:


.
, , ,
, .
, . ,
. ( )
. ,
[Girod 1991]. ,
. , ,
, , , ,
. ,
.
- ,
. ,
, ,
.
, .
.

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

, . - ,
,
.
"has" "is". CAR_OWNER , . ,
APPLE_PIE, APPLE PIE, ( Adele Goldberg) ROSE_TREE, ROSE
TREE.
, , (
, ),
, , .
(convenience inheritance),
,
. , " " " "
, . ,
is-a ,
.

.
, :

. 6.7.
, ,
. :
, "is-a" , ;
, ,
;
- , , ,
.
, .
, ,
. 6.2.
A B :

. 6.8.
, A B , - .
,

.

.
,
. , .
:
:
, A B A' B' ,
B' A', , , A,
B'. A .
A' , B' - , A B - .
" " , ,
( )
( ).
,
.
(

).

, A ,
, B , .
, A .
,
, .
c
: c
c , B A,
, , , B, A.
, B, . A B
.
:

: 1 = 2 ( ).
.
,
, .
,
. , CIRCLE radius,
ELLIPSE.
A, B,
, .
;
(subtyping) .

:
, B , A
A. A .
- () - .
, ,
( ) . .
, .

( ) (
) " " . :
class A feature a1: INTEGER end
class B inherit
A
feature
b1: REAL
end
A ( <n>, n
), B - , (, <1, -2.5>).
MB MA. , "
" , -- MA
, .
, " " ,
. , - ( ISE) RECTANGLE
SQUARE, . : SQUARE side;
RECTANGLE , other_side. ,
.
. ,
.
. ,
. , +, . ,
+ . , , *,
. .
-. , SQUARE
RECTANGLE, , . MOVING_POINT (
) POINT speed,
. , CHAPTER
DOCUMENT, - .

( - .)
, ( , MB
MA), ,
. , ,
. :
class C
c1:
c2:
c3:
end

feature
T1
T2
T3

C' - C -
T'1 _ T'2 _ T'3, ' ,
( ).
, ,
ATTRIBUTE VALUE, :
A1 c1, c2 c3.
A2 VALUE ( ) T'1
A3 c1 T'1 .

T'2

T'3.

, ,
(, A {<a1, 25>},
B - {<a1, 1>, <b1, -2.5>}), - B'
A'. ,
.
, A1 " ...",
" ...", {c1, c2 c3},
. ,
.

.
[M 1990].

( - , !) -
.
:
, B A; A B
, . B ,
. :
: , .
: .
, A, ,
, , ,
, .
, ( ) .
, .
" ",
.
,
.
.
( ).
. , ,
.
MALE_EMPLOYEE FEMALE_EMPLOYEE.
,
(like...) . , SEGMENT :
perpendicular: SEGMENT is
-- , 90
...
DOTTED_SEGMENT, ,
. perpendicular DOTTED_SEGMENT,
. ,
like Current. , ,
, .
(, - ),
-.
. ,
, , . ,
, . , ,
, .
, , ,
.
-:
, ( )
. , , ,
. ,
. ,
,
A, B .

:
, B
A, .

.
, B A (
, A , B ,
, ). .
:
, .
, ,
( ), .
, ,
.
,
. .
- ,
. , -
.
.
B ; A ,
.

- .
:
, A , B
. A ; B ,
.
, , TABLE,
. SEQUENTIAL_ TABLE HASH_TABLE,
. SEQUENTIAL_TABLE ARRAYED_TABLE,
LINKED_TABLE, FILE_TABLE.
"" (reification), , ,
" ". VDM.

:
, A, , , B,
, ,
.
A , . ,
A COMPARABLE, , infix "<" infix ">=",
. , ,
STRING, COMPARABLE.
. , INTEGER
Kernel COMPARABLE NUMERIC ( , infix "+" infix
"*"), . ( NUMERIC
.)
? B
, A, ; B
, A ,
.
, , ,
"is" "car-owner" (AIRPLANE
VENTILATION_SYSTEM). , ,
:
, ,
, . AIRPLANE COMPARABLE,
, VENTILATION_SYSTEM
. stop VENTILATION_SYSTEM .

: AIRPLANE ,
VENTILATION_SYSTEM.

:
, B A (
), , B. A, B
.
. "
", ,
( ), - ( ).
.

, ,
.
:
, A
, , B. :
, A ,
.
, A ,
.
EXCEPTIONS, , ,
.
, , , , , EXCEPTIONS,
( Incorrect_inspect_value), (
trigger ).
,
.
A, B .
, B , , A.
.

, ,
. ""
. , *, .

6.1.

*
*
*
*

*
*

, ?
, ,
(. 14 " - ").
, ,
, ,
. , ,
, ,
.
, . .
-, ,
. ,
.
: ,
, LINEAR_ITERATOR;
? .
.
6.8 , ,
.
, .
,
:
( RECTANGLE, perimeter
POLYGON) ( -
, -).
. (.
[Breu 1995]) .
, .
STATE_INSTITUTIONS
LOUISIANA_INSTITUTIONS, ,
counties, ,
parishes - , .
. ,
,
select .
- , .
.
, ? ,
, , , ,
- , .
- .
,
. goto.
, , ,
. ,
, , "" , ,
.
, , ,
- ,
. 17 " ", ,
, .

,
- :
. , ,
.


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

,
: ,
.
. ,
, , , .

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

CLOSED_FIGURE

DEVICE

FILE

SHIP

QUADRANGLE

RECTANGLE

SQUARE

TEXT_FILE

LEISURE_SHIP

ACCOUNT

POLYGON

SAILBOAT

SAVINGS_ACCOUNT

FIXED_RATE_ACCOUNT

, ,
, , .
, , ,
, , , .
,
. .
, RECTANGLE
SQUARE, ,
.

,
. . , ,
:
, , TRIANGLE, QUADRANGLE etc.,
(EQUILATERAL_POLYGON, SQUARE . .) ?
. ,
.

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

.
. , ,
, . :
ARRAYED_STACK, ARRAY, , , ,
ARRAY .
ARRAY ( ,
, ,
).
: ,
, .
, : B f A, f B
, A. ( f ,
.)

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

, , ,
. .
,
.
ELLIPSE. , :

. 6.9.
ELLIPSE focus_line.
, CIRCLE ELLIPSE: .
- , . (,
, , ,
, .)

. 6.10.
? CIRCLE focus_line ,
:
class CIRCLE inherit
ELLIPSE
export {NONE} focus_line end
...
, .
, . , ,
:
focus_line is
-- ,
require
not equal (focus_1, focus_2)
do
...
end
( , distinct_focuses; ,
CIRCLE .)
.
focus_line, , .
. -,
, .

, ,
, , .
.
, ,
.
MORTGAGE ().
, , ,
. , - . MORTGAGE
redeem ( ), ,
.
, ( )
, ,
. NEW_MORTGAGE; redeem?
, focus_line. ,
, ? , , redeem
.
MORTGAGE .
, , ,
redeemable redeem:
require
redeemable
.
. m.redeem (...) :
if m.redeemable then
m.redeem (...)

else
... ( ?)...
end
, :
MORTGAGE, .
-
.
NEW_MORTGAGE, .
.
redeem .
. ,
if.
redeem , focus_line
.
, -
, . :
class NEW_MORTGAGE inherit
MORTGAGE
export {NONE} redeem end
...
, . - ,
:
m: MORTGAGE; nm: NEW_MORTGAGE
...
m := nm
...
m.redeem (...)
redeem (. 17 " - "),
, 17 " " .

.
, " ABC phylum [ genus, species etc.]
XYZ", "", ""
" ". ,
, , , !
, , , ,
( ):

, ,
.
. ,
.
, .
. , , ,
.
. .
.
. ,
,
.
.
- .
, , . (, ,
, .) . ( BIRD fly.) , . - OSTRICH - ,

, . - OSTRICH - ,
.
- .
, ,
.
(OSTRICH) . , , ,
. -
. .
, , ( ) .
OSTRICH BIRD, fly.

( )
, .

. ,
.

,
. redeem NEW_MORTGAGE fly OSTRICH
,
.
,
( , , ).
. , , ?
, , , , .
,
, .


, ,
, , .

,
. , ARRAYED_STACK:
class ARRAYED_STACK [G] inherit
STACK [G]
redefine change_top end
ARRAY [G]
rename
count as capacity, put as array_put
export
{NONE} all
end
feature
... STACK, put, count, full...
... change_top ARRAY ...
end
ARRAYED_STACK STACK2
(. 11 " - ") - ,
. , ARRAY
( implementation.put,
put).
ARRAY . :
, , STACK, ; ,
, ARRAY, . ARRAYED_STACK
.

, ?
. "is-a".
. . , ,
. , ARRAYED_STACK ARRAY
(count). , ,
"is-a". : ARRAY, put
( array_put), infix "@" count ( capacity),
ARRAYED_STACK, .
STACK.
.
, , CAR_OWNER
, ARRAYED_STACK "is-a".
: ,
( , export), .
, .

, .
STACK2 . representation ARRAY [G]
, ( ):
put (x: G) is
-- x
require
...
do
count := count + 1
representation.put (count, x)
ensure
...
end
ARRAY representation .
: ( representation),
( representation, , ).
, .
"representation". ,
- , , , , .
- , . " " - .
,
. " ,
".
indexing
description: ", "
class
ARRAYED [G]
feature -- Access
item (i: INTEGER): G is
-- i
require
...
do
Result := representation.item (i)
ensure
...
end
feature -- Element change
put (x: G; i: INTEGER) is
-- x i
require
...
do
representation.put (x, i)
ensure

...
end
feature {NONE} -- Implementation
representation: ARRAY [G]
end
item put . ARRAYED ,
. ,
,
ARRAYED. .
, , ARRAYED_STACK ARRAYED_LIST,
ARRAYED: .
item representation.item ; .
! ARRAYED ,
ARRAY? , ARRAY. ARRAYED
, ,
, .
ARRAYED. ,
ARRAY, .


, .
. .
, .

Base Libraries ASCII:
indexing
description:
" ASCII. %
% - , ."
class ASCII feature -- Access
Character_set_size: INTEGER is 128; Last_ascii: INTEGER is 127
First_printable: INTEGER is 32; Last_printable: INTEGER is 126
Letter_layout: INTEGER is 70
Case_diff: INTEGER is 32
-- Lower_a - Upper_a
...
Ctrl_a: INTEGER is 1; Soh: INTEGER is 1
Ctrl_b: INTEGER is 2; Stx: INTEGER is 2
...
Blank: INTEGER is 32; Sp: INTEGER is 32
Exclamation: INTEGER is 33; Doublequote: INTEGER is 34
...
...
Upper_a: INTEGER is 65; Upper_b: INTEGER is 66
...
Lower_a: INTEGER is 97; Lower_b: INTEGER is 98
... .. ...
end
( 142 ),
ASCII.
, , , .
, , , , .
, , TOKENIZER,
, . . ASCII:
class TOKENIZER inherit ASCII feature
... Blank, Case_diff ...
end
, ASCII, , ,
.


, .
, , ()
, , . ""
, , action, , .
, action
, , test,
, test, , . ,
. , ,
action test.
, ,
, LIST SEQUENCE.
6.7 , .
, . 6.11.

. 6.11.
LINEAR_ITERATOR, , :
indexing
description:
", "
names: iterators, iteration, linear_iterators, linear_iteration
deferred class LINEAR_ITERATOR [G] inherit
ITERATOR [G]
redefine target end
feature -- Access
invariant_value: BOOLEAN is
-- , ( : true)
do
Result:= True
end
target: LINEAR [G]
-- ,
test: BOOLEAN is
--
deferred
end
feature - Basic operations
action is
--
deferred

end
do_if is
-- action
--target, test.
do
from start invariant invariant_value until exhausted loop
if test then action end
forth
end
ensure then
exhausted
end
... : do_all, do_while, do_until ...
end
,
. , ,
, (
). :
class JUSTIFIER inherit
LINEAR_ITERATOR [PARAGRAPH]
rename
action as justify,
test as justifiable,
do_all as justify_all
end
feature
justify is
do ... end
justifiable is
-- ?
do
Result := not preformated
end
...
end
. ,
justify_all ( do_all): ,
action test.
justify, , .
("join"),
action, justify ( ),
justify, . , .
LINEAR_ITERATOR (behavior class),
,
.

, ASCII LINEAR_ITERATOR, :
,
;
, .
, .
, .

,
.
, , , ,
ASCII LINEAR_ITERATOR. , , :
" - ,
?"
, RECTANGLE, BANK_ACCOUNT LINKED_LIST, ,

, :
ASCII : " , ASCII".
LINEAR_ITERATOR : " ,
". " ",
5.
, : TOKENIZER
" ASCII", JUSTIFIER "
".
. , . ,
. , .
, ASCII:
charset: ASCII
...
create charset
charset.Lower_a.
charset . LINEAR_ITERATOR.
, -
action test .
-, ,
.


, .

(,
) : , ,
, . , ,
- . , ,
. , - ,
.
, ,
, .
, , EMPLOYEE . ,
:
: ;
: , , .
-. ,
, TEMPORARY_EMPLOYEE MANAGER ,
, .
?
(. 6.12).
.
, , , PERMANENT_EMPLOYEE, ENGINEERING_EMPLOYEE .
,
.

. 6.12.

, ,
(. 6.13).
. , CONTRACT_EMPLOYEE , ,
, ( !).
" , ".
, , ,
. , ,
, . .
.
: , ,
CONTRACT_EMPLOYEE SPECIALTY_EMPLOYEE , PERMANENT
ENGINEER. EMPLOYEE.
:
,
. , ,
, , , ,
. EMPLOYEE (,
) , .

. 6.13. ,
?
.
, ,
.
, , ,
. , ,
: - , .
,
. .
, :
, . ,
, , ?
, ,
, .
EMPLOYEE :
is_permanent: BOOLEAN
. , :
Permanent: INTEGER is unique
Temporary: INTEGER is unique
Contractor: INTEGER is unique
...

, ,
WORK_CONTRACT, , , .
:
if is_permanent then ... else ... end

inspect
contract_type
when Permanent then
...
when ...
...
end
,
, , - .
WORK_CONTRACT , , ,
- .
EMPLOYEE, , , hire
( ) and terminate ().
. 6.14.
, , ,
.
. -
, ( contract) .
, .
( , ).

. 6.14. ,

,

. , ,
. , ,
.
:
,
.

.
( : permanent supervisor, temporary engineer, permanent
engineer ) .
,
.
.
, , Base
, . , ,
[M 1994].
. :

. 6.15. ,
(BOX, COLLECTION, TRAVERSABLE) ; (
, ) .
:
COLLECTION . SET ,
BAG .
, SEQUENCE ( ), STACK (
, ) .
BOX . .
.
.
TRAVERSABLE .
, , . ,
BOX, COLLECTION TRAVERSABLE , ,
.
. ,
.

. 6.16.
, BOX, COLLECTION TRAVERSABLE :
, has ( ) empty (
). - CONTAINER,
. , ,
, ,
.
, ,
. : .
, , .
,
, .


-
, .
?

, ,
( ) (). ,
, - ,
, , , .
, .
, , .
, , ,
, . , ,
.
; , ,
. , , ,
, - .
:
, ,
POINT POINT_3D ;
- FIGURE, RECTANGLE, CIRCLE ;
- , QUADRANGLE ( ), TRIANGLE ( ) SEGMENT
( ), POINT , ;

, -
COMPLEX VECTOR_2D.
, ,
. .
, ,
, , .

POINT .
, . -
, .
.
. ,
, , DNA- .
, () ,
.


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

-
.

.
. B,
, ,
A, :

. 6.17.
, , , , B A, -
. A ,
B . ,
A, , .
, E F
:

. 6.18.
, D.
, , .


( -).
. ,
X, :

. 6.19. ,
B A, E F D, X,
B E ( ) .
,
. , X B E :
b1: B; e1: E
...
b1.some_feature_of_B
...
e1.some_feature_of_E
X , B E .

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

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

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


"is a"
, , .
"has"; .
( CAR_OWNER.)
, .
, . ,
.
,
.
, :
( , ),
( , ) (
, ).
.
.
,
, .
- , ,
.
. .
,
- .
.


[Girod 1991]. - [Page-Jones 1995] , , ,
. - [McGregor 1992]
, .
[Breu 1995] , ,
.
, "" , [Gil 1994].
, Web , " " (http://www.phylogeny.arizona.edu/tree/life.html),
, .
.
.

:
.
. ,
, ,
.

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

6.1 ,

STACK ARRAYED_STACK, ,
" ".
6.2

, .
?
6.3

( .)
STACK put ,
full ( extendible;
, , ).
, ,
, , 1883 .
, (),
, , , :
.
HANOI_STACK, , STACK?
, ? , HANOI_STACK - STACK?
, " " . ,
.
6.4 ?

POLYGON vertices
. POLYGON LINKED_LIST
[POINT]?
6.5

. ,
- , "
".
6.6

, :
SEGMENT OPEN_FIGURE;
COMPARABLE (, ), PART_COMPARABLE
( );
EXCEPTIONS.
6.7 ?

(while_do ) , ,
, LIST? :
action test, ;
: ;
: -, , ,
.
6.8

, : .
, ?
6.9

A B,
, x := y
x A y B?

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



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

.
- . , .
, .
, .
: ( " " " "),
. "has" "is".

: Vision, WEL/PEL/MEL.

.
(obsolete)
.


.
: ,
.
, : ( ).
( ).
: .
: LINKED_LIST, LINKABLE.
: ( Math).

, .
;
.
.

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

( ).
(LIST, LINKED_LIST ).

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

: .
: , ,
.
, .
: rescue, .
.
: ( ) .
, ,
retry.



, :
perimeter POLYGON, RECTANGLE, SQUARE.
: balance ACCOUNT.
.
(, ,
, ). ,
.
.
precursor.
( ).

.
,
.
: . .
, ( ).

:
.
: .
: .
:
, .

( ).

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

-
8. :
- ,
.

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

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

.
, , APL Cobol. Fortran-C-C++
Algol-Pascal-Ada - , , , - .
. .
C-, , "obfuscated
(, ) C C++".
(DIVIDE DAYS BY 7 GIVING WEEKS) Cobol .
, Algol-
. , -
. ,
, ; , disp
(), display ( ), ACCNT () ACCOUNT.
. ,
, . ,
"the" ;
( account_balance ACCOUNT, balance ).
,
, :
from i := 1 invariant i <= n until i = n loop.
. ,

. ,
, , ,
.
, , , - , C, Pascal,
Ada Fortran, .
, Quicksort, -
, C, ,
. ISE
( , ), -
. ? ,
-:
- . C ,
.
Ada . , Java, -,
C, .
.
,
.

- .
,
.
, , .
, .

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

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

.
. .

,

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


, , - .
, .

, .
, ,
. PART, ,
number, num, (), . ,
- . usa
copter ,
. ,
, PART PARTIAL , PART_COMPARABLE, ,
.
. ,
, ANNUAL_RATE, yearly_premium .
, ,
. .
- , ,
.
, - PRODUCT_QUANTITY_INDEX_ EVALUATOR.
, , . ,
. , ,
, - .
:
( ).
, PART, number, part_number.
, ,
. , ,
part1.number, part1 PART .
, Smalltalk ,
X Window System, ,
, yearlyPremium. ,
yearly_premium.
, , , (
aLongAndRatherUnreadableIdentifier
an_even_longer_but_perfectly_clear_choice_of_name).

, .
. , RATE,
ACCOUNT RATE,
rate - , , .
, rate: RATE.
. the,
the_rate, .

, .
, ,
. , , ,
. (
, , , TWO_WAY_LIST e Base)
move (i: INTEGER) is
-- i after, i
local
c: CURSOR; counter: INTEGER; p: like FIRST_ELEMENT
...
remove is
-- ; cursor
-- ( after ).
local
succ, pred, removed: like first_element
...
succ pred , successor predecessor.
new , , ,
other , , ,
clone GENERAL:
frozen clone (other: GENERAL): like other is...

,
.
:
: POINT, LINKED_LIST, PRICING_MODEL.
, G.
, , ,
: balance, deposit, succ, i.
,
: Pi: INTEGER is 3.141598524; Welcome_message: STRING is "Welcome!".
, .
, :
Error_window, Io. i ( )
.
, .
. , do class, ;
. ,
,
, . : Current, Result, Precursor, True False.

, .
, , ,
.
: , ACCOUNT,
, LONG_TERM_SAVINGS_ACCOUNT,

, , ,
NUMERIC REDEEMABLE.
:
() , ,
: make, move, deposit, set_color.
() :
get_value, value.
, number, , ,
last_month_balance. , full.
(empty, ,
" ?" " !"). is_
, is_ empty.

, put
item. .
, :
, , .
, .
. : make
make_some_qualification, , make_polar
make_cartesian POINT COMPLEX.
:

8.1.

extend

replace

force

put, .
put , , , force

remove

( )

prune

wipe_out
( )

8.2.

item

: ARRAY - ;
STACK - ; QUEUE - ""

infix
"@"

item , ARRAY

count

capacity , ,
. 0<count and count <= capacity
:

8.3.

empty

full

? count =
capacity

has

? ( )

extendible ? ( extend)
prunable

? ( remove prune)

readable

? ( remove item)

writable

? ( extend, replace, put .)


, , ,
.
? ,
, ? , item
, - .
-,
. ,
, :
F1 .
F2 ( , , ).
F3 , .
F4 .
, , , , .
. ,
STACK :
put (x: G)
-- x
require
writable: not full
ensure
not_empty: not empty
pushed: item = x
ARRAY :
put (x: G; i: INTEGER)
--
require
not_too_small:
not_too_large:
ensure
replaced: item

x i
i >= lower
i <= upper
(i) = x

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


. ,
- .
.

, :

() ,
. .
, , , 50 ( )
"Cannot find file" ( ). :
population_array.make (1, 50)

print ("Cannot find file") --


,
, :
US_state_count: INTEGER is 50
file_not_found: STRING is "Cannot find file"
...
population_array.make (1, state_count)
...
print (file_not_found)
: ,
.
1 state_count ,
, . ,
, 0 1 ( ),
0.0, , '%0', - "".
One , (1
), ,
.
1 ,
, . ,
Processor_count: INTEGER is 1 , .
,
. , : "
, ".
. ,
, .
- .
, , ,
.

, , ,
- , .
, ,
, . (
.) ASCII Base.


,
. feature,
indexing, , .
:
-, " !",
"
". , is,
; :

distance_to_origin: REAL is
-- (0, 0)
local
origin: POINT
do
create origin
Result := distance (origin)
end
: .
, , . ,
, ,
. CIRCLE :
tangent_from (p: POINT): LINE is
--
-- ,
-- p,
--
require
outside_circle: not has (p)
...
. -, " ..."
" ... ", ,
. , ,
. :
-- ,
-- p,
--
, ,
. ( the),
. . (, ,
, .)
-- ,
-- p,
--
. , - not has (p), ,
. , ,
( : x >= 0 "
x", " ");
. :
-- p
(line) (point)
: LINE POINT.
, ,
. :
-- p
- , .
: ,
, , . ,
, , , ,
(0,0) "" (point).
: ,
, Current.
, ,
. :

-- p
, 18 .
87%, , , .
. " ...",
, : "
( ) ...", , . :
--

--
, ()
( ). .

:
has (v: G): BOOLEAN is
-- v ?
...
- , ,
. ( ).
,
:
-- 'v' ?
, ,
.
. : " ",
"" : " ",
.
.
, ,
, :
count: INTEGER
--
, .
feature
, feature:
indexing
...
class LINKED_LIST [G] inherit ... creation
...
feature -- Initialization
make is ...
feature -- Access
item: G is ...
...
feature -- Status report
before: BOOLEAN is ...
...
feature -- Status setting
...
feature -- Element change
put_left (v: G) is ...
...
feature -- Removal

feature -- Removal
remove is ...
...
feature {NONE} -- Implementation
first_element: LINKABLE [G].
...
end
feature ,
.
. feature, ,
. , ,
feature, . ,
, , short,
.
Base,
( 2000) .
. Status report (
Status setting, ).
Implementation.
, ( , ),
.
.
,
.

,
, :
indexing
description: " "
names: "Sequence", "List"
contents: GENERIC
representation: chained
date: "$Date: 96/10/20 12:21:03 $"
revision: "$Revision: 2.4$"
...
class LINKED_LIST [G] inherit
...
-
,
. , ,
:
indexing_term: indexing_value, indexing_value, ...
indexing_term , indexing_value
, , . , ,
(names),
(contents), (representation), (revision),
. ,
, . ,
,
.
, ,
. , Base,
. description, index_value
, ( ..., "
", " ", "
" . .). - ,
- description indexing.

,
.

, .
, ,
. ,
, . , ,
. - "" (comment out).
.
: -- i 1 i := i + 1.
.
. C ,
C -
,
. - , ,
, ,
. ,
, ,
, , . ,
, check ,
. ,
. : ,
, ,
.


,
.
"" , .
, , , .

,
" ",
, "" "".
, (do, ) ( ,
). , (, ).
, - (comblike structure), Ada. , ,
:
;
, ,
.

. 8.1. -
,
.
, - .
, a, b c,
:
if c then a else b end

if
c
then
a
else
b
end
:
if c then
a
else b end
, if c c end,
- , , .
indexing :
class C inherit

-- [1]

class C feature

-- [2]

class
C
feature

-- [3]


class C
feature

-- [4]

.
[1] [2] .
feature, inherit
[3] ( , [2]):
class
C
feature -- Initialization
...
feature -- Access
..

,
, . ()
, :
count := count + 1; forth
(
, );
. , ,
.
.
, ,
. , ,
.
,
.
, . ,
.

, ( !).
,
:
0: , . : indexing
( ), class ( ), feature (
feature, , feature , class),
invariant ( ) end .
1: - declaration; ;
.
2: , .
: require, local, do, once, ensure, rescue, end.
3: ;
; .
.
, if a then... , .
, . ,
- ,
.
check . , , ,
.
indexing
description: " "
class EXAMPLE inherit
MY_PARENT
redefine f1, f2 end

MY_OTHER_PARENT
rename
g1 as old_g1, g2 as old_g2
redefine
g1
select
g2
end
creation
make
feature -- Initialization
make is
--
require
some_condition: correct (x)
local
my_entity: MY_TYPE
do
if a then
b; c
else
other_routine
check max2 > max1 + x ^ 2 end
--
new_value := old_value / (max2 - max1)
end
end
feature -- Access
my_attribute: SOME_TYPE
-- ( make)
... feature ...
invariant
upper_bound: x <= y
end --class Example

(, , )
, .
, ,
. ,
.
. :
, : f (x) ( f(x) C, f(x)).
, ,
, . : proc1 (x); x := f1 (x) + f2
(y).
, : g (x, y, z).
, : -- .
, , :
p1; p2 (x); p3 (y, z)
,
:
p1 ; p2 (x) ; p3 (y, z)
, . ( .)
. ,
your_entity: YOUR_TYPE.
, a + b. (
, n+1.)

, ,
, Simula. , a.r :
r , a. , .
, 3.14, .


.
; , (a = (b + c)) implies
(u /= v) , , .
"" , , ,
, .


, . , Algol Pascal, ,
. , PL/I, C Ada,
.
.
: ,
" ?" (
- , , , ). ,
, ,
.
.
do instruction1; instruction2; instruction3 end
f (argument1, argument2, argument3). , ,
f (argument1, argument2, argument3,) ? ,
, , ,
,
.
, ,
. : , ,
, Algol 60, ,
:
a; b; c
a; b; c;
; a ;; b ;;; c;
.
, .
, , ,
. ,
.
. 1975
, 25
, , , .
Ada.
, !

, , , : ,
. , , ,
, -,
, , begin a; b; end,
! , ,
. , , ,
PL/I () .

.

, , ,
, .
, ,
. , ,
:

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

, (
), .
, ,
, .
:
found := found + 1; forth
. .
, .
.
( )
. , ,
, , , ,
, - , ,
, , , .
, . (
, ,
, ,
,
.)

:
require
not_too_small: index >= lower
, ,

(. 11 " - "),
,
.
, ,
. , - , ,
:
require
index >= lower; index <= upper

.

,
.

( , , ) .
, , , " ,
number , ". ( number , ,
, !)
, class, feature, invariant ,
(boldface).
: .
, , , Current Result,
.
.
, - , , -
( roman), 1). ,
.
(roman) . ,
, , . :
accelerate
-...
set_number
-...

(s: SPEED; t: REAL) is


s t
(n: INTEGER) is
n number

, ,
, :

-- 'n' 'number'
(, .)
, , short flat,
.

, , Web-.
. , ,
, .
:
, ;
, Bookman;

2).


[Walden 1995] , ,
separated_by_underscores
internalUpperCase.
[Gannon 1975]
.
[M 1990b]
[1994a].
,
, .

8.1

:
reorder (s: SUPPLIER; t: TIME) is
-- s,
-- t;
-- ,
--
require
not_in_past: t >= Now
...
next_reorder_date: TIME is
-- ,
--
8.2

,
, , ,
?
: , (vector1 +
vector2).count.
1)
2)

.
, , - .

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

, :

A1 , ( ) .
A2 .
A3 .
A4 , .
A5 , .
A6 , .
, .
A7 .
,
A1, A2 A3.
, (feasibility study) ,
. ,
.
A0, .
, ,
. , , .
A2 A3 .
,
(A2). ? ?
?
,
. , ,
,
, . A2
, .

:
(A1, A2);
(A7);
(A1);
(A3);
(A1,
A7).
() .

. ,
.
.

, ,
, , .

.

. , ,
.
, ? ,
?
. - .
, ,
.
, . (,
, X, " X , ,
?") ,
, ( ),
, A2 .
.
, -.
, . ,
, ,
, .
,
.


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

. 9.1.
. 9.1. A.
B, .
, , .
, ,
.
.
,
. .

, .


.
, , , ,
. " " , :

(, , , ...) , ;
do ( deferred ,
).

. :

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


- .
.
, .
.

, , .

24- . ( ) SCHEDULE.
:
class SCHEDULE feature
segments: LIST [SEGMENT]
end
.
LIST? : LIST ,
, -
. LIST , .
: , LIST,
: put , count
.
. ,
, ; . -
, , .
:
indexing
description: "24- "
deferred class SCHEDULE feature
segments: LIST [SEGMENT] is
--
deferred
end
air_time: DATE is
--
deferred
end
set_air_time (t: DATE) is
--
require

t.in_future
deferred
ensure
air_time = t
end
print is
--
deferred
end
end
. , ,
, . , ,
.
:
,
. , ,
CASE-,
, .
OO ,
.

. ,
.
, .
in_future DATE, .

.

SCHEDULE, SEGMENT.
:
indexing
description: " "
deferred class SEGMENT feature
schedule: SCHEDULE is deferred end
-- ,
index: INTEGER is deferred end
--
starting_time, ending_time: INTEGER is deferred end
--
next: SEGMENT is deferred end
-- ,
sponsor: COMPANY is deferred end
--
rating: INTEGER is deferred end
-- ( ..)
... change_next, set_sponsor, set_rating . ...
Minimum_duration: INTEGER is 30
--
Maximum_interval: INTEGER is 2
--
invariant
in_list: (1 "= index) and (index "= schedule.segments.count)
in_schedule: schedule.segments.item (index) = Current
next_in_list: (next /= Void) implies (schedule.segments.item (index + 1) = next)
no_next_iff_last: (next = Void) = (index = schedule.segments.count)
non_negative_rating: rating >= 0
positive_times: (starting_time > 0) and (ending_time " 0)
sufficient_duration: ending_time - starting_time >= Minimum_duration
decent_interval: (next.starting_time) - ending_time >= Maximum_interval
end
" " , ,
schedule index. starting_time ending_time,
duration, , .
, ,
.
. in_list in_schedule .

"" . : next_in_list
, - i, - i +1. no_next_iff_last
, .
: sufficient_duration
30 , ,
decent_interval - 2 ( ).
, .
-, ( ).
- DATE, TIME DURATION. -, SEGMENT
: .
SEGMENT
content: PROGRAM_FRAGMENT
PROGRAM_FRAGMENT
. duration PROGRAM_FRAGMENT, SEGMENT
:
content.duration = ending_time - starting_time
.
, -: , ,
, , , .
. ,
, . 0 ,
.

SEGMENT, : ( ).
.

. 9.2.
.
, .
: ,
? ,
COMMERCIAL, .
: INFOMERCIAL (
) .
COMMERCIAL:
indexing
description: " "
deferred class COMMERCIAL inherit
SEGMENT
rename sponsor as advertizer end
feature
primary: PROGRAM is deferred
-- ,
primary_index: INTEGER is deferred
-- primary
set_primary (p: PROGRAM) is
-- p
require
program_exists: p /= Void

same_schedule: p.schedule = schedule


before: p.starting_time <= starting_time
deferred
ensure
index_updated: primary_index = p.index
primary_updated: primary = p
end
invariant
meaningful_primary_index: primary_index = primary.index
primary_before: primary.starting_time <= starting_time
acceptable_sponsor: advertizer.compatible (primary.sponsor)
acceptable_rating: rating <= primary.rating
end
. ,
, .
.
() ,
primary_index. ,
- :
, .
Pepsi-Cola , Coca-Cola.
.
: .
primary . , :
, ,
( SHOW), ,
. ,
, .

, .
: SCHEDULE
; SEGMENT ,
; COMMERCIAL .
-
.
: , .
, .
- , ,
. , ,
acceptable_sponsor .
, , .
, : ,
.

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

:
, , ,

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

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

. , C A (. 9.3),
B
. ,
.

. 9.3.
,
. ,
,
. , ,
. ,
.
- .
,
, , .
, :
1.
:
SCHEDULE, SEGMENT, COMMERCIAL, PROGRAM ...
SCHEDULE 2; SEGMENT 3; [ ..]
2. SCHEDULE
...
3. ...
4. COMMERCIAL
1. :

2. .
COMMERCIAL - SEGMENT,
, .
3. .
sponsor SEGMENT advertizer COMMERCIAL.
...
4. .
...
5. .
COMMERCIAL:
primary, , PROGRAM
: [ , ]
:
,
:
...
:
...
... ...
6. .
... ...
5. PROGRAM
...
. .

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


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


OO
. , , ,
.
, .
Coad-Yourdon .
: , ,
" -" " -",
"" ( -), ; .
OMT (Object Modeling Technique) ,
" -" (entity-relation). .
, , , , -
"-" .
Shlaer-Mellor , ,
. ,
: , ( ), , .
.
Shlaer-Mellor ,
, .
Martin-Odell, OOIE (Object-Oriented Information Engineering), .
, , ,
. , ,
, .
Booch ( ) (
), , ,
. UML (Unified Modeling Language) (. ).
OOSE (Object-Oriented Software Engineering), Jacobson Objectory (
), .
: - ,
, , .
OSA (for Object-oriented Systems Analysis) ,
. : , ,
" ", ,
, , , ,
. ,
, .
Fusion .
.
, ,
, .
.
Syntropy . - " ",
, . - ,
,
. .
: ,
OMT , .
,
.

MOSES : -, ,
, " " , ,
. BON, MOSES
,
. " " ,
.
SOMA (Semantic Object Modeling Approach) " ",
" ".
, , .
, .
(Brian Henderson-Sellers, Don Firesmith, Ian Graham Jim Odell)
OPEN. Rational Corporation UML ( ),
OMT, Booch Jacobson.

BON (Business Object Notation)


. Business Object Notation (BON),
Nerson Walden,
OO-.
. .
. BON
, . BON
, .
BON : , . -
. -
: . (
) - . BON -
, ,
, (, ,
).
BON OO-:
"", .
,
, . , ,
. ,
, , .
BON 1990- . ,
, .
.
. .

. . ,
.
BON - .
,
. -
.
; ,
.
BON : ,
.
. ,
. , delta a ,
a, forall exists ,
member_of - .
.
.

9.1. BON
CLASS

Class_name

Part:

Short description ( ) Indexing information ( )


Inherits from ( )

Queries ()
Commands ()
Constraints ()
, . ,
, . 9.4.

. 9.4. BON ([Walden 1995], )

. .
.
:
B1 : , ,
, , .
B2 -, ,
.
B3 : ,
, . .
B4 : , .
B5 : , .
B6 : .
B7 .
, .
, .
, ,
( , !).
, .
. BON
, .


Business Object Notation [Walden 1995].
[Nerson 1992]. Web- www.tools.com/products/bon/.
. CoadYourdon: [Coad 1990], www.oi.com; OMT: [Rumbaugh 1991]; Shlaer-Mellor:
[Shlaer 1992], www.projtech.com; Martin-Odell, [Martin 1992]; Booch: [Booch 1994]; OOSE: [Jacobson 1992]; OSA: [Embley
1992], www.osm7.cs.byu.edu/OSA.html; Syntropy: [Cook 1994], www.objectdesigners.co.uk/syntropy; Fusion, [Coleman
1994]; MOSES: [Henderson-Sellers 1994], www.csse.swin.edu.au/cotar/OPEN/OPEN.html; SOMA, [Graham 1995].
. [Henderson-Sellers 1996]. [Computer 1996] ,
Unified Modeling Language (Booch-OMT-Jacobson) Rational Corporation.
- : www.arkhp1.kek.jp/~amako/OOInfo.html.

-
10. :
- . .
. Object Success.
: ,
, , , .

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

, , .
.
. ,
. ,
.
. ,
, - .
- , .
Lace, .
.
, . ,
, - , ,
. ,
.
,
.


-
. , 1970 ., "
, ". ,
.
:
, , ,
- . : ,
.
, ,
. ,
, "" ,
Internet.
- ,
. -
, .
.

. 10.1.
.
(
), , .
- :

. 10.2.
.
:
.


:
: ( ) ;
: ;
: ;
(Verification &amp; Validation): ( ,
);
: (. ).
. ,
, - "-".
. -, ,
, (feasibility study),
. -, . ,
,
.


, , . 10.3.
: , .
:
.

.
.
. ,
, (
).

. .
.

.

. 10.3.
, ,
.
.
, , .
,
, , . ,
.

. 10.4.

-. ,
.
, , , .

, . ,
. 10.3 , . 10.4, ,
, .
.
, ( . 10.4 ).

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

,
.

, ,
. , , - ,
, , , ,
. .
. ,
, , , - .
,
. .
, ,
.
- .
. , ,
, !
? . ,
. ,
, . ,
.
( ),
, , , .
, .
a priori a posteriori:

, .
, , .
.
,
- .
:
: , .
(Factoring): ,
, .
, ,
. , ,
.
rescue ,
.
.

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


OO .
, ,
. ,
.

, , .
. ,
. ,
, , ,
.

:
,
, (, ,
...).
, . ,
,
.
,
.
, .
, -.
, ,
.
:
.
- ,
. , ,
.
, , , :
, - , - . ,
, -
? , ? ?
- esprit de l'escalier, (" ", ).
.
Marengo, . , ,
- , , ! .
esprit de l'escalier ? ,
, . .
, , , .
OO- , esprit de l'escalier - ,
. . ,
, . ,
, .
.
3 :
, , .

:

. 10.5. ,

-

. - ,
, , , ,
. , ,
.
, ,
( - ) , ,
. ,
, - . .
1970- , -
. , .
, . , ,
. .
.
,
( ) .
- ,
, .
. .
, ,
. .
, "Essays on General Linguistics",
:
: " , !".
, : " , , !".
" ", - . - " ". : ", , ,
. - ".
. - !


, , .
- .
.
-
, .
.

[M 1995] .
, - , ,
.
[Baudoin 1996] , ,
, , .
[Gindre 1989]. - , "
", [Henderson-Sellers 1990] [Henderson-Sellers 1991], [Henderson-Sellers
1994]. , , .
-, [Rumbaugh 1991] ( OMT) [Henderson-Sellers
1991], .
. [Walden 1995].
***
Wisdom sometimes blooms late in the season
Or half-way down the stairs.
Is it, my Lords, a crime of high treason
To trust the implementers?1)
1)

, . , , ,
?

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

()

, . ,
, .
, , ,
. ,
. , -
-. - -
, mOOzak. , ,
, ,
? ! - ,
. - , , .
, , :
: " "
T1 .
T2 -.
T3 .
T3 : - ,
. , -, ,
- . .
- .
, - mOOzak,
- . ,
- - ?
? -
? ? -
. , ,
( , ),
,
, , .
,
. , .

-, .
:

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

- .
. -, :

50% .
, :

, .
, -, , .
, , , , ,
, . (
, , [Goldberg 1995], [Baudoin 1996] [M 1995]).
,
. ,
.

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


(
).
-, , ,
-, ,
.

?
, . - .
, .
, .
- , , .
, , , . , -.
, : (
) ( ).
, . . ,
, , Algol, ,
, , .
, , ,
? , , .

( ) -
, ,
, .
,

-,
.
- ,
:
, .
, , ,
, , ,
.
, Z VDM,
. , ,
. -

.

- ,
, . ,
, , ,
- ,
, .
, C, , ,
- ,
;
. , ,
- , , , .
.
. ,
. ,
. ,
, .
.
, , : , , ,
. . , C++ Java
, :
public static void main(String[] args {
if (this->fd == -1 && !open_fd(this))
if ((xfrm = (char*)malloc(xfrm_len + 1)) == NULL) {
, , , .
, , .
, .

Usenet:
, Java (
). , Java
. , .
:
, , : public static void main (String
[ ] args), IOException. 6
, .
, - ,
(import, declare, initialize). -
. .
Java (int, char, boolean, float, long, ...) ,
. (Integer, Boolean, Character . .).
int Integer.
String ( ).
, . StringBuffer , .

, .
.
, ,
, Stack Hashtable.
.
. ,
: " , ".
, , ,
, . Pascal,
, ,
, , , ,
, . ,
, , -.
, ,
. :
(computing science departments) Pascal,
Fortran, Cobol PL/I, .
C++ Java ,
.
C++ Java , -. ,
, .
C - .
:
. - - RPG Cobol.
1996 Java, 1995 Java.
2010 2020? , ,
.
(intellectual) .
, ,
. , , . ,
-, , C++- Java, , .
Pascal , ,
.
Pascal; Pascal.
- Fortran, Cobol PL/I.
- , ,
- . ,
,
.


, - ,
. .

.
, .
:
, , (High school (US),
lyceum, Gymnasium).
- (,
"undergraduate studies" - , Gakubu ).
, ,
preparatoires
. Grundstudium.
(undergraduate) .
, (, ),
, (graduate - ,
postgraduate - , DEA, DESS - , Hauptstudium - , Daigakuin -

).

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

:
, , , ,
, , ,
.
(curriculum)
,
, (software curriculum).
. , -
, .


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

.
, , .
" "
- , , .
.
,
, .
25
- .
-, - , ,
, , .
, ,
, .
.
: ,
. ,
, .
, .
,
( - !).
, , , , ,
- .
: ,
, . ,
(, ,
, ).
" "
" ". (" "
.)

S1
S2
S3
S4
S5

, .
.
.
.
.

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

,
. , , ,

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

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

" "
, , - . , , ,
, , .
( - ) . , , ,
- .
,
, , ,
.
() .
,
. :
, .
, Lex Yacc,
. .

" " ,
" ".
( , , , , , , VLSI
), - :
, VLSI CAD;
, , ;
;
;
.
, , : ,
,
, , .

" " ,
, , ,
.
,
, .
, ,
. ,
, . ,

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

, , .
, ,

, . ,
, . , ,
, .
, .

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

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

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

.
, .
: , (
"comliuting science"), - ( "information systems").
, ,
, .
, ,

, , .
, ,
" X -" " Y ". ,
, UCSD Pascal, Waterloo Fortran X Window, MIT.


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


, Journal of Object-Oriented Programming,
TOOLS USA 93
( [M 1993c]).
Object Success [M1995], mOOzak,
.
- [McKim 1992]
[Helotis 1996].
Bernard Cohen [Cohen 1991].
, ,
.
: Christine Mingins, James McKim, Richard Mitchell, John Potter, Robert Switzer, Jean-Claude
Boussard, Roger Rousseau, David Riley, Richard Wiener, Fiorella De Cindio, Brian Henderson-Sellers, Pete
Thomas, Ray Weedon, John Kerstholt, Jacob Gore, David Rine, Naftaly Minsky, Peter Lohr, Robert Ogor, Robert
Rannou.
-.
2 " - ",
: [Rist 1995], [Wiener 1996], [Gore 1996],
[Wiener 1997], [Jzequel 1996].

-
12. : , , -
, , ,
( , ) .
, , . . . ,
, . - ,
, , : , ,
. ,
. .
, , .
, , - , ,
- . : -
? :
.


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

, .
, , :
- separate. ?
-: x.f (a), O1,
f O2, x a. ,
, O1 O2, O1
, , .
, ,
x. : ,
x: SOME_TYPE, x: separate SOME_TYPE, , x
, x .
create x.make (...) - -
x.
, . ,
separate - , ,
. .
: (),
() , , ()
. "" - ;
( ,
, Unix Windows)
. , , - " " -_ ("Concurrency Configuration File"),
.
, . :
, x.f
(a) separate x . ,
, , value :=
x.some_query. (wait by necessity).
O2
a, separate, , , r(a).
, , separate (, a),
, .
( , )
, , .
,
. , , ;
, .
,
, - .
, , .


. , ,
.
(multiprocessing) (multiprogramming) :
(object request brokers) .


, (
, ). ,
, , .
.
, ,
, , (-, ) ,
, , , , .
.
: Toy Story, ,
( ), - ,
.

, , , , .
(load balancing):
, .
, - (client-server
computing), : "",
,
. , , ,
, , ,
.
- ,
. 60- 70- ,
. , 80-,
, ( " "). ,
().
- 90-. - :
- , , ,
- , :
.

,
.
( ,
), ,
. ,
, : ,
, ,
. , (, ,
,
) ,
.
(time-sharing),
. , "", , ,
. , ,
. ,
: , - ,
. .

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

,
. ,
, , - ,
.
( - Object Request Broker)
CORBA (Object
Management Group) OLE 2/ActiveX . , ,

1).
,
. CORBA , , (interoperability).
, CORBA, , "
" .
:
, .
, IDL ( - Interface Definition Language);
IDL, ,
IDL.
IDL - -, . IDL
, ( , IDL );
, . , -,
IDL- , . ,
, IDL- , .

90- (WorldWide Web).
- , ,
, ,
. : ,
.
, .
,
.
. (plug-in)
.
Java, Java- .
.
, , Java; ,
"-" Java ( ,
Java-).
, , : ISE
- Java.
: ?
,
. ,
.

, . :

.
, ISE, -
, . "external" ,
, ,
. " " Java ,
, .
,
, , -. ,
( ), .
-
- .


, ,
. ? , -.
, (Robin Milner) 1991 -: " ,
[-] " ( [Matsuoka 1993]). ,
, , ?
-, . - : , ,
, .
, :

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

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

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

, -
" ". - , :
. Java [Doug Lea 1996]:
( (?) Unix)
.
. .
: , .
. , (
) , - ,
. , .
, , : ,
, , !
- - ,
, , , , . ,
- (producer-consumer) producer,
:
", producer "
" x"
", producer "
" consumer"
" x consumer"
consumer,
", consumer "
" producer"
" x producer"
", consumer "
" , x"

. 12.1. - (producer-consumer)
, ; handshake () rendez-

vous (). - "


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

, ,
-, , .
B A (. . ,
), B A?
,
, , - .
. Simula 67 ,
: Simula , (. 17).
A inner, ,
B. , A :
some_initialization; inner; some_termination_actions
B :
specific_B_actions
B :
some_initialization; specific_B_actions; some_termination_actions
, , ,
. -, , , B,
. -, ,
- ( -)
.
:
, ?
, " ",
.
, -
. , , ,
-;
- , . ( ,
- , - ,
.)
, , . - , , ;
. .

, , .
: . ,
. !
, , ?
, ;
, . , , -
, , live, :
indexing
description: ", "
note: " , PROCESS, %
% PRINTER"
class

PRINTER_1
feature -- Status report
stop_requested: BOOLEAN is do ... end
oldest: JOB is do ... end
feature -- Basic operations
setup is do ... end
wait_for_job is do ... end
remove_oldest is do ... end
print (j: JOB) is do ... end
feature -- Process behavior
live is
--
do
from setup until stop_requested loop
wait_for_job; print (oldest); remove_oldest
end
end
... ...
end
: live
, , -,
. PRINTER_1
, .
, ,
- ,
. live .
, , ,
, - , .
:
indexing
description: " "
deferred class
PROCESS
feature -- Status report
over: BOOLEAN is
-- ?
deferred
end
feature -- Basic operatios
setup is
--
-- ( : )
do
end
step is
--
deferred
end
wrapup is
--
-- ( : )
do
end
feature -- Process behavior
live is
--
do
from setup until over loop
step
end
wrapup
end
end
: step , setup wrapup ,
.
step, ,
.
. ,
.
, , :
indexing
description: ", "
note: " , PROCESS"
class PRINTER inherit

PROCESS
rename over as stop_requested end
feature -- Status report
stop_requested: BOOLEAN
--
-- ?
oldest: JOB is
--
do ... end
feature -- Basic operations
step is
--
do
wait_for_job; print (oldest); remove_oldest
end
wait_for_job is
--
do
...
ensure
oldest /= Void
end
remove_oldest is
--
require
oldest /= Void
do
if oldest.is_stop_request then stop_requested := True end
" "
end
print (j: JOB) is
-- j,
require
j /= Void
do
if not j.is_stop_request then " , j"
end
end
end
, j,
jlis_stop_request. ( print remove_oldest,
- " "; [. 12.1]).
-. ,
, , " ",
, , .
, , live ( , ,
operate, PROCESS).
: perform_internal_test ( ),
switch_to_Postscript_level_1( Postscript1) set_resolution ( ).
- , .
, , , - - , ,
, - .
-, . ,
, PROCESS, ,
, , ,
.
-, .


, , ?

, ( 5 "
- "),
:

. 12.2.
- ,
. (, ), .
? , .
, ,
.
. , ,
.
: ( ) ,
-.
, .

:
- ,
.
, , ,
(CPU),
. "" - " ",
. , .
, :
( ) ;
, , - , Unix, Windows
;
( , ,
,
, );
"", Solaris, OS/2 Windows NT.
. , ;
() , . , (
- ),
. , .
. ,
( ).
, ,
.
([Lieberman 1987])(
):
[] , , []
, . , ,
.
, , , ""
: .
.
" " ("Concurrency Control File"), ,
.

() . , O2
- , O2 (. .

x.f (a), x O2).


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

- , :
x.f (a)
y := x.f (a)

-- f -
-- f -

, , O2 - , x, O1 - , .
( , , O1).
f, O2 a
. :
... previous_instruction; x.f (a); next_instruction; ...
( ), next_instruction , f.
. ,
, , ,
.
("") .
:
O1 O2 , O1 (next_instruction)
. .
O1 O2 , O1 ,
O2. .
, O2
. 1
. , , , , y,
, .

,
.
, , ,
, . , () O2
O1. , x, .

x.
, .
:
x: SOME_TYPE
:
x: separate SOME_TYPE
, x , .
, :
separate class X ... ...
class X ... deferred class X ...
, y expanded T , ,
T , T - , expanded class T. - (expanded),
(deferred), (separate) - ,
class.
, -
, .
. "" ("separate") ,

( ), ( ). : , separate class; ;
, separate T T; x.f (...) - ,
x . : ;
, , - .
:
BOUNDED_BUFFER (_) ,
( - - , - -
).
PRINTER (), , -, PRINT_CONTROLLER (_),
. ,
( , ,
).
DATABASE ( ), -
, , .
BROWSER_WINDOW (_) .

, :
,
. (, , - ,
, ). BROWSER_WINDOW:
, . BOUNDED_BUFFER PRINT_CONTROLLER
.
,
. DATABASE: - db_server:
separate DATABASE db_server.ask_query (sql_query).
server.
BOUNDED_BUFFER PRINT_CONTROLLER.
, , .
:
create x.make (...)
.
:
, , , :
server (name: STRING; ... ...): separate DATABASE
.
.
, - . ,
() (, Windows Unix),
; , .
, (proxy):

. 12.3.
O1, T x: separate U. - O1 O2, . -,
O1. - , .
O2: , O2, O2
. x, O1 , .
, , O2,
O2.
, , .
.
.

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

separate " ?",
, (. 12.4),
, ( Vision, ,
, . 14).
. , ,
.
separate.

. 12.4.
( . 12.4 ).
. 12.4 :
, .
. :
, . ,
, - , ,
, .
. , - ,
. .
, CORBA
.
(PVM) ( - Parallel Virtual Machine),
Linda, Java...
,
( (handle) )
, .
.
: (Concurrency Control File)

, - .
. , , ;
,
.
" " () ("Concurrency Control File" (CCF)),
. Ace,
( 7 " - ").
:
creation
local_nodes:
system
"pushkin" (2): "c:\system1\appl.exe"
"akhmatova" (4): "/home/users/syst1"
Current: "c:\system1\appl2.exe"
end
remote_nodes:
system
"lermontov": "c:\system1\appl.exe"
"tiutchev" (2): "/usr/bin/syst2"
end
end
external
Ingres_handler: "mandelstam" port 9000
ATM_handler: "pasternak" port 8001
end
default
port: 8001; instance: 10
end
, (creation, external,
default) , .
creation , ( create x.make (...)
x). : local_nodes, ,
remote_nodes. :
set_cpu_group ("local_nodes")
, local_nodes
set_cpu_group. CONCURRENCY,
, .
, local_nodes:
pushkin, - akhmatova, - (. .
, ). -
pushkin . . , Current , instance
default ( 10), , 1. ,
, , , pushkin c:\system1\appl.exe (,
Windows OS/2).
. (
, ) , .
external , .
, Ingres_handler ATM_handler,
. , server :
server (name: STRING; ... ...): separate DATABASE
server ("Ingres_handler", ...) , Ingres.
, mandelstam 9000.
, defaults, ,
.
.
,
( external)
( creation).
, , , - ( ) - . ,
, , .
.

.
, (

).
, , , .
, ; .
.
, .
,
. ,
. - :
, (
), .
:
, ,
( x: T T) .
, x.f (a) - - ,
, , . ,
, , - (traitor).
, , ,
.
. , . .
:
(1)
( ) ,
.
x y x := y , f (..., y, ..), y -
, x. , y , x , x ,
x (, y)
, . .
, x , y .
" ". - ;
(, , a + b : a.plus
(b)). : ,
.
, , ,
, .
, ,
. :
x.f (a),
a T , x . f , x, :
f (u:SOME_TYPE)
T a SOME_TYPE. ! (. .
x) O1, a, - , ,
u , , ,
:

. 12.5.
, SOME_TYPE , , separate T.
:

(2)
,
.
. , , INTEGER,
.
, , ,
, . . : " , , ".
, ,
. :
create subsystem.make (Current, ... ...),
Current - , subsystem (progenitor)
. Current - , make
. make :
make (p: separate PROGENITOR_TYPE; ... ...) is
do
progenitor := p
... ...
end
progenitor .
, p ,
progenitor. progenitor.some_resource (...)
.
.
(3)
, ,
.
,
.
(4)
,
.
, , - "
" , .
, .
. 12.6 , u . O1
O'1, u (. 8 " "). O1 , - O'1.
, O1 ; " ".

. 12.6.
u , ; O'1,
, u.
:
a: expanded SOME_TYPE; a1: SOME_TYPE

...
a1 := a;
x.f (a1)

-- a1

u ,
separate SOME_TYPE. u ,
.

, ,
, clone ( ANY). :
clone (other: GENERAL): like other is
-- , other
...
y := clone (x) x 1- : x,
, other. , . ,
, () , .
, - ,
.
GENERAL :
deep_import (other: separate GENERAL): GENERAL is
-- , other
...
, ,
other. ,
deep_clone (. 8 " - "),
. deep_import. ,
. (, ,
, ).
deep_import ,
-
, .


( )
( ). , ,
, . .
.
, , , , -
- , -.
? , . - ,
, .
-, .
versus
, -, -.
( ) :
, . ,
( ),
( ).
, , - (
, ) .
,
, . ,
. , , ,
.
,
, , - ,
. - : reserve () free (),
P V, .
, . reserve,
. , , free, .
, reserve, , .
:

30.1.

reserve
free

, , , ,
.
, ,
. ( (fairness),
, , ).
. n
n>0.
,
. .
(critical regions) . -
, .
a :
hold a then ... a ...end.
then... end.
, , hold, .
- (conditional critical region),
. ,
, , , , ,
. :
hold buffer when not buffer.full then " , " end
hold buffer when not buffer.empty then " , " end

. .
,
, (monitor). - ,
Modula Ada. : .
.
" " (path expression).
. , :
init ; (reader* | writer)+ ; finish
: init, writer
reader; ,
finish. (*) ,
(;) - , (|) - "-", (+) - .
,
, ,
.
,
, . ,
. ,
, ( ,
).
.
,
" " (), 70-,
- , .
. ,
. , , ,
: , ,
. .
. .
: " , , ".
"-": v "" c ? v;
c ! v.
.

, |,
, .
, ,
, :
(balance_enquiry ? customer R
(ask_password.customer ? password R
(password_valid R (balance_out.customer ! balance)
| (password_invalid R (denial.customer ! denial_message)))
| transfer_request ? customer R ...
| control_operation ? manager R ...)
: (balance_enquiry),
(transfer_request), (control_operation). , ,
, ( ).
:
, (ask_password),
(password). : balance_out
(balance) (denial).
.
Ada, ""
, "" "" (. 15). Occam,
, (transputer)
, Inmos ( SGS-Thomson) .
-
-.
, , .
, -
- .
, : , , .
.
-. ,
, , .
. , BUFFER remove (
) put ( ), ,
:
empty: {put}
partial: {put, remove}
full: {remove}
[Matusoka 1993], " ".
12.3.
. ,
NEW_BUFFER remove_two,
( ). :
empty: {put}
partial_one: {put, remove}

-- ,
--
partial_two_or_more: {put, remove, remove_two}
full: {remove, remove_two}
, BUFFER
NEW_BUFFER, .
, , (inheritance anomaly)
- . ,
- POOL .
" " ,
.
,
, .
, , ,
, , . BUFFER NEW_BUFFER
: put require not full, remove_two - require
count >= 2 . . ,
( ). ,
, . ,

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


, -.

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

. 12.7.
, : (S1),
(S2 ). " "
. , : ,
(
, 11 " - "). p , :
{Default and prep} Bodyp {postp and INV}
r :
{prer and INV} Bodyr {postr and INV}
.
, , , ,
, , "" , .
. , ,
, , . .,
. ,
, ,
, .


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

, ,
.
, ( ), .
x.f (...) x, O2,
- O1. , O1
, , , O2
O1. , , ,
.
, , ,
. , O2 - (, )
remove . O1
, :
Buffer.remove; buffer.remove,
, ,
.
buffer ( ) remove_two,
. : -
.
, .
, . :
hold a then ___ end
:
hold a when a._ then ___ end
, , , .
, , a - , :
___ (a)
, , a, . hold
-
.
, , x.some_routine
x, a. , ,
some_attribute := x, . ,
.
, hold.
. hold
, - " ", ,
, .
, ,
hold.
, ( ) .
a,
, a . , ,
. :
r (a: separate SOME_TYPE) is
do
...; a.r1 (...); ...
...; a.r2 (...); ...
end
, ,
a , . ( , ,
, ; , !)

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

, r
. ,
: r, , , , .
:

, .
, a.r (...) , a - .
a, a .
. , attrib - , ,
attrib.r (...) rf(attrib, ...), :
rf (x: separate SOME_TYPE; ... ...) is
-- r.
do
x.r (...)
end
, ,
.
, , , ,
, , .
. , ,
.
. , - -
remove count . "" :
if buffer.count >= 2 then
buffer.remove; buffer.remove
end
. , , - , ,
buffer. , count
, remove, ,
, remove .
, item, , ,
remove:
if not buffer.empty then
value := buffer.item; buffer.remove
end
buffer item remove.
, , , , (
) ! .
buffer , : , buffer
.
, .
. - ,
, . - ,
, - . , , , :
( ) ,
count remove. .
. ,
, .
, ,
BOUNDED_BUFFER:
remove_two (buffer: BOUNDED_BUFFER) is
--
do
if buffer.count >= 2 then

buffer.remove; buffer.remove
end
end
get_and_remove (buffer: BOUNDED_BUFFER) is
-- value
do
if not buffer.empty then
value := buffer.item; buffer.remove
end
end
; , BUFFER_ACCESS
(__),
.
. .

,
( buffer.remove). , , .
, , ,
.
, (, ,
-, Hybrid)
. (. " "
) . , , .
, a.r (...) a, O1,
? , O1, , ,
. - ,
a.r (...) , , ,
, .
, (), ,
( ), . ,
- .
, , s :
s.put (x1); ... ...; s.put (x2); ... ...; value := s.item
( s).
, " " s, , ,
; - ( x2).
:
, .
.
( " " " "
" ", , )
, ,
.

, . ,
, :
launch (a: ARRAY [separate X]) is
-- a
require
-- a
local
i: INTEGER
do
from i := a.lower until i > a.upper loop
launch_one (a @ i); i := i + 1
end
end
launch_one (p: separate X) is
-- p
require
p /= Void
do
p.live
end

live X , ,
launch_one, , :
. .
, , ,
, , , Simula detach
.

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

,
,
.
, " " " ,
".
()
, ,
, (
).
, .
:
x.f (a) , x - , a - ; , a - ,
, Current. f :
f (u: separate SOME_TYPE) is
do
local_reference := u
end
local_reference separate SOME_TYPE .
local_reference , f,
local_reference.some_routine (...).
. , , f -, , g u.g
(...). : ( , u a)
f , , , .
:

,
.
,
( 12.4 12.13 ).
.


. :
( );
, , , ?

-
. , , (
) ,
. , , , ,
. - .
maxcount . ,
, .
, ,
. , - ,
: (put)
(item, remove). , .
, , , ,
"-, - (FIFO)".

. 12.8.
- , -
representation capacity = maxcount + 1; oldest
, next - , .
, 1 capacity (. . 12.9).
put, x, :
Representation.put (x, next); next := (next\\ maxcount) + 1
\\ - ; item,
, representation @ oldest ( oldest),
remove oldest:= (oldest\\ maxcount) + 1. capacity ( )
; empty, next = oldest,
full, (next\\ maxcount) + 1 = oldest.

. 12.9. ,
FIFO , ,
: , , .
, , 3 Undo.
(
):
class interface BOUNDED_QUEUE [G] feature
empty, full: BOOLEAN
put (x: G)
require
not full
ensure
not empty
remove

remove
require
not empty
ensure
not full
item: G
require
not empty
end
, , , :
separate class BOUNDED_BUFFER [G] inherit
BOUNDED_QUEUE [G]
end
separate , , .
, , . ,
, : expanded deferred. ,
, class.
, -,
, , . , (,
) -
, .

buffer , y
put. , buffer - , buffer: BOUNDED_BUFFER
[T] T ( y ).
, , buffer ,
, :
make (b: BOUNDED_BUFFER [T],...) is do ...; buffer := b; ... end
buffer, , , buffer.put (y)
, buffer.
put(buffer, y), put - ( put
BOUNDED_BUFFER), :
put (b: BOUNDED_BUFFER [T]; x: T) is
-- x b. ( )
do
b.put (x)
end
. put BOUNDED_BUFFER not full.
x b, :
put (b: BOUNDED_BUFFER [T]; x: T) is
-- x b
require
not b.full
do
b.put (x)
end
. buffer y? ,
. :
if not full (buffer) then put (buffer, y)

-- [PUT1]

, , :
remove (buffer); put (buffer, y)

-- [PUT2]

remove not full. ( PUT2 ,


not empty remove.)
?
- . full put PUT1 remove put PUT2
- . ,
.
, PUT1 PUT2 , buffer
, , PUT1:
put_if_possible (b: BOUNDED_BUFFER [T]; x: T) is

-- x b, ; was_full - true
do
if b.full then was_full:= True else
put (b, x); was_full := False
end
end
. -, was_full ,
, ? - , .
put , , , .

, , ,
.
( 11
" - "):

30.2. put
put

( :) put(x)

( :) ,
x

( :) , x ( :)
,
not empty
" ": ,
, . put ,
, .
, BOUNDED_BUFFER,
: , ,
, !
. , , put BOUNDED_QUEUE ( ,
BOUNDED_BUFFER) , full.
: ,
.
.
: put ,
not empty . ,
, .
, , .
. , ,
, . .
,
-,
, .
, ,
. 12.6.

:
A1 . , put BOUNDED_BUFFER
BOUNDED_QUEUE .
A2 () .
full .
A3 ,
. .
: , .
, .
. " "
, , .
not b.full put.
:

, ,
.

, ,
.
,
( , ).
, (
" ",
). " ":
r (x: separate SOME_TYPE) is do some_attribute := x end
- , x.some_routine, ,
x.
, .
r (x: blocking SOME_TYPE)...
put :
put (b: BOUNDED_BUFFER [T]; x: T) is
require
not b.full
do
b.put (x)
ensure
not b.empty
end
put (buffer, y) - , buffer ()
. buffer , , , - -
( not b.empty, ,
); , , , -
.
, , (
), ?
. FIFO, .

.
, ,
, . . , b.some_property , b -
. , i > = 0, ,
:
, , ,
.

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

. ,
:
f (x: SOME_TYPE) is
require
some_property (separate_attribute)
do
...
end
separate_attribute - . , separate_attribute,
. f (
, , x, ) ,
.

:

, , ,
.
, , ,
.

. 12.10 , ,
, .
, ,
, .
, .

. 12.10.


.
, .
, ,
, . , CONCURRENCY,
, .
:

EXCEPTIONS 12 " - ";

MEMORY (. 9 " - ").

ABCL/1 ([Yonezawa 1987a]) "- " , " " VIP-,
.
- , ,
. . ,
. - , ,
, , ,
- ? , ?
. 14 " " " ,
". , " ,

".
, - .
, , , ,
. - .
. , , ,
. , , ,
(fail), (retry) .
. ,
- .

, "- " (
- ).
:
r (b)
b. b b,
. r b, ,
, , , :
s (c)
c , b.
r. , ?
CONCURRENCY . ,
yield, : " ". ,
: yield , , . ,
, , retain.
, , . :
Demand " !". ( yield), , ,
, ( demand -
). , .
Insist : , , ,
- , .
wait_turn.
CONCURRENCY ,
. , . , insist,
, yield, .
, , .
- .
, CONCURRENCY ( ).

30.3.

Wait_turn

demand

insist

retain

yield

" ", , - ,
. retry ,
.
, , EXCEPTIONS. ,
, is_concurrency_interrupt.
: "-"
, . , -
-, , shared.
,
, ,
.
(),
- (), , -
. -
. - - ,
.

"-" , :
, , , ,
. , , ,
.
, , ,
operate interrupted,
, . operate, next,
. , , CONCURRENCY (yield retain),
EXCEPTIONS (is_concurrency_interrupt). operate ,
.
execute_interruptibly is
--
-- ( -)
local
done, next: INTEGER; interrupted: BOOLEAN
do
from done := 0 until termination_criterion loop
if interrupted then
process_interruption (shared); interrupted := False
else
next := done + 1; yield
operate (next, shared, interrupted) --
retain; done := next
end
end
rescue
if is_concurrency_interrupt then
interrupted := True; retry
end
end
.
, - ( )
. shared ,
:
insist; interrupt (shared); wait_turn
-- , , .
-- shared.
process_interruption, operate, shared: shared
, , .
. , operate
process_interruption ; (
). process_interruption -
, . , ,
process_interruption , shared.
. ( operate
), , .
interrupt , ,
. . , shared,
deposited . interrupt not
shared.deposited, ,
shared.set_deposited, process_interruption shared.set_not_deposited.
" " create partner.make (shared, ...),
shared, .
execute_interruptibly
, operate, process_interruption, termination_criterion,
.
.
,
, , .
, .
:
, ;
, ;
;
.

, -
.

. 12.11.
" " - ,
, ,
. , , , , .
. , , ,
.
.
, , ( ):
separate class PHILOSOPHER creation
make
inherit
GENERAL_PHILOSOPHER
PROCESS
rename setup as getup undefine getup end
feature {BUTLER}
step is
--
do
think
eat (left, right)
end
feature {NONE}
eat (l, r: separate FORK) is
-- , l r
do ... end
end
, , eat, left right,
, .
,
left right. ,
.
PHILOSOPHER , PROCESS:
live, PROCESS from setup until over loop step end,
, , step. ,
setup getup.

, , . ,

. ,
.
, GENERAL_PHILOSOPHER:
class GENERAL_PHILOSOPHER creation
make
feature -- Initialization
make (l, r: separate FORK) is
-- l , r
do
left := l; right := r
end
feature {NONE} -- Implementation
left, right: separate FORK
--
getup is
--
do ... end
think is
--
do ... end
end
.
:
class FORK end
BUTLER ("") :
class BUTLER creation
make
feature
count: INTEGER
--
launch is
--
local
i: INTEGER
do
from i := 1 until i > count loop
launch_one (participants @ i); i := i + 1
end
end
feature {NONE}
launch_one (p: PHILOSOPHER) is
--
do
p.live
end
participants: ARRAY [PHILOSOPHER]
cutlery: ARRAY [FORK]
feature {NONE} -- Initialization
make (n: INTEGER) is
-- n
require
n >= 0
do
count := n
create participants.make (1, count); create cutlery.make (1, count)
make_philosophers
ensure
count = n
end
make_philosophers is
--
local
i: INTEGER; p: PHILOSOPHER; left, right: FORK
do
from i := 1 until i > count loop
p := philosophers @ i
left := cutlery @ i
right := cutlery @ ((i \\ count) + 1
create p.make (left, right)
i := i + 1
end
end
invariant
count >= 0; participants.count = count; cutlery.count = count
end

, launch launch_one, , ,
, p.live , .

,
. .
, .
- - ,
, , ,
, ,
.
, :
class BINARY_TREE [G] feature
left, right: BINARY_TREE [G]
... ...
nodes: INTEGER is
--
do
Result := node_count (left) + node_count (right) + 1
end
feature {NONE}
node_count (b: BINARY_TREE [G]): INTEGER is
-- b
do
if b /= Void then Result := b.nodes end
end
end
nodes .
node_count.
, ,
. , (separate), nodes
:
separate class BINARY_TREE1 [G] feature
left, right: BINARY_TREE1 [G]
... ...
nodes: INTEGER
update_nodes is
-- nodes,
do
nodes := 1
compute_nodes (left); compute_nodes (right)
adjust_nodes (left); adjust_nodes (right)
end
feature {NONE}
compute_nodes (b: BINARY_TREE1 [G]) is
-- b
do
if b /= Void then
b.update_nodes
end
end
adjust_nodes (b: BINARY_TREE1 [G]) is
-- b
do
if b /= Void then nodes := nodes + b.nodes end
end
end
compute_nodes . ,
.
( ), , -,
. ,
,
() .
b .
- , left right, - ,
.
, , , .
. ,
, , .

create new_node.make (new_element). new_node BINARY_TREE1[G],


. .

, , (lockers),
- (lockable) - , ,
. . :
class LOCKER feature
grab (resource: separate LOCKABLE) is
--
require
not resource.locked
do
resource.set_holder (Current)
end
release (resource: separate LOCKABLE) is
require
resource.is_held (Current)
do
resource.release
end
end
class LOCKABLE feature {LOCKER}
set_holder (l: separate LOCKER) is
-- l
require
l /= Void
do
holder := l
ensure
locked
end
locked: BOOLEAN is
-- - ?
do
Result := (holder /= Void)
end
is_held (l: separate LOCKER): BOOLEAN is
-- l?
do
Result := (holder = l)
end
release is
--
do
holder := Void
ensure
not locked
end
feature {NONE}
holder: separate LOCKER
invariant
locked_iff_holder: locked = (holder /= Void)
end
, , LOCKABLE.
, grab release .
, , ,
. ,
-. , use,
:
deferred class LOCKING_PROCESS feature
resource: separate LOCKABLE
use is
-- resource
require
resource /= Void
do
from create lock; setup until over loop
lock.grab (resource)
exclusive_actions
lock.release (resource)
end
finalize
end
set_resource (r: separate LOCKABLE) is
-- r

require
r /= Void
do
resource := r
ensure
resource /= Void
end
feature {NONE}
lock: LOCKER
exclusive_actions
-- resource
deferred
end
setup
-- ; :
do
end
over: BOOLEAN is
-- ?
deferred
end
finalize
-- ; :
do
end
end
LOCKING_PROCESS exclusive_actions over ,
setup finalize . , LOCKING_PROCESS
PROCESS.
, LOCKING_PROCESS, grab :
, .
, .
grab LOCKER , : resource
Current, .
, (.
12.7). - :
reserve free.
, LOCKING_PROCESS,
,
reserve free.
(Coroutines)
( ),
.
(, , ) , ,
- Simula 67; 17.
.
. ,
:
. ,
, ; .
, - .
- . a ,
b ; b , ,
, , ; a
.
resume c, : c , ,
, - (resumes) .

. 12.12.
() .
; , , ,
, .
:
, .
, , .
:
separate class COROUTINE creation
make
feature {COROUTINE}
resume (i: INTEGER) is
-- i
do
actual_resume (i, controller)
end
feature {NONE} -- Implementation
controller: COROUTINE_CONTROLLER
identifier: INTEGER
actual_resume (i: INTEGER; c: COROUTINE_CONTROLLER) is
-- i .
-- ( resume).
do
c.set_next (i); request (c)
end
request (c: COROUTINE_CONTROLLER) is
-- c
require
c.is_next (identifier)
do
--
end
feature {NONE} --
make (i: INTEGER; c: COROUTINE_CONTROLLER) is
-- i c
do
identifier := i
controller := c
end
end
separate class COROUTINE_CONTROLLER feature {NONE}
next: INTEGER
feature {COROUTINE}
set_next (i: INTEGER) is
-- i
do
next := i
end
is_next (i: INTEGER): BOOLEAN is
-- i ?
do
Result := (next = i)
end
end
,
(. 12.10). .
i, resume actual_resume next i,
, next = j, j - .
.
, ( ,
), ,
. ( , ,

.)
, resume COROUTINE, . .
, . unique,
. : ,
, :
resume (i) i. ,
resume (i) i.
, : ,
- .

-

.
, .
- . - ,
- . ,
, ().
. ,
, (, ).
, , , ,
. .
,
( ), -
.
MOTOR , :
separate class MOTOR feature {ELEVATOR}
move (floor: INTEGER) is
-- floor
do
" floor"
signal_stopped (cabin)
end
signal_stopped (e: ELEVATOR) is
-- , e
do
e.record_stop (position)
end
feature {NONE}
cabin: ELEVATOR
position: INTEGER is
--
do
Result := " , "
end
end
cabin . ELEVATOR
: puller , .
"" :
, move , , ,
.
record_stop signal_stopped. ELEVATOR
MOTOR BUTTON.
separate class ELEVATOR creation
make
feature {BUTTON}
accept (floor: INTEGER) is
-- floor
do
record (floor)
if not moving then process_request end
end
feature {MOTOR}
record_stop (floor: INTEGER) is
-- floor
do
moving := false; position := floor; process_request
end
feature {DISPATCHER}

position: INTEGER
moving: BOOLEAN
feature {NONE}
puller: MOTOR
pending: QUEUE [INTEGER]
--
-- ( )
record (floor: INTEGER) is
-- floor
do
" floor pending"
end
process_request is
-- pending,
local
floor: INTEGER
do
if not pending.empty then
floor := pending.item
actual_process (puller, floor)
pending.remove
end
end
actual_process (m: separate MOTOR; floor: INTEGER) is
-- m floor
do
moving := True; m.move (floor)
end
end
: , , ,
. : ,
, , ,
-, , .
( , ,
, pending ELEVATOR).
FLOOR_BUTTON , . ,
: , - .
, , BUTTON , . ,
, ELEVATOR BUTTON,
:
separate class BUTTON feature
target: INTEGER
end
separate class CABIN_BUTTON inherit BUTTON feature
cabin: ELEVATOR
request is
-- target
do
actual_request (cabin)
end
actual_request (e: ELEVATOR) is
-- e target
do
e.accept (target)
end
end
separate class FLOOR_BUTTON inherit
BUTTON
feature
controller: DISPATCHER
request is
-- target
do
actual_request (controller)
end
actual_request (d: DISPATCHER) is
-- d target
do
d.accept (target)
end
end
. ,
.
, DISPATCHER. accept,

position moving ELEVATOR,


going_up (_). , ,
ELEVATOR .
separate class DISPATCHER creation
make
feature {FLOOR_BUTTON}
accept (floor: INTEGER) is
-- floor
local
index: INTEGER; chosen: ELEVATOR
do
" , floor"
index := " "
chosen := elevators @ index
send_request (chosen, floor)
end
feature {NONE}
send_request (e: ELEVATOR; floor: INTEGER) is
-- e floor
do
e.accept (floor)
end
elevators: ARRAY [ELEVATOR]
feature {NONE} --
make is
--
do
" "
end
end

, .
.
action ,
failed (true), t
. wait (t),
t .
, . , ,
TIMED action, TIMED. action
t , timed_action (t). (
WATCHDOG), wait (t), . action
, . , t: REAL
t>=0, .
deferred class TIMED inherit
CONCURRENCY
feature {NONE}
failed: BOOLEAN; alarm: WATCHDOG
timed_action (t: REAL) is
-- , t ,
-- , failed true
do
set_alarm (t); unset_alarm (t); failed := False
rescue
if is_concurrency_interrupt then failed := True end
end
set_alarm (t: REAL) is
-- t
do
-- :
if alarm = Void then create alarm end
yield; actual_set (alarm, t); retain
end
unset_alarm (t: REAL) is
--
do
demand; actual_unset (alarm); wait_turn
end
action is
-- ,
deferred
end
feature {NONE} --
actual_set (a: WATCHDOG; t: REAL) is

-- a t
do
a.set (t)
end
... actual_unset ...
feature {WATCHDOG} --
stop is
-- , timed_action
do -- Nothing end
end
separate class
WATCHDOG
feature {TIMED}
set (caller: separate TIMED; t: REAL) is
-- t caller;
-- ,
require
caller_exists: caller /= Void
local
interrupted: BOOLEAN
do
if not interrupted then wait (t); demand; callerl stop; wait_turn end
rescue
if is_concurrency_interrupt then interrupted:= True; retry end
end
unset is
-- ( ,
-- set)
do -- Nothing end
feature {NONE}
early_termination: BOOLEAN
end
yield , , retain : yield; " "; retain.
demand ( insist) : demand; " "; wait_turn.
.

, .
separate class BOUNDED_BUFFER [G] inherit BOUNDED_QUEUE [G] end ,
BOUNDED_QUEUE .
q BOUNDED_BUFFER [T] q.remove, ,
q . BUFFER_ACCESS
(__), , .
. ,
( , BOUNDED_ QUEUE)
.
indexing
description: " "
class BUFFER_ACCESS [G] is
put (q: BOUNDED_BUFFER [G]; x: G) is
-- x q, ,
require
not q.full
do
q.put (x)
ensure
not q.empty
end
remove (q: BOUNDED_BUFFER [G]) is
-- q, ,
require
not q.empty
do
q.remove
ensure
not q.full
end
item (q: BOUNDED_BUFFER [G]): G is
--
require
not q.empty
do
Result := q.item
ensure
not q.full
end

end
end


, ,
. ,
, , , [ 1990],
.
-
:
{INV and pre} body {INV and post}
pre, post body - , , INV - .
-.
.
-, - - , ,
, , - :
t.f (..., a, ...)
f, , , a, t, .
:

, f, , f, ,
, ,
. some_boolean_property
t t.some_boolean_property.
, , put BOUNDED_QUEUE,
not full, , not empty, q a
:
{not q.full} q.put (a) {not q.empty}
, -
(Hoare) :

INV - , Pre (f) - f, Post (f) -


. , :
clause1; ...; clausen
"" . f ,
, t.q' , f.
, .
. , , [M
1990].
, , "",
,
. , INV
( ), ( ).
?
t.cond, t - , ,
. :
f (..., a: T, ...) is
require
clause1; clause2; ...
do
...

end
, ,
: , .
, a.some_condition, a
, , .
,
:

Nonsep_Pre (f) - f, , Nonsep_Post (f) .


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


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

separate.
, :
x: TYPE
:
x: separate TYPE
, , class C, deferred class C expanded class C,
separate class C. C .
, , ,
. ,
:
.
T , separate T ( T ,
, , , ).
, . ,
. , () .
, ( , ,
).

:
1. ( ) ,
;
2. ,
;

3. , ,
;
4. ,
.
, : separate TYPE TYPE
, .
, .
, , ,
( ).

- . t
, , . t ,
.
, : (). ,
,
.
: " ", "" "". "", ,
. ""
( ), - .
, - -
. , t.f (..., s, ...), f - . ( f
, , ,
.)
C_OBJ,
"". :
: (satisfiable call)
CONCURRENCY ( ) f, C_OBJ,
, ,
A_OBJ,
, :
S1A_OBJ () C_OBJ.
S2 f A_OBJ .
, ; C_OBJ
, "", A_OBJ ,
, .
, (" " ""),
A_OBJ ( () C_OBJ).
, ; () C_OBJ "".
.
, ( ).
, .
:
,
, . (
, ,
.) "".

CONCURRENCY , S1 ,
A_OBJ ("") , C_OBJ ("") demand
insist; , .
, " ", , yield.
"" retain; yielding
. Challenging,
Normal, Demanding Insisting.
Normal wait_turn. demand
insist , , yielding, demand
, insist , wait_turn.
,
is_concurrency_exception EXCEPTIONS "" (true).


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

- - , , ,
.
. -
. ,
- ,
. , ,
- .
,
.
-
-, -,
. , " "
-. -
, .
.
, (
PROCESS), , .
.
, -.

, .
.
.
, .

.
(), , ( ), ,
.
, , :
next_element := buffer.item
buffer.remove
, ,
next_item. , .
, - get,
.
. : .
, .
, buffer b, b,
buffer . , , ,
, .
. ,
.


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

,
. , -
.
, . ,
.
- . ,
.
(, , , , .)
.
(, PROCESS ),
.
, , , ,
, .
, , , CONCURRENCY, ,
.

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

,
.
, ( BOUNDED_QUEUE)
( BOUNDED_BUFFER; separate class BOUNDED_BUFFER [G]
inherit BOUNDED_QUEUE [G] end). ,
, BUFFER_ACCESS. , -,
. ,
- .

, , - .
- . , ,
( , , ),
, .
. , ,
, , ,
free reserve,
, . ,
.
, , . ,
. - - (-
, , ,
). .
?
- ,
- . VIP-
.
: ,
, ( {INV and pre} body {INV
and post}), .

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


.
, .
, Web .

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

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


TOOLS EUROPE [M 1990a],
[M 1993b], ( , ).
SCOOP ("Simple Concurrent Object-Oriented Programming" - ). (John Potter) (Ghinwa Jalloul) ,
hold [Jalloul 1991], [Jalloul, 1994]. (Denis Caromel)
[Caromel 1989], [Caromel1993].
(Terry Tang) (Xavier Le Vourch).
.
[Ben Ari 1990]. :
[Dijkstra 1968a] ( " "), [Hoare 1974],
[Campbell 1974]. CSP [Hoare 1978]; [Hoare 1985]
. Occam2 [Inmos 1988]. CSP Occam
: http://www.comlab.ox.ac.uk/archive/csp.html ( (Bill Roscoe)
CSP.) CCS (Communicating Concurrent
Systems - ) [Milner 1989].
Linda (Carriero) (Gelernter) [Carriero 1990] ,
.
Communications of the ACM [M 1993a] , TOOLS.
[Agha 1993]. [Yonezawa 1987]
(Yonezawa) (Tokoro)
. [Papathomas 1992] [Wyatt 1992].
[Wilson 1996] C++.
(Hewitt) (Agha) -; [Agha 1990]
[Agha1986]. - , ,
. , ;
. ,
, " ".
- POOL [Amerika 1989]; POOL
, .
,
. POOL ,
.
- . [Yonezawa 1987]
, ABCL/1 [Yonezawa 1987a]. - MUSE,
(Sony), (Tokoro)

TOOLS EUROPE 1989 [Yokote 1989]. " " (Matsuoka)


(Yonezawa) [Matsuoka 1993],
.
, CHORUS
[Lea 1993] -, GUIDE (Krakowiak) . [Balter 1991],
(Shapiro) [Shapiro 1989]. ,
, - (Jean-Marc Jezequel) EPEE [Jezequel 1992], [Jezequel 1996], [Guidec 1996].
Nierstrasz Hybrid [Nierstrasz1992], [Papathomas
1992], ( ), ,
(activity). ,
.
DRAGOON [Atkinson 1991], , ,
- , pSather [Feldman 1993],
MONITOR.
.
. , ECOOP OOPSLA, [Agha1988], [Agha1991],
[Tokoro 1992], , , ,
.
.
- (Mordechai
Ben-Ari), (Richard Bielak), (John Bruno), (Paul Dubois), (Carlo Ghezzi),
(Peter Lohr), (Dino Mandrioli), - (Jean-Marc Nerson), ( Robert
Switzer) (Kim Walden).

12.1

PRINTER ,
. , , print,
" " ( print not j.is_stop_request).
12.2

, ( deep_import). ,
, .
12.3 " "

, BUFFER, " "


yield, , :
put (x: G) is
do
" x , "
if " " then
yield full
else
yield partial
end
end
remove. NEW_BUFFER
remove_two (_) ,
( , ).
12.4 ( )

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

, CONCURRENCY,
, yield, insist , .
12.6

:
f: FILE
...

...
if f /= Void and then f.readable then
f.some_input_routine
-- some_input_routine - ,
-- ; readable
end
, , , .
(: - ,
.)
, ?
12.7 (Locking)

LOCKING_PROCESS PROCESS.
12.8

, . (: ,
.) , ,
reserve free.
12.9

, .
12.10

, , .
12.11

Simula .
.
12.12

, ,
.
12.13

, set WATCHDOG . ,
.
12.14

( ,
, , )?
1)

Web- .

-
13. : ()
- . ,
? .
, . ,
. ,
- . - , ,
,
. - , ( ) -
. , -, - , . , -
. -.



. , ,
-, .

,
, , ,
(. 8 " - "), .
8 " - " ,
,
, . 13.1.

. 13.1.
, , O1,
, ,
(" ") loved_one O1.
STORABLE, : store
retrieved . , -
. 8 " " :
SAVE. ISE.
. ,
(Abstract Syntax Tree (AST)).
AST (" ") ,
. store;
AST retrieved.
STORABLE , , ;
- Net.

store . , basic_store (_),


, ,
.
.
, independent_store (_), ;
. ,
,
. -,
,
, . , PC
Net.
, ,
, Vision.
, - basic_store, independent_store.
, retrieved,
, ,
.

. ,
.
,
, STORABLE - , .
, .
, , - , .
.
, .
. , . 13.1,
address , .
ArchiText ISE,
, . , FAMILY
. 13.2, , , ,
CITY FAMILY. , , -
.

. 13.2. ,
"" .
. -, , , ,
- . :
? , ,
.
- , ,
. custom_independent_store
, independent_store.
ACTIONABLE , ,
, pre_store post_store,
. , , pre_store :
preserve; address := Void,

preserve - ACTIONABLE, - .
post_action :
restore,
.
:
store_ignore ("address"),
store_ignore . store_ignore
, preserve restore,
, pre_store-post_store ,
. , ,
.
,
post_retrieve, ,
. ,
post_retrieve - ACTIONABLE, :
address := my_city_structure.address_value (...)
, ,
- .
, , ACTIONABLE; ,
pre_store ,
post_store. , post_retrieve (
, post_store) ,
pre_store. , ,
, .

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

:
( !).
, . .

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

: ,
.
-, -
. ,
. . ,
;
. - ,
, ,
.
, .
,
. , :
(Detection) - ( );
(Notification) - ,
,
( !);
(Correction) - , . .
-
.
. , .

: (nominal) (structural).
,
.
.
, :

( ).
, OLE 2
, " IP-" .
, ,
.
.
, . ,
, , .
. (,
.) :
. ,
.
? .

,
. :
C1 , .
: , ,
, , ,
. .

C2 - ,
, ( ). ,
: ,
. ,
. , , ,
. ,
,
( )
.
C3 ,
. ,
, ( 1)
.
C4 C3 , . ,
, , ,
, , .
C3 - , ,
.

,
?
,
. . GENERAL (
) :
correct_mismatch is
do
.... ...
end
, correct_mismatch
(_) .
correct_mismatch
default_rescue. correct_ mismatch
.
( ) correct_mismatch? ,
, . ,
.
:
correct_mismatch is
--
do
raise_mismatch_exception
end
, , , .
, , .
, , ,
, correct_mismatch, , ANY. (
, GENERAL , ANY,
.)
mismatch_information (__)
ANY, . set_mismatch_information (info: ANY)
correct_mismatch , , .
, ,
, correct_mismatch ,
. - .

, ?
,
.

: ( retrieved STORABLE,
) ,
, .
, , ,
, , . .

. 13.3.
, -
- create x.make (...)
, make (. 8 "
- ". ,
, ;
, make
, .
, (. .
C3), , ,
. .
.
.
:
, . ,
correct_mismatch ,
. - ,
- .
, , . ,
, ?
, , , C4, .
- ,
. ? - . ,
,
, ( , - ). ,
, , , ,
!
- ACCOUNT deposits_list withdrawals_list. ,
balance. , ,
, .

. 13.4. account ().(, ?)


balance : , ,

.
:
balance = deposits_listltotal - withdrawals_listltotal
, balance ,
, .
balance - ,
$1000.
correct_mismatch .
:
correct_mismatch is
-- , balance
do
balance := deposits_list.total -withdrawals_list.total
end
, correct_mismatch
, , retry (
). ,
, , , .
, , ,
.


STORABLE , .
: , ,
, retrieved ,
. , STORABLE
.
,
.
, , (
"") (),
:
(Persistence): ,
.
(Programmable structure):
, .
, ,
.
(Arbitrary size): ( , ,
)
.
(Access control): "" .
, (Property-based querying): ,
, , .
(Integrity constraints):
.
(Administration): , ,
, , .
(Sharing):
.
(Locking): ( ,
) .
(Transactions): , ,
,
.
- , , ,
. , ,
, ; (rolling back) .
; ,
.

-
, (relational) ,
, (E. F. Codd) 1970 .

- (relations), (tuples) (
[records]). , ,
. , BOOKS ():

13.1. (BOOKS)
title ()
"The Red and the Black"

date () pages () author ()


1830

341

"STENDHAL"

"The Charterhouse of Parma" 1839

307

"STENDHAL"

"Madame Bovary"

1856

425

"FLAUBERT"

"Euge_nie Grandet"

1833

346

"BALZAC"

(fields).
; , - .
: title, date . . ()
(attributes).
, ,
( , , , ) .

,
. - (selection), (projection) (join).
, ,
. "pages , 400" BOOKS, ,
, BOOKS.

. ,
: "STENDHAL", "FLAUBERT" "BALZAC".
, ,
.
,
( , )
. , AUTHORS ():

13.2. AUTHORS ()
Name () real_name (_) Birth (_ ) death (_ )
"BALZAC"

"Honore_ de Balzac"

1799

1850

"FLAUBERT" "Gustave Flaubert"

1821

1880

"PROUST"

1871

1922

1783

1842

"Marcel Proust"

"STENDHAL" "Henry Beyle"

BOOKS AUTHORS author name


:

13.3. BOOKS AUTHORS


author name
title
"The Red and the Black"

date pages author/name

real_name

birth death

1830 341

"STENDHAL" "Henry Beyle"

1783 1842

"The Charterhouse of Parma" 1839 307

"STENDHAL" "Henry Beyle"

1783 1842

"Madame Bovary"

1856 425

"FLAUBERT" "Gustave Flaubert"

1821 1880

"Euge_nie Grandet"

1833 346

"BALZAC"

"Honore_ de Balzac" 1799 1850

- -

, SQL. :
, (" SQL") . SQL-
:
select title, date, pages from BOOKS
, BOOKS. ,
. :
select title, date, pages, author where pages < 400
. :
select
title, date, pages, author, real_name, birth, date
from AUTHORS, BOOKS where
author = name
, , .
-
, ,
-. , - , .
, (
SQL).
- C++, Smalltalk (
Store). , - ,
. :
- , , ,
. , - .
- ,
. ( , .)
, ,
(impedance mismatch) -
.
: - .

-
- .
D1 - ,
.
D2 .
D3 ,
( ),
.
,
. .
.
- D2 ,
(D1), -.

. ( , ,
.)
, , .
, (, ), :
R1 : ;
R2 :
;
R3 ( , ,
, ...), .
,

, : (), (),
(), () .
(R3) , , CAD-CAM ,
, ,
. , " ",
, - .
, , , , .
, , -
. , redblack.author.birth_year 1783,
redblack . 13.5.
author (), .

. 13.5.
, .
BOOKS AUTHORS, .
, author
name - .
: " " "?"
, . . ,
birth.
, .
, ,
: " , ,
, , -
?" -,
, .

,
. () A x B x ...
A, B, ...; , , , <a1, b1, ...>,
a1 A . . , ,
, . ,
<"The Red and the Black", 1830, 341, "STENDHAL"> BOOKS
. -,
.
, equal (obj1, obj2) , obj1 obj2 - ,
, obj1 = obj2 .
- ( ).
-.
: .

. 13.6. , ( )
,
. :
, .
, , , ,
.
, :
.
. - .
-, , :
,
, . (
, , ISE, ;
.) ,
-.
: ,
, ; , ,
, ,
.

, -:
, , - ( [Zdonik
1990]). (, , .) ,
: , , .
:
T1 , ;
T2 , . .
;
T3 ;
T4 .
, -, ,
. , . ,
. -,
, ,
(, ) .
- , .
" " -,
, , .. ,
- ( , ,
, , );
-.

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

. , , :
, , , , -.

, ,
. . , O1
O2. O1, . O2. ,
, O2, O1.
- ,
, , .

- , :
. , .
- .

,
, ,
. ,
, ; ,
( ), (
) - . , , (
, ).
, , CAD-CAM (
) ,
, .
,
, - , .
, , , .
, ,
. ,
( ) . ,
(configuration management),
,
, , . , ,
: .
,
-,
, .

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

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

-:
-.
: Gemstone, Itasca, Matisse, Objectivity, ObjectStore, Ontos, O2, Poet, Versant.
, UniSQL, - ,
. ,
Illustra Informix ( POSTGRES )
Oracle Oracle 8.
, - Object
Database Management Group , ODMG -
.
: Matisse Versant.
Matisse
MATISSE ADB Inc., - -, C, C++, Smalltalk .
Matisse - .
, ,
. -, , ,
, -.
:
, - - ,
, ;
;
,
: ( )
;
(. );
;
-,
"" .
Matisse .
: ,
, . ,
, , .
, ,
, ( ),
, , .
, - . -,
, .
(dirty reads).
Matisse, ,
, : .
( ) .
: , ,
.
, ,
,
.
.
, , " ",
.
Matisse . ,
EMPLOYEE () supervisor (): MANAGER, Matisse (
) ,
, , . , ,
.
Versant
Versant Versant Object Technology - -, C++, Smalltalk .
-, ,

, , ,
.
Versant - , ODMG. - ,
Matisse,
.
Versant .
. , .
:
, , ,
. ,
() .
: ,
.
, ;
. .
, .
, ,
.
Versant ,
, , . ,
.
Versant ,
. ,
. ,
.

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

. 13.7.
,
:

. 13.8. -
! ,
(" ", , )
-. "- " ?1)
, , , , , - ,
. (
)
= + ,
, , , . ,
- ! .

. 13.9.
-, -
- . ,
, . ,
,
12. :
flights: separate FLIGHT_DATABASE; ...
flight_details (f: separate FLIGHT_DATABASE;
rf: REQUESTED_FLIGHTS): FLIGHT is
do
Result := f.flight_details (rf)
end
reserve (f: separate FLIGHT_DATABASE; r: RESERVATION) is
do
f.reserve (r); status := f.status
end
, .
, , ,
, .
, .
, ,
, , . ,
,
64- , , [Sombrero-Web],

" 4- ( 32-
) 136 . ,
, ".
, .
, -.
: -, ,
-
,
.

. , (
AltaVista, Web Crawler Yahoo),
, .
,
. , , , 80%
(. . , , ),
. :
, ,
. , ,
, : ,
. : ?
- . .
;
, , . ,
-.


- , -
.
,
(" "). :
, .
.
, ,
.
, .
- , : , - .
-
, -.
-: Matisse,
, Versant, .
:
- , ,
.


[Codd 1970]; . , c - [Date 1995] (
, ). [Elmasri 1989].
[Walden 1995] , -
. [Khoshafian 1986] .
-
[Zdonik 1990], ,
" ", . " -
" [Atkinson 1989], ,
-. ,
( ): [Kim 1990], [Bertino 1993], [Khoshafian 1993], [Kemper 1994], [Loomis 1995].
- (Michael Ley)
[Ley-Web]. (Klaus Dittrich)
- http://www.ifi.unizh.ch/groups/dbtg/ObjectDB/ ODBminiFAQ.html. [Cattel 1993]
ODMG. ( ) -

[Stein 1995].
( Richard Bielak), ,
, -, Versant Sombrero. Versant [Versant 1994],
Matisse - [ADB 1995] (. http://www.adb.com/techovw/features.html). . (Shel
Finkelstein) Matisse. O2 [Banchilhon 1992]. Sombrero
[ Sombrero -Web]
.
, , [M 1996c].
, - , ,
1995 . TOOLS USA European Software Engineering Conference [M 1996d].

13.1

, , , ,
.
13.2 -

, -.
1)

(oxymoron) - ( , ).

-
14. : -
.
, ( )
, .
, , ,
, , . GUI,
Graphical User Interface ( ), .
- WYSIWYG (What You See Is What You Get ( , )), WIMP (Window s, Icons, Menus, Pointing device
(, , , )) " " - ,
, , . ,
, ,
. , ,
, .
, ,
: , .
.
, .
. , GUI , . - ,
; , , . , .
- .
. GUI ,
.

.
, , , .
"?". " ", - , " , ".
Unix'. ( " "
Unix.)


?
,
. "" (
) . , ,
, , .
, , , . ,
"" :
,
.
- , .
, . , :
.
,
.
, ,
.
, GKS PHIGS.
, (, Windows API, Xlib API Unix' Presentation Manager API
OS/2) , ,
"", , Motif.
, ,
. .
. , Motif,
,
, XmPushButtonCallbackStruct ,
Button B , back - b . C
. API Windows
.
- , . ., -
( ).

.
. Motif, Windows Presentation
Manager, , . . ,
Windows PM , Motif
, "" .
( PM
). .
, " "
, - .
,
.

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

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


,
. ,
. :
"" , , Microsoft Windows, (
). : ,
, "" .
, ,
:

. 14.1.
ISE,
. (Vision) ,
- , WEL Windows, ""
.
WEL ,
: Vision WEL Windows,
MEL Motif . . .
.
, C,
-, , WEL.
(. 6).
:
.
, , ,
, , Vision.
(,
, Windows NT),
.
.
? .
(" "),
, .
, . - :
,
, .
. - : ,
, ,
, . ,
, ,
.
.
, , .
. , . ,
(, WEL) .
, , .
, "" ,
. , ,
.
( ISE ) (. 16
" - "). .
, m, , , MENU.
, , , ,
, . . , , WEL_MENU.
, wm.
:
wm ?= m
if wm = Void then
... Windows! ...
else

... wm Windows WEL_MENU ...


end
, Windows. , , -
, . ,
.
.


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

. 14.2.
- WORLD, FIGURE, WINDOW, DEVICE - ,
,
, . ()
( ).
. 14.2 : (), () ().
, ,
. -
. ( ). (
.)

: .
, . ;
( ) - , .
-
: , - , -
.
, ( x
y ) ( ).
.

,
( x y ) ,
. , ,
, .
, , ,
.

, WINDOW TWO_WAY_TREE,
. :
(-), ( ) . .
( ):

14.1.


go
pan

place_proportional
place_pixel

move_proportional
move_pixel

_proportional
, ( go pan,
_pixel). .

, , FIGURE,
display (), hide (), translate (), rotate (),
scale ().
, , (, ,
) . , :
COMPOSITE_FIGURE, FIGURE
, LIST [FIGURE].


, .

: ,
( - ,
), .
,
. , ( ),
, :
... ...
print (", , xxx.")
read_input
xxx := value_read
... ,
...
, : ,
, , - ,
, . ,
.
- . ,
, , ,
. .
, .
( EVENT) , , , ,
, . . .
, ,
raise(e).


GUI " ": , ,
, . OK.

. 14.3.
- . ,
, , , :
. ,
.
, ,
. , ,
. - , .
- , . . ,
.
.
- " ()?" IN (uio),
uio - .
c not c ; not IN (uio) OUT (uio).
ANYWHERE , NOWHERE .
, ANYWHERE
IN(uio) uio. ,
,
. , not c c ( , c
).


, .
.

.
3 Undo. ,
, ,
Undo, .
exit_label, .

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

, -- (Context-Event-Command-State) .
, - .
, , :

. 14.4.
; ,
, , Save, OK.
:

. 14.5.
-: OK Cancel
. "", , ,
, . . ,
, , .
:
; -
. .
, , .
Vi, Unix.
, ( ),
( , ,
. .). , Vi .

( ,
) ,
. , x ,
, , i , R
. , , z
( - ).
, , - Vi, "save" "restart".
,
, . ESCAPE
.
,
, .

. 14.6. Vi
,
. Smalltalk [Goldberg 1981]
" !"( "Don't mode me in!"). ,
,
( ,
).
.
, . " "
, , ,
. ,
(,
).
, , ,
. ,
- ,
.
STATE ();
, , ,
, , ,
, .

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

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


, ,
, ,
(currying).
,
, ,
-, , , " " 1),
[M 1995e].


, ,
Build ISE, [M 1995e],
.
1) , , , CD. ,
. ,
- , ,
. . x.f(a) x f(a)
F(x,a), f(a) =
curry(F(x,a)). - . .

-
15. : OO- Ada
70- ,
Algol 60 Algol W Pascal .
, . ( "
" - .) ,
. . Modula-2, Pascal,
- Algol W,
Pascal () Oberon. CLU MIT , ,
-. Mesa, Xerox,
. ,
Carnegie-Mellon University Alphard . - Ada,
, ( ),
. Modula-2, , ,
.


Ada 70- ,
(DoD). , Ada,
, 450 ,
. ,
, , .
COBOL, 50- DoD,
. -
. , - , ,
, 1979 , , Green,
(Jean D. Ichbiah) CII-Honeywell Bull.
1983 ANSI.
Ada ( Green) .
.
.
, - -
. Algol 60 , Ada
, .
Ada , Ada 95,
. Ada
Ada 83, .
Ada ? , . , :
"" Ada
.
, NASA
. , -
, - .
, , ,
, , Ada .
Ada -. ,
Simula 67 - -. , ,
- , ,
, .
, , . , , DoD.
, - JOVIAL (
60- .). Pascal,
. Ada , ,
, . , Ada,
DoD ,
, (post-Ada)
.
Ada , , - 80- 90- .
, Ada.
, Ada, ,
, , ,


. Ada , - Modula-2 Mesa, -
CLU.
- , . , -
. , ,
. (,
...) ,
. :
Ada , ,
- , ( )
. ,
, .
.
Ada - . .
, :
( );
, , ;
, , ,
, ;
.
.
, , Ada.


Ada .
, "" "". -
, (
), "".
: , ,
. , ,
, :
function item (s: STACK) return X;
, ,
.

, , . ,
package () ; , ,
package body ( ).
package REAL_STACKS is
type STACK_CONTENTS is array (POSITIVE range <>) of FLOAT;
type STACK (capacity: POSITIVE) is
record
implementation: STACK_CONTENTS (1..capacity);
count: NATURAL := 0;
end record;
procedure put (x: in FLOAT; s: in out STACK);
procedure remove (s: in out STACK);
function item (s: STACK) return FLOAT;
function empty (s: STACK) return BOOLEAN;
Overflow, Underflow: EXCEPTION;
end REAL_STACKS;
: STACK - ,

STACK_CONTENTS, STACK,
( ) .
(, ,
).
:
STACK STACK_CONTENTS,
, .
.
, . STACK .
,
, - , -
. ,
-: s,
(. ).
, .
count STACK 0.
, () .
, .
Ada: POSITIVE NATURAL
INTEGER, , ,
, array (TYPE range <>), <> Box-,
.
TYPE. STACK,
[1..capacity] POSITIVE. STACK .
STACK capacity,
:
s: STACK (1000)
Ada in, out in out,
( ,
, ). in.
, Overflow Underflow. -
, - .
,
. Ada .

, :
s: REAL_STACKS.STACK (1000);
REAL_STACKS.put (3.5, s); ...;
if REAL_STACKS.empty (s) then ...;
Ada ,
REAL_STACKS, .
( " " )
REAL_STACKS. - .
:
use REAL_STACKS;
, :
s: STACK (1000);
put (3.5, s); ...;
if empty (s) then ...;
, , ,
(, use).
Ada use,
: , empty (s),

empty ( REAL_STACKS). -, s.empty,


s.
- - : ,
. , , - .

REAL_STACKS .
.
package body REAL_STACKS is
procedure put (x: in FLOAT; s: in out REAL_STACK) is
begin
if s.count = s.capacity then
raise Overflow
end if;
s.count := s.count + 1;
s.implementation (count) := x;
end put;
procedure remove (s: in out STACK) is
... remove ...
end remove;
function item (s: STACK) return X is
... item ...
end item;
function empty (s: STACK) return BOOLEAN is
... empty ...
end empty;
end REAL_STACKS;
, , :
( ).

, , . FLOAT,
. , Ada :
generic
type G is private;
package STACKS is
... , , FLOAT G ...
end STACKS;
generic , -
(class C [G]...), . , , generic,
, . B
.
generic , FLOAT G.
is private G .
, ,
Ada: , ,
, .
.
Ada . , limited
private, .
, , STACKS,
, ;
, .
:
package REAL_STACKS_1 is new STACKS (FLOAT);
- Ada . -

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

:
STACKS , , .
STACK STACK_CONTENTS, ,
. , :
[1]
use REAL_STACKS_1;...
s: STACK; ...
s.implementation (3) := 7.0; s.last := 51;
.
. ?
.
Ada
, .
:
. .
REAL_STACKS_1 ( STACKS, REAL_STACKS_1
), .
:
use REAL_STACKS_1;...
s1, s2: STACK; ...
s2 := s1;
, STACK.
STACK STACK_CONTENTS.
, Ada:
- , - .
: ,
, , . -
, private. , ,
. ,
:
generic
type G is private;
package STACKS is
type STACK (capacity: POSITIVE) is private;
procedure put (x: in G; s: in out STACK);
procedure remove (s: in out STACK);
function item (s: STACK) return G;
function empty (s: STACK) return BOOLEAN;
Overflow, Underflow: EXCEPTION;
private
type STACK_VALUES is array (POSITIVE range <>) of G;
type STACK (capacity: POSITIVE) is
record
implementation: STACK_VALUES (1..capacity);
count: NATURAL := 0;
end record
end STACKS;
, STACK : ,
private, , .
s: REAL_STACK ,
, . , private,

: ,
.
, STACK_VALUES .
.
, , ,
. STACKS
, [1], ,
.
STACK,
. .
( Ada , short,
.) ,
. , ,
, .
, , (
, , ):.
, ,
.
.

STACKS : Overflow Underflow. Ada


, ,
.
Ada 12 "
- ",
Ada .

Ada ,
. ,
- , :
action1;
if error1 then
error_handling1;
else
action2;
if error2 then
error_handling2;
else
action3;
if error3 then
error_handling3;
else
...
Ada - ,
"" , , .
Ada . , ,
.
- , - .

, ,
:
action1;
if error1 then raise exc1; end;
action2;

if error2 then raise exc2; end;


action3;
if error3 then raise exc3; end;
...
raise exc ,
(exception handler),
:
exception
when exc1, ...=> treatment1;
when exc2 ...=> treatment2;
...
exc
- , ,
raise, , . 15.1:

. 15.1. ( 12 " ")


, exc, exc when (
when others). (
=>),
. (Ada .)
exc, ,
, , , .

Ada ,
, .
.
.
when, - EXCEPTIONS.
,
retry. Ada
goto .
,
. ,
" ", , ("
"). Ada ,
,
.
:
Ada

Ada
raise, .
Ada - ,
.
.
raise some_exception
, ,
. . STACKS .
Overflow,
Underflow. Underflow, , remove item
? , ,
. , ,
, . :
[2]
use REAL_STACKS;
procedure proc (...) is
s: STACK; ...
begin
... remove (s); ...
exception
when Underflow => action1;
...
end proc;
, . when Underflow
. , , :
[3]
if not s.empty then s.remove else action1 end
( , ). [2], ,
[3] :
action1 , ;
.
if... then... else...,
, , ,
. ,
, .
, , remove,
.
.
, .
,
. rescue/retry, , ,
. Ada
.
, . , ,
. ,
- , .
, , .
,
.

, Ada - . -
Ada .
, .
, .

, . , -
, , .
( )
.
, . ,
(entry). , , ,
, :
task BUFFER_MANAGER is
entry read (x: out G);
entry write (x: in G);
end BUFFER_MANAGER;
( , G ,
.) : accept,
, .
, , , read write
, read , , write - .
,
- - .
. , Ada -,
, - (,
accept .)
- , ,
,
. , - ,
...

Ada 83 Ada 95
Ada 95 -.
( ), .
- Ada 95:
Ada 95.
. (
Ada 95), , ACCOUNT,
(tagged). , , -, ,
, - . , new
.
(null record, , end).
package Accounts is
type MONEY is digits 12 delta 0.01;
type ACCOUNT is tagged private;
procedure deposit (a: in out ACCOUNT; amount: in MONEY);
procedure withdraw (a: in out ACCOUNT; amount: in MONEY);
function balance (a: in ACCOUNT) return MONEY;
type CHECKING_ACCOUNT is new ACCOUNT with private;
function balance (a: in CHECKING_ACCOUNT) return MONEY;
type SAVINGS_ACCOUNT is new ACCOUNT with private;
procedure compound (a: in out SAVINGS_ACCOUNT; period: in Positive);
private
type ACCOUNT is tagged
record
initial_balance: MONEY := 0.0;
owner: String (1..30);
end record;
type CHECKING_ACCOUNT is new ACCOUNT with null record;
type SAVINGS_ACCOUNT is new ACCOUNT with
record
rate: Float;
end record;
end Accounts;

- . - - .
. ( -, deposit .
. ACCOUNT, compound - SAVINGS_ACCOUNT,
.) , , -
; . ,
,
.
.
,
. ,
.
balance SAVINGS_ ACCOUNT .
withdraw deposit . , , Ada 95
- .
( redefine), . ,
balance SAVINGS_ACCOUNT ACCOUNT,
. ,
, , .
abstract, .
abstract, .
, , .
, , ,
, FIGURE . Ada, ,
FIGURE, " ",
FIGURE. .
, :
procedure print_balance (a: in ACCOUNT'Class) is
-- .
begin
Put (balance (a));
New_Line;
end print_balance;
. "
" (classwide operation) 'Class .
C++ "".
.
Ada 95 " " A1.B A.
A . ( ,
, , .)
, , , Accounts.Checking
CHECKING_ACCOUNT , Accounts.Saving SAVINGS_ACCOUNT.
Ada 95 :
Ada 95 ,
. , ,
, .
- . Ada 83
. -,
, , Ada 95 , ,
:
, , , ,
: ( , ,
private);
, ,
,
;

, , ;
, , (
) ;
" " (, ),
, , :
protected type ANOTHER_ACCOUNT_TYPE is
procedure deposit (amount: in MONEY);
function balance return MONEY;
private
deposit_list: ...; ...
end ANOTHER_ACCOUNT_TYPE;
. , ,
, Ada use with. :
"" , with
. with
.
:
.
, . ?
, , Ada, Ada 95
.
:
9X [ Ada 95]... 9X
60000.
, , . Ada 95 ,
, .
:
Ada 95 , Ada 95
. Ada,
, , .
Ada 95 , SAVINGS_ACCOUN,
(Accounts), .
, , , ,
.
. ,
.
, Ada 95, , "
". ,
Simula, - , .
, ,
, .
- Ada
Ada 95 . , - Ada .
. Ada
-, .
:
, Ada 95,
, Ada,
. , .
, , , C C++.
, ( with
use ), , ,
.
, .
, , ,

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


Ada, " ",
Modula-2, - ( ).
: .
.
""
- , .
- . .
.
,
.
Ada ;
,
.
, , ,
.
Ada 95 ,
, .


[Booch 1986a] ( "-", , . .)
Ada.
Ada [ANSI 1983]
. .
, : [Mitcell 1979] - Mesa, [Wirth 1982] Modula-2, [Liskov 1981, Liskov 1986] - CLU, [Shaw 1981] - Alphard.
Ada 95 [Feldman-Web].
Ada 95, ,
. .

15.1 ,

Ada, ,
-,
. , - :
C, C,
-. ,
. C - , .
, , , -
, private Ada. (: ,
, : ,
, -
, _ .)
.
Ada?
15.2

Ada , .
- . (. .)
15.3 ( Ada)

COMPLEX Ada. , .
15.4 Ada

( Ada.) Ada 83,


, ,
( ), .
15.5 -

( Ada 83.) ,
Ada 83, , , ,
, , .

-
16. : -
Fortran, Cobol, Pascal, C, Basic, PL/I
. , , , .
, , , , , . ,
, - , ,
, .
, . ,
Fortran, Pascal C, . Ada
. -, Simula, Smalltalk, Objective-C, C++
Java. : , , , Basic Cobol,
; -
.


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

, . .
Ada.
-. , .
2 " - ",
, ,
.
, ,
, , ,
, .
, , ,
" ". " " " ".
. " " ,
,
Lisp, , , ,
.
"". " "
, .
" " " -"! "" "", "".
-, , .
-. - "
". ,
, . ,
-, . ,
- put, remove, item, empty, .
, .
, , ,
. .

- Pascal?
Pascal, 1970. ,
.
Pascal - .
Pascal
- Pascal?
, . Pascal .
Pascal , : ,

, , , ( ) .
.
. -
. , ADT, , , :
, , , , ,
, . Pascal
: , . .
-. Pascal
:
.
, Pascal, ,
.
Pascal
Pascal
, .
, . , Pascal,
Pascal. , ,
Modula-2 Ada, .
- Pascal
- Pascal, "Object Pascal".
:
Apple, , Clascal
Macintosh , - Lisa;
Borland Pascal, Borland Delphi.
, Pascal ,
. , Borland Pascal - -
. , ,
.

Fortran
FORTRAN .
FORTRAN: , IBM, , 1954
Fortran -
. , ""
Pascal, Fortran -, ,
.

Fortran IBM 704 IBM
( Algol).
1957 . Fortran II, . Fortran IV 1966
ANSI (Fortran III ).
Fortran 77, 1978 , .
Fortran 90 Fortran 95, -
.
Fortran .
Fortran , "-", " ",
"-", " ", Fortran
, .
, ,
Fortran , . , - .
( ,
, )
.
, ,
. ,

. ,
, , . ,
, Fortran.
COMMON
Fortran .
?
, COMMON,
(, put . . ) .
COMMON - Fortran, ,
. put :
SUBROUTINE RPUT (X)
REAL X
C
C
X
C
COMMON /STREP/ TOP, STACK (2000)
INTEGER TOP
REAL STACK
C
TOP = TOP + 1
STACK (TOP) = X
RETURN
END
( ). ,
:
INTEGER FUNCTION RITEM
C
C
C


COMMON /STREP/ TOP, STACK (2000)
INTEGER TOP
REAL STACK
RITEM = STACK (TOP)
RETURN
END

. REMOVE
. - STREP - ,
.
: ( ),
, . Fortran
: ( 2000 - ).
, ,
. RPUT RITEM, R Real. ,
.

, COMMON, , .
, , .
( ) ,
Fortran 77 - .
, , , , -.
, ,
. .
, SAVE
. , :
, , .
, - SAVE,
- - , RETURN:
ENTRY (arguments)

... ...
RETURN
, COMMON,
. 34.1 .
:
LOGICAL OK
REAL X
C
OK = MAKE ()
OK = PUT (4.5)
OK = PUT (-7.88)
X = ITEM ()
OK = REMOVE ()
IF (EMPTY ()) A = B
, , , , , ,
, !
Fortran , . ,
EMPTY ITEM , ,
MAKE, .

16.1. Fortran
C
C
C

--
--

C
C

--
ENTRY REMOVE (X)
IF (LAST .NE. 0) THEN
REMOVE = .TRUE.
LAST = LAST - 1
ELSE
REMOVE = .FALSE.
END IF
RETURN

INTEGER FUNCTION RSTACK ()


PARAMETER (SIZE=1000)
C
C
C

--
REAL IMPL (SIZE)
INTEGER LAST
SAVE IMPL, LAST

C
C
C

--

C
C
C

LOGICAL MAKE
LOGICAL PUT
LOGICAL REMOVE
REAL ITEM
LOGICAL EMPTY

C
REAL X
C
C
C

--
ENTRY MAKE ()
MAKE = .TRUE.
LAST = 0
RETURN

C
C
C

--

C
C
C

ENTRY ITEM ()
IF (LAST .NE. 0) THEN
ITEM = IMPL (LAST)
ELSE
CALL ERROR
('ITEM: EMPTY STACK')
END IF
RETURN
-- ?
ENTRY EMPTY ()
EMPTY = (LAST .EQ. 0)
RETURN

C
END

--
ENTRY PUT (X)
IF (LAST .LT. SIZE) THEN
PUT = .TRUE.
LAST = LAST + 1
IMPL (LAST) = X
ELSE
PUT = .FALSE.
END IF
RETURN

Ada Modula-2
, , Fortran. , :
: -
, -
Fortran - .

, , .
.
.
Fortran
.
, , ,
.

- C
C . , ,
, - , (C++, Objective-C, Java). , -.

C AT&T's Bell Laboratories .
Unix , .
1970 . . BCPL. ,
( , Algol Pascal), -
(- , )
( - ).
. 70- Unix ,
. 80- . , lingua
franca ( ), , Basic, , Pascal.
Unix , .
.
, , ,
, .
,
1980 . ( Algol)
, : Fortran , Cobol PL/I IBM.

. ,
-, . ( ,
, .)

. C++ Objective-C.
.
: ( ),
(, ),
, .
ANSI 1990 . K&R (
- ).
- - .
, ,
. , ,
C++ Java.
, , , C++ Java, - , ,
. -, , .
, , , , -
- . ,
( ,
, , ).

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

"include" ( ):
#include <header.h>
header.h - (h - ).
. , , ,
,
.
, , .
, Ada
.

, -
- .
,
, .
" , ". ,
, . !
"" ( Pascal) .

. 16.1.
, REAL_STACK :
typedef struct
{
/* */
void (*remove) ();
void (*put) ();
float (*item) ();
BOOL (*empty) ();
/* () */
int count;
float representation [MAXSIZE];
}
REAL_STACK;
{...} ; float ;
void; /* *?/. *?
. , ,
, ,
&. , -, .
REAL_STACK - , -
.
, .
,
. , my_stack , C_remove - ,
, remove my_stack :

my_stack.remove = C_remove
remove .
C_remove :
C_remove (s)
REAL_STACK s;
{
... remove ...
}
remove my_stack:
my_stack.remove (my_stack)
, rout, n , C_rout
n+1 . -:
x.rout (arg1, arg2, ..., argn)
:
x.C_rout (x, arg1, arg2, ..., argn)

.
.
, . 16.1.
.
, .
, .
, ,
. .
: n*m n+m, n - , m - ,
. 16.2.

. 16.2. C,

, .
.
-, Objective-C C++ 80-. ,
, ,
-.
, , (
), , , .
. , ,
.
f x.f (...)
( -). :
, .
- . . 16.2
type.
OO C:
, -. ,
. Fortran, -
. - " " ( BCPL PL/360,
), , .
-.
- ,
. ,
: , -
. , .


Fortran, , [M1982a].
, COMMON, ,
-, , .
,
.
.
, Fortran ,
, .
[Cox 1990] C -.
[Wexelblat 1981], .
[Knuth 1980].

16.1 ( Fortran)

Fortran ,
(, , ).
GKS.
16.2 ( C)

"real stack" ,
G, float?
16.3 - C ( )

- , .
, , ,
.
:
,
;

, ;
, , .

-
17. : Simula Java : -
Simula, 1967 ., - , .
, : Simula, Smalltalk, C++ - C, Java.
- . .
. - , , ,
. , , -
, . :
, , (, Simula) . ,
,
. .
"" , .
, ( ), . , ,
Simula, Simula - ,
.

Simula
Simula - ( ). (
) 1967 . , , :
- ,
, " ".
, - ,
, , , , ,
.

Simula, , . 60- , Simula 1,
. - ,
. Simula - Simula 67, 1967 . (Kristen Nygaard, Ole-Johan Dahl)
(Norsk Regnesentral). ,
. ,
,
, , Simula 67 -
. -
SIMULATION, Simula.
Simula 1986 ., 1987 .

Simula , .
, .
Simula (Simula Standards Group). ,
.

Simula. ,
Smalltalk. , Simula.
, , ,
.
Simula - - Algol 60. Algol
Simula. , , Algol: , ,
( case Pascal). (, . .)
Algol.
Algol, Simula ,
. - , (
). Simula .
Simula Algol 60: , ,
.
Simula . ,
, , , SIMULATION, .
, , ,
, . , .

ref(C), C, C.
, (:-, ==, =/= ),
(:=, =, /=).
.
new, :
ref (C) a; ...;a :- new C
new C . (
):
class C (x, y); integer x, y
begin ... end;
new :
a :- new C (3, 98)
.
(), .
, , .
, new . , ,
, -, ,
.
. Simula . B
A:
A class B;
begin ... end
, .
( redefine ).
Simula 67 . ,
, protected, . , hidden,
. ,
.
" ", virtual
. , ,
. ,
POLYGON :
class POLYGON;
virtual: procedure set_vertices
begin
...
end
POINT set_vertices: - TRIANGLE,
- QUADRANGLE . . .
C++ : ++ Simula,
virtual. ++ ,
( , ++,
). Simula " " C++.
Simula : B - A, a1 :- b1 a1 A b1 B.
, : b1 a1,
, -
. , ,
, ( ).
, . f - ,
A, a1.f A f , B.
qua1), :
(a1 qua B). f
, .
( Simula),

.
, .
Simula , .
qua, inspect
a1, ,
A, a1:
inspect a1
when A do ...;
when B do ...;
...
, ,
-.

Simula.
, 2.
class STATE;
virtual:
procedure display;
procedure read;
boolean procedure correct;
procedure message;
procedure process;
begin
ref (ANSWER) user_answer; integer choice;
procedure execute; begin
boolean ok;
ok := false;
while not ok do begin
display; read; ok := correct;
if not ok then message (a)
end while;
process;
end execute
end STATE;
class APPLICATION (n, m);
integer n, m;
begin
ref (STATE) array transition (1:n, 0:m-1);
ref (STATE) array associated_state (1:n);
integer initial;
procedure execute; begin
integer st_number;
st_number := initial;
while st_number /= 0 do begin
ref (STATE) st;
st := associated_state (st_number); st.execute;
st_number := transition (st_number, st.choice)
end while
end execute
...
end APPLICATION

- Simula - .
. .
, .
, . ,
, , . ,
, .
:
from some_initialization loop forever
" "; " "
end

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

. 17.1.
, .
, "-",
, .
, .
.
Simula . ,
, . ,
Simula . , ,
( ).
. -
while continuation_condition do begin
... ...;
resume other_coroutine;
... ...
end
continuation_condition True,
( , ).
, , , , :
corout1 :- new C1; corout2 :- new C2; ...
resume corouti
new .
( ) .
new , , .
. new ,
- C2 C1.
Simula detach. detach,
, new. detach (
, ), . detach
, , , .

, .
, .
( ,
). in n- , :
i1
i7

i2
i9

i3
i10

i4
i11

i5
i6
i12
i13

i14

i15

i17

. .

, 1000 .
. ,
: , , ,
, 1000 .
. , , .
: producer (), printer () controller. :
begin
class PRODUCER begin ... . ... end PRODUCER;
class PRINTER begin ... . ... end PRINTER;
class CONTROLLER begin ... . ... end CONTROLLER;
ref (PRODUCER) producer; ref (PRINTER) printer;
ref (CONTROLLER) controller;
producer :- new PRODUCER; printer :- new PRINTER;
controller :- new CONTROLLER;
resume controller
end
, . - . :
class CONTROLLER; begin
integer i;
detach;
for i := 1 step 1 until 1000 do resume printer
end CONTROLLER;
class PRINTER; begin
integer i;
detach;
while true do
for i := 1 step 1 until 8 do begin
resume producer;
outreal (producer.last_input);
resume controller
end;
next_line
end
end PRINTER;
class PRODUCER; begin
integer i; real last_input, discarded;
detach;
while true do begin
for i := 1 step 1 until 6 do begin
last_input := inreal; resume printer
end;
discarded := inreal
end
end PRODUCER;
detach,
. inreal , , outreal ,
next_line .
- . ,
: , . Producer
, printer - , controller - , . ,
;
, ( ).
, -.
. ,
. ,
(, last_input producer). , ,
. ,
. , ,
.

Simula (detach, resume),


( )
. ,
. Simula, ( ,
; , ),
.
bodyC - , C, actual_bodyC -
, C. C , actual_bodyC -
bodyC . C A (, ), actual_bodyC -
:
actual_bodyA ; bodyC
, . , ,
, . , , Simula inner,
.
, inner . A :
instructions1 ; inner; instructions2
, , A , actual_bodyC :
instructions1 ; bodyC ; instructions2
, :
, ( POLYGON
RECTANGLE);
, , C, : bodyC
, new;
(
Simula).
inner - , .
- Simula inner
.

Simula . ,
, - .
.
: ,
, .
,
, , .
,
. ,
- ( ), ,
.
,
, .
-
.
, , . , ,
, ,
. .
.
, , ,
, , ,
.
. ( , , , )
? ?
?
- .

, .
, .
.
, .
. -
, . Simula time
.
time SIMULATION,
. " " ,
SIMULATION.
Simula : , : C begin... end
, C. SIMULATION
, . " ".
SIMULATION PROCESS. ( , Simula
.) - - PROCESS,
" ", - "". PROCESS
. (
, PROCESS - Simula, LINKABLE).
:
- ;
- ;
- , ;
.
( SIMULATION) (event list),
(event notices). -
<process, activation_time>, activation_time process. (
, "" " ",
- , time.)
activation_time; , . ,
, .

. 17.2.
- , ,
.
SIMULATION, , activate
reactivate. ( ,
activate .) :
activate some_process scheduling_clause
some_process - PROCESS. scheduling_clause
:
at some_time
delay some_period
before another_process
after another_process
, ,
max (time, some_time) at max (time, time + some_period) delay.
,
, prior.
. scheduling_clause
delay 0.

, - some_process.
reactivate. ,
. ,
3 (180 .), - worker - :
reactivate worker delay 180
, ,
:
hold (180)
.
, , , .
. hold (some_period)
( , , resume) :
-- :
my_new_time := max (time, time + some_period)
create my_reactivation_notice.make (Current, my_new_time)
event_list.put (my_reactivation_notice)
-- :
next := event_list.first; event_list.remove_first
-- , :
time := time.max (next.when); resume next.what
:
my_new_time: REAL; my_reactivation_notice, next: EVENT_NOTICE
class EVENT_NOTICE creation make feature
when: REAL - ..
what: PROCESS
make (t: REAL; p: PROCESS) is
do when := t; what := p end
end
, ,
.
, () .
, ,
, , . ,
hold (0) resume,
, .

.
, .
; m, 5 , ,
.
PROCESS class WORKER begin
while true do begin
" i d";
if i = 2 then
activate m delay 300; reactivate this WORKER after m;
end;
hold (d)
end while
end WORKER
" "
, . Simula
. , m -
MACHINE, .
.
Simula:
Algol 60, Simula ,

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

Smalltalk
Smalltalk 1970 . ,
, . Algol
60, . ( Algol , , Simula.) ,
, Algol ,
. Xerox Palo Alto Research Center - PARC,

. Smalltalk Xerox PARC . .
(Adele Goldberg, Daniel Ingalls).
Smalltalk-72 Smalltalk-76, Smalltalk-80. -
Xerox, . Smalltalk
.

Smalltalk Simula , Lisp.
, , .
. , ,
.
Smalltalk . "",
" " (
).
Smalltalk
. Smalltalk - , .
, .
, , object. ,
, - class. :
: Smalltalk , .
: ,
, ,
.
: , , .
, new,
.
, ,
.

Smalltalk ( ): ,
. :
acc1 balance
balance , acc1. acc1.balance,
Simula . , , .
:
point1 translateBy: vector1
window1 moveHor: 5 Vert: -3
, . Smalltalk
, ,
translateBy moveHor. Simula point1.translate
(vector1) window1.move (5, -3).
, Ada ,
" " . ,
, , 2+3, :

2 addMeTo: 3
Smalltalk . :
. a + b * c , - (a + b) * c.
. ,
window1 height + window2 height .
Simula Smalltalk ().
, , , .
:
x | |
xx
y | |
yy
scale: scaleFactor | |
xx <- xx * scaleFactor
yy <- yy * scaleFactor
x y () xx yy. ,
- , .
scale scaleFactor. | | ,
.
- Smalltalk, ,
.
, Smalltalk ,
, super, :
aFunction: anArgument |...|
... super aFunction: anArgument ...
, Precursor, .
Smalltalk - . , ,
, ,
.
, : Smalltalk
, , ,
.
, x f ( x.f) , ,
f. C , ,
C, Smalltalk
, , FIGURE rotate :
rotate: anAngle around: aPoint | |
self shouldNotImplement
shouldNotImplement . self
.

Smalltalk .
. Xerox PARC,
Smalltalk. , , ,
, - Palo Alto .
-, , - Smalltalk.
Simula, . Smalltalk-80
, , ""
"", .
,
Smalltalk. Smalltalk
, . ,
. , , Smalltalk,
. , ,
, Smalltalk.

Smalltalk:
Smalltalk , ,
Simula , .
Simula ; Smalltalk
Byte 1981 . .
, Smalltalk , 90-
. , "
":
" ". ,
, , , , C++.
,
-: Smalltalk. Smalltalk - , " " C
C .
Lisp. Lisp ( Prolog ,
) ,
. 70-, , Lisp ; Smalltalk
.
Smalltalk. Smalltalk -
, (
, Delphi Borland Visual Basic Microsoft).
. ,
, , -
, , ,
. .
: , , Smalltalk .

Lisp
, Lisp -. Simula Smalltalk
- Lisp . , Lisp
, -,
, .
:
;
;
;
, , , Interlisp 70- .
;
, .
Lisp - , C, Pascal Ada. "",
- , Lisp.
- Lisp, Prolog , . Lisp-
, - , " -"
" ". -
(), (), Smalltalk-
Lisp- .
. ,
.
80- . Lisp: Loops, Xerox
Interlisp, Flavors, MIT, Lisp-
, Ceyx, INRIA. Loops ",
", ( ).
, ,
. , ,
.
Common Lisp (Common Lisp Object System CLOS),
-, ANSI.

C
1980- .
, -

. , , Objective-C,
- C++.
"" ,
, - ,
. ( Ada 95 Borland Pascal.)
Objective-C : -
, . C++
, , , . :
, ,
.
,
. - - -
"" . , , C
Fortran, Ratfor, 70- . "
", .
Objective-C
Stepstone ( Productivity Products International) (Brad Cox)
Objective-C Smalltalk C.
NEXTSTEP. C++ , Objective-C
.
Smalltalk, , Objective-C
, . Objective-C:
= Proceedings: Publication {id date, place; id articles;}
+ new {return [[super new] initialize]}
- initialize {articles = [OrderedCollection new]; return self;}
- add: anArticle {return [contents add: anArticle];}
- remove: anArticle {return [contents remove:anArticle];}
- (int) size {return [contents size];}
=:
Proceedings Publication (Objective-C
). (" "). ; self,
Smalltalk, . id
- . , +, " ".
new. , -, " ",
.
Objective-C Stepstone ,
Smalltalk. NEXTSTEP .
C++
C++ 1986 . AT&T Bell Laboratories (,
Unix C).
, .
(
C++).
C++ , - ,
, . , , ""
C++. , C++
"C++ ". .
C++ .
C++ C .
:
class POINT {
float xx, yy;
public:
void translate (float, float);
void rotate (float);
float x ();
float y ();
friend void p_translate (POINT*, float, float);
friend void p_rotate (POINT*, float);
friend float p_x (POINT*);

friend float p_y (POINT*);


};
- . ,
, , .
, , .
- "" . C++
C++ .
, , .
POINT*, POINT.
C++ :
, .
. ,
.
. ( , , .)
, .
,
. C++ .
" " .
, , ().
(-
), .
-
(, - ).
,
.
- downcasting.
- "". : ,
( ++ ).
( ).
assert ,
(, , ), -.
, , MFC (Microsoft Foundation Classes).

C++ , .
.
C C++,
(ANSI), (Dictionary of Standard C) C++. (
++):
, - , .
. ,
- () . -
, . ,
, . void .
. int , , int,
. int int.
, . , , , ,
. ( , : (1) , (2)
, (3) , , (4) , .) , :
, , .
C++ , .
, , ,
, , . ,
, .
- , ++
" ", -
.
C++:
C++ . "Geek Chic",
" ". , , "
++ ".

C++ , "" . :
?
?
(. . .. .)
C++ .
- ,
, -
. C++, , -. C++
, ,
,
. C++ : ,
, , . , ++
, -
- , Unix, ,
Bell. ++ ,
, ,
.
, C++ -, ,
, . C++,
21 , .
++ - .

Java
Sun Microsystems, Java
1996 . , . ComputerWorld ,
Java 1996 . 4325 ( 2-3 ,
). , , 5076
.
Java . ,
. Java- - .
. Java-,
-. -
, . , . ,
-. , , Web-,
.
, Sun
. - Java,
.
- Pascal Ada, ,
, ,
.
Java - , . Java
. - , , 1985 .
++. ++, ,
. ++ ,
, ,
, ,
, .
C++, Java . ++:
, , , , .
, , , :
( , Java assert ++),
,
(, , ). ,
. , ,
:
String [ ] labels = (depth == 0 ? basic : extended);
while ((name = getNextPlayer()) != null) {
, : =,
, , , , . .

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

-
, .
-, .
.
Oberon - - Modula-2, , ,
.
Modula-3, Digital Equipment (DEC Research),
, , Modula-2.
Trellis, DEC Research, ,
.
Sather, , ,
. pSather .
Beta - Simula, (
Simula). pattern , , ,
.
Self , "", ,
.
Ada 95 , Ada.
Borland Pascal - Pascal Pascal.


Simula
[Dahl 1966] Simula, Simula 1. Simula,
Simula 67, [Dahl 1970], Algol 60, Simula.
" " (: , , ) [Dahl 1972]
. 1984 .,
Algol 60. - [SIS 1987]. Simula,
, . [Nygaard 1981].
Simula - [Birtwistle 1973]. . [Pooley 1986].
Smalltalk
Smalltalk (72 76) . [Goldberg 1981] [Ingalls 1978].
Byte, Smalltalk - [Goldberg 1981] - ,
Smalltalk . , [Goldberg
1983], , . [Goldberg 1985],

Smalltalk, VisualWorks [Hopkins 1995];


[Lalonde 1990-1991].
Simula Smalltalk ("Algol ")
TWA Ambassador (, ), - 80-.
, Lisp Smalltalk.
C: Objective-C, C++
Objective-C [Cox 1984] [Cox 1990] ( 1986 .).
-, Objective-C [Pinson 1991].
C++. (. [Stroustrup 1994].)
[Stroustrup 1984], [Stroustrup 1986], [Stroustrup 1991],
. - [Ellis 1990].
"C++ " [Joyner 1996], -
-.
Lisp
Loops: [Bobrow 1982]; Flavors: [Cannon 1980], [Moon 1986]; Ceyx: [Hullot 1984]CLOS: [Paepske 1993].

Java
Java . ,
, : [Arnold 1996] , [Gosling 1996] [Gosling 1996a]
.
Java (
), Usenet 1995, . http://java.sun.com/archives/java-interest/0992.html.

Oberon: [Wirth 1992], [Oberon-Web]. Modula-3: [Harbison 1992], [Modula-3-Web]. Sather: [Sather-Web]. Beta: [Madsen
1993], [Beta-Web]. Self: [Chambers 1991], [Ungar 1992].

17.1

Simula (Printer-Controller-Producer), ,
1000 . (: - ,
"".)
17.2

( Simula, , ,
, .) ,
resume .
PROCESS resume hold (0).: ,
.
, .
17.3

-,
. , 17.1.
: resume, ,
resume. 12,
.
17.4

Simula: SIMULATION, EVENT_NOTICE,


PROCESS.
: , .
17.5

super Smalltalk , ,
: Precursor , ,
.
1)

Qua (.) - , , .

-
18. : -
, -
: , ! ! .
OO-. , (
, ). (ISE EiffelStudio),
, -.
(. 18.2). CD, .
, , - . :
( ). OO-.
, , , Borland Delphi, . ,
- . ,
, .


1) :
: -, ;
- , , ;
, : , ,
, ;
.
, .

- , 7-18 " - "


. ,
.

1986 . (1990 .)
, .
, . (
12, separate) Precursor
. , ,
.

,
. external .
Cecil -:
(, ).
C C++. C++ Legacy++,
C++ (wrapper class),
. ,
C++
. Legacy++ .


.

:
C1 ,
C. OO- .
C2 . ,
, . ,
, .
C3 , :
Internet .
. C1 ,
. C2,
" " , (C1)
.


, (Melting Ice
Technology), .
, . , ,
. .
" - " C2. ""
, .
,
. ,
, ! , , :
. - .

. 18.1. "" ""


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

. "" .
, (
). .

, .
Melt Project Tool, , ,
. Make, "include file".
, , ,
. , ,
. , ,
. - -
, .
: ,
.
, .
, , C, .
.

,
, .
, .
.
Ace .
.
. B C A
(, Vision - Net, ,
Base), A .
( .
4). , .
- , ,
.

, , -,
. - (Execution Engine), 3E
.
3E (plug-in) Web-
. 3E , . Java.
3E, .
, -. ,
( ), - .
- - Java,
Java.

C1 . ,
:
, , , ,
. ,
. 50%.
, ,
.
.
, ,
. , ,
, . ,
, , .
, - (finalization),
( ).
, , ,
. - .
, .
.


. 18.2 . , , OO- (
),
, . ,
!
Bench
Bench - , ,
, , . Bench.
, Bench. (
, )
C, .
C. C . C
. ,
. C .
:

C - ,
. ,
.
C , ,
, C, C++ .
C .
, , : ,
, .
- , , , .
. 18.2 , .

. 18.2 .
Build - , --- (. 14).
(GUI) .
Case - ,
. Case
:

. 18.2.
, ("")

. Case ( - forward
engineering).
,
( - reverse engineering).
, .
, , Case
, . Case
, .
,
.
Case BON (. 9). BON (zooming).
, , ,
, .
. 18.3 Case, ,
(VAT) (fill).


. 18.2. ,
( ) .
:
Base, 200 . - ,
, , , , . . Kernel,
(ELKS).
: Vision , WEL
Windows, MEL Motif, PEL OS/2-Presentation Manager.
Net - .
( independent_store
).
Lex, Parse . Parse, , ,
- (
, . ). YOOCC
Parse.
Math - , - .
NAG . 13
" - ", - .

. 18.3. , Case ( Sun Sparcstation Motif,


Windows )
ObjEdit .

Web , Web- CGI-.


. 18.2 , .
STORABLE , , ,
. Store
, (Oracle, Ingres, Sybase) -
.
, .
.
Net, Vision and Store -
. Store , Base,
Math . . , Vision ( ),
.


,
.
. ,
.
(. ).

Sun Sparcstation .
, Windows 95 Windows NT, Windows 3.1, OS/2, Digital
VMS (Alpha Vax) Unix (SunOS, Solaris, Silicon Graphics, IBM RS/6000, Unixware, Linux, Hewlett-Packard
9000 Series . .).
,
, Windows, .
. 18.4 . -,
, .
, - , - .
.

, ,
: , .
, Sun Java Workshop ( 1996 .) ,
.

. 18.4.
. , ,
. . ,
: , ,
. , , ,
. . : "" ""
() , .
, , ,
,
(development objects). (Class Tool),
(Feature Tool), (System Tool), (Project Tool),
(Object Tool) , -: , , (
), ("" ).
Project Tool, , . Melt, Freeze Finalize.
. 18.2 Project Tool , .

. 18.5. Project Tool


Class Tool , , LIST (. 18.6).

. 18.6. Class Tool,


Feature Tool Project Tool (. 18.7)
, (. Project Tool). Feature Tool
call_this_routine TEST.

. 18.7. Project Feature Tool


Object Tool, .
18.8.
. , guardian, ,
, .
Class Tool, Feature Tool Object Tool, , System
Tool Project Tool .

. 18.8.

, Class Tool LIST ARRAY.

( ,
"*" - ARR* ).
pick-and-throw1 (" ") (. 15
" - "). ,
, CHAIN Class Tool LIST, "" (pebble) ,
, . "" (hole) Class Tool ( )
, .
.

. 18.9. pick-and-drop (" ")


pick-and-drop - drag-and-drop.
. , .

(. 18.9). , .
drag-and-drop:
. drag-and-drop
.
,
. ( Windows 95
, . , .)
drag-and-drop ! , - .
pick-and-drop .
, , .
: , RECTANGLE
POLYGON,
. . (
drag-and-drop ,
.)
. pick-and-drop

- .
Class Tool, LIST Base (. 18.10),
. :
class text ( ) ;

ancestors () ;

short form ( ) ;

routines () ;

deferred routines ( )

. . ,
Ancestors (), Class Tool (. 18.10).

. 18.10.
(clickable). ,
CURSOR_STRUCTURE pickand-drop .
, . pick-and-drop Feature Tool
. Feature Tool ,
: , . .
pick-and-drop.
, (. 18.7), pickand-drop. 0X142F18 ( , ,
) Object Tool, PERSON (. 18.8).

, .
.
(HTML, TX, RTF, FrameMaker MML, troff),
.
, .
,
. INTEGER, Class Tool
. , -
. .
, .
Java Workshop
, , , . ,
.
, . INTEGER ,
Java .
, ( , . .),
. , ""
Stop Point.

, "-" (buttonholes), . ,
Stop Point Project Tool .
.
,
. ,
: " ? , , .
?"
, , , . ,
.


[M 1996b], Internet [M-Web]
.
[M 1993] , .
.
[M 1985c], [M 1987b], [M 1987c], [M 1988], [M 1988a], [M 1988d], [M 1988f], [M 1989], [M 1993d], [M 1997]
.
[M 1992]. Reusable Software [M 1994a]
Base.
[M 1994] . [. 1995c] Case , [. 1995e] Build [M 1995e]. [M 1993d].
YOOC Christine Mingins, Jon Avotins, Heinz Schmidt Glenn Maughan Monash University [Avotins 1995]
FTP- Monash University. - Parse [M 1989d]
[M 1994a].
Math [Dubois 1997].
. Eric Bezault (
), Reynald Bouy, Fred Deramat, Fred Dernbach ( ),
Sylvain Dufour, Fabrice Franceschi, Dewi Jonker, Patrice Khawam, Vince Kraemer, Philippe Lahire, Frederic Lalanne, Guus Leeuw,
Olivier Mallet, Raphael Manfredi ( ), Mario Menger, Joost De Moel, David Morgan,
Jean-Marc Nerson ( ), Robin van Ommeren, Jean-Pierre Sarkis, Glen Smith, Philippe Stephan
( ), Terry Tang, Dino Valente, Xavier Le Vourch, Deniz Yuksel.
, .
1) , , , (
) . , , Envision,
Eiffel Visual Studio.Net. ,
. ,
.

Вам также может понравиться