home *** CD-ROM | disk | FTP | other *** search
/ Solo Programadores 22 / SOLO_22.iso / docs / faq / prog / part2 < prev    next >
Mailbox/MIME Entity  |  1996-04-24  |  26.5 KB

open in: MacOS 8.1     |     Win98     |     DOS

browse contents    |     view JSON data     |     view as text


This file was processed as: Mailbox/MIME Entity (archive/mbox).

ConfidenceProgramDetectionMatch TypeSupport
100% dexvert Newsgroup Content (archive/news) magic Supported
100% dexvert Mailbox/MIME Entity (archive/mbox) magic Supported
100% dexvert Internet Message Format (text/imf) magic Supported
1% dexvert Text File (text/txt) fallback Supported
100% file news, ASCII text default
100% checkBytes Printable ASCII default
100% dexmagic PrintFox/Pagefox WEAK default
100% perlTextCheck Likely Text (Perl) default
100% siegfried fmt/950 MIME Email (1.0) default
100% detectItEasy Format: Plain text[LF] default
100% xdgMime message/news default



hex view
+--------+-------------------------+-------------------------+--------+--------+
|00000000| 50 61 74 68 3a 20 73 65 | 6e 61 74 6f 72 2d 62 65 |Path: se|nator-be|
|00000010| 64 66 65 6c 6c 6f 77 2e | 6d 69 74 2e 65 64 75 21 |dfellow.|mit.edu!|
|00000020| 62 6c 6f 6f 6d 2d 62 65 | 61 63 6f 6e 2e 6d 69 74 |bloom-be|acon.mit|
|00000030| 2e 65 64 75 21 6e 65 77 | 73 2e 6b 65 69 2e 63 6f |.edu!new|s.kei.co|
|00000040| 6d 21 6e 65 77 73 2e 6d | 61 74 68 77 6f 72 6b 73 |m!news.m|athworks|
|00000050| 2e 63 6f 6d 21 74 61 6e | 6b 2e 6e 65 77 73 2e 70 |.com!tan|k.news.p|
|00000060| 69 70 65 78 2e 6e 65 74 | 21 70 69 70 65 78 21 6f |ipex.net|!pipex!o|
|00000070| 6c 65 61 6e 65 21 69 6e | 32 70 33 2e 66 72 21 73 |leane!in|2p3.fr!s|
|00000080| 77 69 64 69 72 2e 73 77 | 69 74 63 68 2e 63 68 21 |widir.sw|itch.ch!|
|00000090| 65 70 66 6c 6e 65 77 73 | 21 64 69 6e 65 77 73 2e |epflnews|!dinews.|
|000000a0| 65 70 66 6c 2e 63 68 21 | 4d 61 67 6e 75 73 2e 4b |epfl.ch!|Magnus.K|
|000000b0| 65 6d 70 65 0a 46 72 6f | 6d 3a 20 4d 61 67 6e 75 |empe.Fro|m: Magnu|
|000000c0| 73 2e 4b 65 6d 70 65 40 | 64 69 2e 65 70 66 6c 2e |s.Kempe@|di.epfl.|
|000000d0| 63 68 20 28 4d 61 67 6e | 75 73 20 4b 65 6d 70 65 |ch (Magn|us Kempe|
|000000e0| 29 0a 4e 65 77 73 67 72 | 6f 75 70 73 3a 20 63 6f |).Newsgr|oups: co|
|000000f0| 6d 70 2e 6c 61 6e 67 2e | 61 64 61 2c 63 6f 6d 70 |mp.lang.|ada,comp|
|00000100| 2e 61 6e 73 77 65 72 73 | 2c 6e 65 77 73 2e 61 6e |.answers|,news.an|
|00000110| 73 77 65 72 73 0a 53 75 | 62 6a 65 63 74 3a 20 41 |swers.Su|bject: A|
|00000120| 64 61 20 46 41 51 3a 20 | 50 72 6f 67 72 61 6d 6d |da FAQ: |Programm|
|00000130| 69 6e 67 20 77 69 74 68 | 20 41 64 61 20 28 70 61 |ing with| Ada (pa|
|00000140| 72 74 20 32 20 6f 66 20 | 34 29 0a 46 6f 6c 6c 6f |rt 2 of |4).Follo|
|00000150| 77 75 70 2d 54 6f 3a 20 | 70 6f 73 74 65 72 0a 44 |wup-To: |poster.D|
|00000160| 61 74 65 3a 20 31 37 20 | 4d 61 72 20 31 39 39 36 |ate: 17 |Mar 1996|
|00000170| 20 31 34 3a 32 32 3a 32 | 34 20 47 4d 54 0a 4f 72 | 14:22:2|4 GMT.Or|
|00000180| 67 61 6e 69 7a 61 74 69 | 6f 6e 3a 20 4e 6f 6e 65 |ganizati|on: None|
|00000190| 0a 4c 69 6e 65 73 3a 20 | 36 34 32 0a 53 65 6e 64 |.Lines: |642.Send|
|000001a0| 65 72 3a 20 6d 61 67 6e | 75 73 40 6c 67 6c 73 75 |er: magn|us@lglsu|
|000001b0| 6e 34 2e 65 70 66 6c 2e | 63 68 20 28 4d 61 67 6e |n4.epfl.|ch (Magn|
|000001c0| 75 73 20 4b 65 6d 70 65 | 29 0a 41 70 70 72 6f 76 |us Kempe|).Approv|
|000001d0| 65 64 3a 20 6e 65 77 73 | 2d 61 6e 73 77 65 72 73 |ed: news|-answers|
|000001e0| 2d 72 65 71 75 65 73 74 | 40 4d 49 54 2e 45 44 55 |-request|@MIT.EDU|
|000001f0| 0a 44 69 73 74 72 69 62 | 75 74 69 6f 6e 3a 20 77 |.Distrib|ution: w|
|00000200| 6f 72 6c 64 0a 4d 65 73 | 73 61 67 65 2d 49 44 3a |orld.Mes|sage-ID:|
|00000210| 20 3c 34 69 68 37 37 30 | 24 66 71 32 40 64 69 73 | <4ih770|$fq2@dis|
|00000220| 75 6e 6d 73 2e 65 70 66 | 6c 2e 63 68 3e 0a 52 65 |unms.epf|l.ch>.Re|
|00000230| 70 6c 79 2d 54 6f 3a 20 | 4d 61 67 6e 75 73 2e 4b |ply-To: |Magnus.K|
|00000240| 65 6d 70 65 40 64 69 2e | 65 70 66 6c 2e 63 68 20 |empe@di.|epfl.ch |
|00000250| 28 4d 61 67 6e 75 73 20 | 4b 65 6d 70 65 29 0a 4e |(Magnus |Kempe).N|
|00000260| 4e 54 50 2d 50 6f 73 74 | 69 6e 67 2d 48 6f 73 74 |NTP-Post|ing-Host|
|00000270| 3a 20 6c 67 6c 73 75 6e | 34 2e 65 70 66 6c 2e 63 |: lglsun|4.epfl.c|
|00000280| 68 0a 4d 69 6d 65 2d 56 | 65 72 73 69 6f 6e 3a 20 |h.Mime-V|ersion: |
|00000290| 31 2e 30 0a 43 6f 6e 74 | 65 6e 74 2d 54 79 70 65 |1.0.Cont|ent-Type|
|000002a0| 3a 20 74 65 78 74 2f 70 | 6c 61 69 6e 3b 20 63 68 |: text/p|lain; ch|
|000002b0| 61 72 73 65 74 3d 69 73 | 6f 2d 38 38 35 39 2d 31 |arset=is|o-8859-1|
|000002c0| 0a 43 6f 6e 74 65 6e 74 | 2d 54 72 61 6e 73 66 65 |.Content|-Transfe|
|000002d0| 72 2d 45 6e 63 6f 64 69 | 6e 67 3a 20 38 62 69 74 |r-Encodi|ng: 8bit|
|000002e0| 0a 53 75 6d 6d 61 72 79 | 3a 20 41 64 61 20 50 72 |.Summary|: Ada Pr|
|000002f0| 6f 67 72 61 6d 6d 65 72 | 27 73 20 46 72 65 71 75 |ogrammer|'s Frequ|
|00000300| 65 6e 74 6c 79 20 41 73 | 6b 65 64 20 51 75 65 73 |ently As|ked Ques|
|00000310| 74 69 6f 6e 73 20 28 61 | 6e 64 20 61 6e 73 77 65 |tions (a|nd answe|
|00000320| 72 73 29 2c 0a 20 20 20 | 20 20 20 20 20 20 20 20 |rs),. | |
|00000330| 70 61 72 74 20 32 20 6f | 66 20 34 2e 0a 20 20 20 |part 2 o|f 4.. |
|00000340| 20 20 20 20 20 20 50 6c | 65 61 73 65 20 72 65 61 | Pl|ease rea|
|00000350| 64 20 62 65 66 6f 72 65 | 20 70 6f 73 74 69 6e 67 |d before| posting|
|00000360| 2e 0a 4b 65 79 77 6f 72 | 64 73 3a 20 61 64 76 61 |..Keywor|ds: adva|
|00000370| 6e 63 65 64 20 6c 61 6e | 67 75 61 67 65 2c 20 61 |nced lan|guage, a|
|00000380| 72 74 69 66 69 63 69 61 | 6c 20 6c 61 6e 67 75 61 |rtificia|l langua|
|00000390| 67 65 73 2c 20 63 6f 6d | 70 75 74 65 72 20 73 6f |ges, com|puter so|
|000003a0| 66 74 77 61 72 65 2c 0a | 20 20 20 20 20 20 20 20 |ftware,.| |
|000003b0| 20 20 64 61 74 61 20 70 | 72 6f 63 65 73 73 69 6e | data p|rocessin|
|000003c0| 67 2c 20 70 72 6f 67 72 | 61 6d 6d 69 6e 67 20 6c |g, progr|amming l|
|000003d0| 61 6e 67 75 61 67 65 73 | 2c 20 41 64 61 0a 58 72 |anguages|, Ada.Xr|
|000003e0| 65 66 3a 20 73 65 6e 61 | 74 6f 72 2d 62 65 64 66 |ef: sena|tor-bedf|
|000003f0| 65 6c 6c 6f 77 2e 6d 69 | 74 2e 65 64 75 20 63 6f |ellow.mi|t.edu co|
|00000400| 6d 70 2e 6c 61 6e 67 2e | 61 64 61 3a 34 32 34 37 |mp.lang.|ada:4247|
|00000410| 36 20 63 6f 6d 70 2e 61 | 6e 73 77 65 72 73 3a 31 |6 comp.a|nswers:1|
|00000420| 37 36 31 33 20 6e 65 77 | 73 2e 61 6e 73 77 65 72 |7613 new|s.answer|
|00000430| 73 3a 36 37 31 37 37 0a | 0a 41 72 63 68 69 76 65 |s:67177.|.Archive|
|00000440| 2d 6e 61 6d 65 3a 20 63 | 6f 6d 70 75 74 65 72 2d |-name: c|omputer-|
|00000450| 6c 61 6e 67 2f 41 64 61 | 2f 70 72 6f 67 72 61 6d |lang/Ada|/program|
|00000460| 6d 69 6e 67 2f 70 61 72 | 74 32 0a 43 6f 6d 70 2d |ming/par|t2.Comp-|
|00000470| 6c 61 6e 67 2d 61 64 61 | 2d 61 72 63 68 69 76 65 |lang-ada|-archive|
|00000480| 2d 6e 61 6d 65 3a 20 70 | 72 6f 67 72 61 6d 6d 69 |-name: p|rogrammi|
|00000490| 6e 67 2f 70 61 72 74 32 | 0a 50 6f 73 74 69 6e 67 |ng/part2|.Posting|
|000004a0| 2d 46 72 65 71 75 65 6e | 63 79 3a 20 6d 6f 6e 74 |-Frequen|cy: mont|
|000004b0| 68 6c 79 0a 4c 61 73 74 | 2d 6d 6f 64 69 66 69 65 |hly.Last|-modifie|
|000004c0| 64 3a 20 32 38 20 46 65 | 62 72 75 61 72 79 20 31 |d: 28 Fe|bruary 1|
|000004d0| 39 39 36 0a 4c 61 73 74 | 2d 70 6f 73 74 65 64 3a |996.Last|-posted:|
|000004e0| 20 32 36 20 4a 61 6e 75 | 61 72 79 20 31 39 39 36 | 26 Janu|ary 1996|
|000004f0| 0a 0a 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 |.. | |
|00000500| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00000510| 20 41 64 61 20 50 72 6f | 67 72 61 6d 6d 65 72 27 | Ada Pro|grammer'|
|00000520| 73 0a 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 |s. | |
|00000530| 20 20 20 20 20 20 20 20 | 20 46 72 65 71 75 65 6e | | Frequen|
|00000540| 74 6c 79 20 41 73 6b 65 | 64 20 51 75 65 73 74 69 |tly Aske|d Questi|
|00000550| 6f 6e 73 20 28 46 41 51 | 29 0a 0a 20 20 20 49 4d |ons (FAQ|).. IM|
|00000560| 50 4f 52 54 41 4e 54 20 | 4e 4f 54 45 3a 20 4e 6f |PORTANT |NOTE: No|
|00000570| 20 46 41 51 20 63 61 6e | 20 73 75 62 73 74 69 74 | FAQ can| substit|
|00000580| 75 74 65 20 66 6f 72 20 | 72 65 61 6c 20 74 65 61 |ute for |real tea|
|00000590| 63 68 69 6e 67 20 61 6e | 64 0a 20 20 20 64 6f 63 |ching an|d. doc|
|000005a0| 75 6d 65 6e 74 61 74 69 | 6f 6e 2e 20 54 68 65 72 |umentati|on. Ther|
|000005b0| 65 20 69 73 20 61 6e 20 | 61 6e 6e 6f 74 61 74 65 |e is an |annotate|
|000005c0| 64 20 6c 69 73 74 20 6f | 66 20 41 64 61 20 62 6f |d list o|f Ada bo|
|000005d0| 6f 6b 73 20 69 6e 20 74 | 68 65 0a 20 20 20 63 6f |oks in t|he. co|
|000005e0| 6d 70 61 6e 69 6f 6e 20 | 63 6f 6d 70 2e 6c 61 6e |mpanion |comp.lan|
|000005f0| 67 2e 61 64 61 20 46 41 | 51 2e 0a 0a 54 68 69 73 |g.ada FA|Q...This|
|00000600| 20 69 73 20 70 61 72 74 | 20 32 20 6f 66 20 61 20 | is part| 2 of a |
|00000610| 34 2d 70 61 72 74 20 70 | 6f 73 74 69 6e 67 2e 0a |4-part p|osting..|
|00000620| 50 61 72 74 20 33 20 62 | 65 67 69 6e 73 20 77 69 |Part 3 b|egins wi|
|00000630| 74 68 20 71 75 65 73 74 | 69 6f 6e 20 36 2e 0a 50 |th quest|ion 6..P|
|00000640| 61 72 74 20 34 20 62 65 | 67 69 6e 73 20 77 69 74 |art 4 be|gins wit|
|00000650| 68 20 71 75 65 73 74 69 | 6f 6e 20 39 2e 0a 50 61 |h questi|on 9..Pa|
|00000660| 72 74 73 20 33 20 61 6e | 64 20 34 20 73 68 6f 75 |rts 3 an|d 4 shou|
|00000670| 6c 64 20 62 65 20 74 68 | 65 20 6e 65 78 74 20 70 |ld be th|e next p|
|00000680| 6f 73 74 69 6e 67 73 20 | 69 6e 20 74 68 69 73 20 |ostings |in this |
|00000690| 74 68 72 65 61 64 2e 0a | 50 61 72 74 20 31 20 73 |thread..|Part 1 s|
|000006a0| 68 6f 75 6c 64 20 62 65 | 20 74 68 65 20 70 72 65 |hould be| the pre|
|000006b0| 76 69 6f 75 73 20 70 6f | 73 74 69 6e 67 20 69 6e |vious po|sting in|
|000006c0| 20 74 68 69 73 20 74 68 | 72 65 61 64 2e 0a 0a 20 | this th|read... |
|000006d0| 20 20 20 52 65 63 65 6e | 74 20 63 68 61 6e 67 65 | Recen|t change|
|000006e0| 73 20 74 6f 20 74 68 69 | 73 20 46 41 51 20 61 72 |s to thi|s FAQ ar|
|000006f0| 65 20 6c 69 73 74 65 64 | 20 69 6e 20 74 68 65 20 |e listed| in the |
|00000700| 66 69 72 73 74 20 73 65 | 63 74 69 6f 6e 20 61 66 |first se|ction af|
|00000710| 74 65 72 20 74 68 65 20 | 74 61 62 6c 65 0a 20 20 |ter the |table. |
|00000720| 20 20 6f 66 20 63 6f 6e | 74 65 6e 74 73 20 28 69 | of con|tents (i|
|00000730| 6e 20 70 61 72 74 20 31 | 29 2e 20 54 68 69 73 20 |n part 1|). This |
|00000740| 64 6f 63 75 6d 65 6e 74 | 20 69 73 20 75 6e 64 65 |document| is unde|
|00000750| 72 20 65 78 70 6c 69 63 | 69 74 20 63 6f 70 79 72 |r explic|it copyr|
|00000760| 69 67 68 74 2e 0a 0a 0a | 35 3a 20 4f 62 6a 65 63 |ight....|5: Objec|
|00000770| 74 2d 4f 72 69 65 6e 74 | 65 64 20 50 72 6f 67 72 |t-Orient|ed Progr|
|00000780| 61 6d 6d 69 6e 67 20 77 | 69 74 68 20 41 64 61 0a |amming w|ith Ada.|
|00000790| 0a 0a 35 2e 31 3a 20 57 | 68 79 20 64 6f 65 73 20 |..5.1: W|hy does |
|000007a0| 41 64 61 20 68 61 76 65 | 20 22 74 61 67 67 65 64 |Ada have| "tagged|
|000007b0| 20 74 79 70 65 73 22 20 | 69 6e 73 74 65 61 64 20 | types" |instead |
|000007c0| 6f 66 20 63 6c 61 73 73 | 65 73 3f 0a 0a 20 20 20 |of class|es?.. |
|000007d0| 28 54 75 63 6b 65 72 20 | 54 61 66 74 20 72 65 73 |(Tucker |Taft res|
|000007e0| 70 6f 6e 64 73 29 3a 0a | 0a 20 20 20 53 6f 6d 65 |ponds):.|. Some|
|000007f0| 6f 6e 65 20 72 65 63 65 | 6e 74 6c 79 20 61 73 6b |one rece|ntly ask|
|00000800| 65 64 20 6d 65 20 74 6f | 20 65 78 70 6c 61 69 6e |ed me to| explain|
|00000810| 20 74 68 65 20 64 69 66 | 66 65 72 65 6e 63 65 20 | the dif|ference |
|00000820| 62 65 74 77 65 65 6e 20 | 74 68 65 0a 20 20 20 6d |between |the. m|
|00000830| 65 61 6e 69 6e 67 20 6f | 66 20 74 68 65 20 74 65 |eaning o|f the te|
|00000840| 72 6d 20 22 63 6c 61 73 | 73 22 20 69 6e 20 43 2b |rm "clas|s" in C+|
|00000850| 2b 20 61 6e 64 20 69 74 | 73 20 6d 65 61 6e 69 6e |+ and it|s meanin|
|00000860| 67 20 69 6e 20 41 64 61 | 20 39 58 2e 20 48 65 72 |g in Ada| 9X. Her|
|00000870| 65 20 69 73 0a 20 20 20 | 61 20 73 79 6e 6f 70 73 |e is. |a synops|
|00000880| 69 73 20 6f 66 20 74 68 | 65 20 61 6e 73 77 65 72 |is of th|e answer|
|00000890| 3a 0a 0a 20 20 20 49 6e | 20 43 2b 2b 2c 20 74 68 |:.. In| C++, th|
|000008a0| 65 20 74 65 72 6d 20 22 | 63 6c 61 73 73 22 20 72 |e term "|class" r|
|000008b0| 65 66 65 72 73 20 74 6f | 20 74 68 72 65 65 20 64 |efers to| three d|
|000008c0| 69 66 66 65 72 65 6e 74 | 2c 20 62 75 74 20 72 65 |ifferent|, but re|
|000008d0| 6c 61 74 65 64 0a 20 20 | 20 74 68 69 6e 67 73 3a |lated. | things:|
|000008e0| 0a 20 20 20 20 20 2a 20 | 61 20 6c 61 6e 67 75 61 |. * |a langua|
|000008f0| 67 65 20 63 6f 6e 73 74 | 72 75 63 74 2c 20 74 68 |ge const|ruct, th|
|00000900| 61 74 20 65 6e 63 61 70 | 73 75 6c 61 74 65 73 20 |at encap|sulates |
|00000910| 74 68 65 20 64 65 66 69 | 6e 69 74 69 6f 6e 73 20 |the defi|nitions |
|00000920| 6f 66 20 64 61 74 61 0a | 20 20 20 20 20 20 20 6d |of data.| m|
|00000930| 65 6d 62 65 72 73 2c 20 | 6d 65 6d 62 65 72 20 66 |embers, |member f|
|00000940| 75 6e 63 74 69 6f 6e 73 | 2c 20 6e 65 73 74 65 64 |unctions|, nested|
|00000950| 20 74 79 70 65 73 2c 20 | 65 74 63 2e 3b 0a 0a 20 | types, |etc.;.. |
|00000960| 20 20 20 20 2a 20 61 20 | 70 61 72 74 69 63 75 6c | * a |particul|
|00000970| 61 72 20 6b 69 6e 64 20 | 6f 66 20 74 79 70 65 2c |ar kind |of type,|
|00000980| 20 64 65 66 69 6e 65 64 | 20 62 79 20 61 20 63 6c | defined| by a cl|
|00000990| 61 73 73 20 63 6f 6e 73 | 74 72 75 63 74 20 28 6f |ass cons|truct (o|
|000009a0| 72 20 62 79 0a 20 20 20 | 20 20 20 20 22 73 74 72 |r by. | "str|
|000009b0| 75 63 74 22 20 77 68 69 | 63 68 20 69 73 20 61 20 |uct" whi|ch is a |
|000009c0| 73 70 65 63 69 61 6c 20 | 63 61 73 65 20 6f 66 20 |special |case of |
|000009d0| 22 63 6c 61 73 73 22 29 | 3b 0a 0a 20 20 20 20 20 |"class")|;.. |
|000009e0| 2a 20 61 20 73 65 74 20 | 6f 66 20 74 79 70 65 73 |* a set |of types|
|000009f0| 20 63 6f 6e 73 69 73 74 | 69 6e 67 20 6f 66 20 61 | consist|ing of a|
|00000a00| 20 74 79 70 65 20 61 6e | 64 20 61 6c 6c 20 6f 66 | type an|d all of|
|00000a10| 20 69 74 73 20 64 65 72 | 69 76 61 74 69 76 65 73 | its der|ivatives|
|00000a20| 2c 0a 20 20 20 20 20 20 | 20 64 69 72 65 63 74 20 |,. | direct |
|00000a30| 61 6e 64 20 69 6e 64 69 | 72 65 63 74 2e 0a 0a 0a |and indi|rect....|
|00000a40| 20 20 20 49 6e 20 41 64 | 61 20 39 58 2c 20 74 68 | In Ad|a 9X, th|
|00000a50| 65 20 74 65 72 6d 20 22 | 63 6c 61 73 73 22 20 72 |e term "|class" r|
|00000a60| 65 66 65 72 73 20 6f 6e | 6c 79 20 74 6f 20 74 68 |efers on|ly to th|
|00000a70| 65 20 74 68 69 72 64 20 | 6f 66 20 74 68 65 20 61 |e third |of the a|
|00000a80| 62 6f 76 65 0a 20 20 20 | 64 65 66 69 6e 69 74 69 |bove. |definiti|
|00000a90| 6f 6e 73 2e 20 41 64 61 | 20 39 58 20 28 61 6e 64 |ons. Ada| 9X (and|
|00000aa0| 20 41 64 61 20 38 33 29 | 20 68 61 73 20 74 68 72 | Ada 83)| has thr|
|00000ab0| 65 65 20 64 69 66 66 65 | 72 65 6e 74 20 74 65 72 |ee diffe|rent ter|
|00000ac0| 6d 73 20 66 6f 72 20 74 | 68 65 0a 20 20 20 63 6f |ms for t|he. co|
|00000ad0| 6e 63 65 70 74 73 20 63 | 6f 72 72 65 73 70 6f 6e |ncepts c|orrespon|
|00000ae0| 64 69 6e 67 20 74 6f 20 | 74 68 65 20 61 62 6f 76 |ding to |the abov|
|00000af0| 65 20 74 68 72 65 65 20 | 74 68 69 6e 67 73 3a 0a |e three |things:.|
|00000b00| 20 20 20 20 20 2a 20 61 | 20 22 70 61 63 6b 61 67 | * a| "packag|
|00000b10| 65 22 20 65 6e 63 61 70 | 73 75 6c 61 74 65 73 20 |e" encap|sulates |
|00000b20| 74 68 65 20 64 65 66 69 | 6e 69 74 69 6f 6e 73 20 |the defi|nitions |
|00000b30| 6f 66 20 74 79 70 65 73 | 2c 20 6f 62 6a 65 63 74 |of types|, object|
|00000b40| 73 2c 0a 20 20 20 20 20 | 20 20 6f 70 65 72 61 74 |s,. | operat|
|00000b50| 69 6f 6e 73 2c 20 65 78 | 63 65 70 74 69 6f 6e 73 |ions, ex|ceptions|
|00000b60| 2c 20 65 74 63 20 77 68 | 69 63 68 20 61 72 65 20 |, etc wh|ich are |
|00000b70| 6c 6f 67 69 63 61 6c 6c | 79 20 72 65 6c 61 74 65 |logicall|y relate|
|00000b80| 64 2e 20 28 54 68 65 0a | 20 20 20 20 20 20 20 6f |d. (The.| o|
|00000b90| 70 65 72 61 74 69 6f 6e | 73 20 6f 66 20 61 20 74 |peration|s of a t|
|00000ba0| 79 70 65 20 64 65 66 69 | 6e 65 64 20 69 6d 6d 65 |ype defi|ned imme|
|00000bb0| 64 69 61 74 65 6c 79 20 | 77 69 74 68 69 6e 20 74 |diately |within t|
|00000bc0| 68 65 20 70 61 63 6b 61 | 67 65 20 77 68 65 72 65 |he packa|ge where|
|00000bd0| 0a 20 20 20 20 20 20 20 | 74 68 65 20 74 79 70 65 |. |the type|
|00000be0| 20 69 73 20 64 65 63 6c | 61 72 65 64 20 61 72 65 | is decl|ared are|
|00000bf0| 20 63 61 6c 6c 65 64 2c | 20 69 6e 20 39 58 2c 20 | called,| in 9X, |
|00000c00| 74 68 65 20 22 70 72 69 | 6d 69 74 69 76 65 20 6f |the "pri|mitive o|
|00000c10| 70 65 72 61 74 69 6f 6e | 73 22 0a 20 20 20 20 20 |peration|s". |
|00000c20| 20 20 6f 66 20 74 68 65 | 20 74 79 70 65 2c 20 61 | of the| type, a|
|00000c30| 6e 64 20 69 6e 20 73 6f | 6d 65 20 73 65 6e 73 65 |nd in so|me sense|
|00000c40| 2c 20 64 65 66 69 6e 65 | 20 74 68 65 20 22 70 72 |, define| the "pr|
|00000c50| 69 6d 69 74 69 76 65 22 | 20 73 65 6d 61 6e 74 69 |imitive"| semanti|
|00000c60| 63 73 0a 20 20 20 20 20 | 20 20 6f 66 20 74 68 65 |cs. | of the|
|00000c70| 20 74 79 70 65 2c 20 65 | 73 70 65 63 69 61 6c 6c | type, e|speciall|
|00000c80| 79 20 69 66 20 69 74 20 | 69 73 20 61 20 70 72 69 |y if it |is a pri|
|00000c90| 76 61 74 65 20 74 79 70 | 65 2e 29 0a 0a 20 20 20 |vate typ|e.).. |
|00000ca0| 20 20 2a 20 61 20 22 74 | 79 70 65 22 20 69 73 20 | * a "t|ype" is |
|00000cb0| 63 68 61 72 61 63 74 65 | 72 69 7a 65 64 20 62 79 |characte|rized by|
|00000cc0| 20 61 20 73 65 74 20 6f | 66 20 76 61 6c 75 65 73 | a set o|f values|
|00000cd0| 20 61 6e 64 20 61 20 73 | 65 74 20 6f 66 0a 20 20 | and a s|et of. |
|00000ce0| 20 20 20 20 20 70 72 69 | 6d 69 74 69 76 65 20 6f | pri|mitive o|
|00000cf0| 70 65 72 61 74 69 6f 6e | 73 20 28 74 68 65 72 65 |peration|s (there|
|00000d00| 20 61 72 65 20 61 20 6d | 69 6c 6c 69 6f 6e 20 64 | are a m|illion d|
|00000d10| 65 66 69 6e 69 74 69 6f | 6e 73 20 6f 66 20 22 74 |efinitio|ns of "t|
|00000d20| 79 70 65 2c 22 0a 20 20 | 20 20 20 20 20 75 6e 66 |ype,". | unf|
|00000d30| 6f 72 74 75 6e 61 74 65 | 6c 79 2c 20 62 75 74 20 |ortunate|ly, but |
|00000d40| 79 6f 75 20 6b 6e 6f 77 | 20 77 68 61 74 20 49 20 |you know| what I |
|00000d50| 6d 65 61 6e 2e 2e 2e 29 | 3b 0a 0a 20 20 20 20 20 |mean...)|;.. |
|00000d60| 2a 20 61 20 22 63 6c 61 | 73 73 22 20 69 73 20 61 |* a "cla|ss" is a|
|00000d70| 20 73 65 74 20 6f 66 20 | 74 79 70 65 73 20 77 69 | set of |types wi|
|00000d80| 74 68 20 73 69 6d 69 6c | 61 72 20 76 61 6c 75 65 |th simil|ar value|
|00000d90| 73 20 61 6e 64 20 6f 70 | 65 72 61 74 69 6f 6e 73 |s and op|erations|
|00000da0| 3b 20 69 6e 0a 20 20 20 | 20 20 20 20 70 61 72 74 |; in. | part|
|00000db0| 69 63 75 6c 61 72 2c 20 | 61 20 74 79 70 65 20 61 |icular, |a type a|
|00000dc0| 6e 64 20 61 6e 64 20 61 | 6c 6c 20 6f 66 20 69 74 |nd and a|ll of it|
|00000dd0| 73 20 64 65 72 69 76 61 | 74 69 76 65 73 2c 20 64 |s deriva|tives, d|
|00000de0| 69 72 65 63 74 20 61 6e | 64 0a 20 20 20 20 20 20 |irect an|d. |
|00000df0| 20 69 6e 64 69 72 65 63 | 74 2c 20 72 65 70 72 65 | indirec|t, repre|
|00000e00| 73 65 6e 74 73 20 61 20 | 28 64 65 72 69 76 61 74 |sents a |(derivat|
|00000e10| 69 6f 6e 29 20 63 6c 61 | 73 73 2e 20 41 6c 73 6f |ion) cla|ss. Also|
|00000e20| 2c 20 74 68 65 20 73 65 | 74 20 6f 66 0a 20 20 20 |, the se|t of. |
|00000e30| 20 20 20 20 69 6e 74 65 | 67 65 72 20 74 79 70 65 | inte|ger type|
|00000e40| 73 20 66 6f 72 6d 20 74 | 68 65 20 69 6e 74 65 67 |s form t|he integ|
|00000e50| 65 72 20 22 63 6c 61 73 | 73 2c 22 20 61 6e 64 20 |er "clas|s," and |
|00000e60| 73 6f 20 6f 6e 20 66 6f | 72 20 74 68 65 20 6f 74 |so on fo|r the ot|
|00000e70| 68 65 72 0a 20 20 20 20 | 20 20 20 6c 61 6e 67 75 |her. | langu|
|00000e80| 61 67 65 2d 64 65 66 69 | 6e 65 64 20 63 6c 61 73 |age-defi|ned clas|
|00000e90| 73 65 73 20 6f 66 20 74 | 79 70 65 73 20 69 6e 20 |ses of t|ypes in |
|00000ea0| 74 68 65 20 6c 61 6e 67 | 75 61 67 65 2e 0a 0a 0a |the lang|uage....|
|00000eb0| 20 20 20 53 6f 6d 65 20 | 4f 4f 50 20 6c 61 6e 67 | Some |OOP lang|
|00000ec0| 75 61 67 65 73 20 74 61 | 6b 65 20 61 6e 20 69 6e |uages ta|ke an in|
|00000ed0| 74 65 72 6d 65 64 69 61 | 72 79 20 70 6f 73 69 74 |termedia|ry posit|
|00000ee0| 69 6f 6e 2e 20 49 6e 20 | 43 4c 4f 53 2c 20 61 20 |ion. In |CLOS, a |
|00000ef0| 22 63 6c 61 73 73 22 0a | 20 20 20 69 73 20 6e 6f |"class".| is no|
|00000f00| 74 20 61 6e 20 65 6e 63 | 61 70 73 75 6c 61 74 69 |t an enc|apsulati|
|00000f10| 6e 67 20 63 6f 6e 73 74 | 72 75 63 74 20 28 43 4c |ng const|ruct (CL|
|00000f20| 4f 53 20 68 61 73 20 22 | 70 61 63 6b 61 67 65 73 |OS has "|packages|
|00000f30| 22 29 2e 20 48 6f 77 65 | 76 65 72 2c 20 61 0a 20 |"). Howe|ver, a. |
|00000f40| 20 20 22 63 6c 61 73 73 | 22 20 69 73 20 62 6f 74 | "class|" is bot|
|00000f50| 68 20 61 20 74 79 70 65 | 20 61 6e 64 20 61 20 73 |h a type| and a s|
|00000f60| 65 74 20 6f 66 20 74 79 | 70 65 73 2c 20 64 65 70 |et of ty|pes, dep|
|00000f70| 65 6e 64 69 6e 67 20 6f | 6e 20 63 6f 6e 74 65 78 |ending o|n contex|
|00000f80| 74 2e 0a 20 20 20 28 4d | 65 74 68 6f 64 73 20 22 |t.. (M|ethods "|
|00000f90| 66 6c 6f 61 74 22 20 66 | 72 65 65 6c 79 2e 29 0a |float" f|reely.).|
|00000fa0| 0a 20 20 20 54 68 65 20 | 64 69 73 74 69 6e 63 74 |. The |distinct|
|00000fb0| 69 6f 6e 20 41 64 61 20 | 39 58 20 6d 61 6b 65 73 |ion Ada |9X makes|
|00000fc0| 20 62 65 74 77 65 65 6e | 20 74 79 70 65 73 20 61 | between| types a|
|00000fd0| 6e 64 20 63 6c 61 73 73 | 65 73 20 28 3d 20 73 65 |nd class|es (= se|
|00000fe0| 74 20 6f 66 0a 20 20 20 | 74 79 70 65 73 29 20 63 |t of. |types) c|
|00000ff0| 61 72 72 69 65 73 20 6f | 76 65 72 20 69 6e 74 6f |arries o|ver into|
|00001000| 20 74 68 65 20 73 65 6d | 61 6e 74 69 63 20 6d 6f | the sem|antic mo|
|00001010| 64 65 6c 2c 20 61 6e 64 | 20 61 6c 6c 6f 77 73 20 |del, and| allows |
|00001020| 73 6f 6d 65 0a 20 20 20 | 69 6e 74 65 72 65 73 74 |some. |interest|
|00001030| 69 6e 67 20 63 61 70 61 | 62 69 6c 69 74 69 65 73 |ing capa|bilities|
|00001040| 20 6e 6f 74 20 70 72 65 | 73 65 6e 74 20 69 6e 20 | not pre|sent in |
|00001050| 43 2b 2b 2e 20 49 6e 20 | 70 61 72 74 69 63 75 6c |C++. In |particul|
|00001060| 61 72 2c 20 69 6e 20 41 | 64 61 20 39 58 0a 20 20 |ar, in A|da 9X. |
|00001070| 20 6f 6e 65 20 63 61 6e | 20 64 65 63 6c 61 72 65 | one can| declare|
|00001080| 20 61 20 22 63 6c 61 73 | 73 2d 77 69 64 65 22 20 | a "clas|s-wide" |
|00001090| 6f 62 6a 65 63 74 20 69 | 6e 69 74 69 61 6c 69 7a |object i|nitializ|
|000010a0| 65 64 20 62 79 20 63 6f | 70 79 20 66 72 6f 6d 20 |ed by co|py from |
|000010b0| 61 0a 20 20 20 22 63 6c | 61 73 73 2d 77 69 64 65 |a. "cl|ass-wide|
|000010c0| 22 20 66 6f 72 6d 61 6c | 20 70 61 72 61 6d 65 74 |" formal| paramet|
|000010d0| 65 72 2c 20 77 69 74 68 | 20 74 68 65 20 6e 65 77 |er, with| the new|
|000010e0| 20 6f 62 6a 65 63 74 20 | 63 61 72 72 79 69 6e 67 | object |carrying|
|000010f0| 20 6f 76 65 72 20 74 68 | 65 0a 20 20 20 75 6e 64 | over th|e. und|
|00001100| 65 72 6c 79 69 6e 67 20 | 74 79 70 65 20 6f 66 20 |erlying |type of |
|00001110| 74 68 65 20 61 63 74 75 | 61 6c 20 70 61 72 61 6d |the actu|al param|
|00001120| 65 74 65 72 2e 20 46 6f | 72 20 65 78 61 6d 70 6c |eter. Fo|r exampl|
|00001130| 65 3a 0a 0a 20 20 20 20 | 20 70 72 6f 63 65 64 75 |e:.. | procedu|
|00001140| 72 65 20 50 72 69 6e 74 | 5f 49 6e 5f 42 6f 6c 64 |re Print|_In_Bold|
|00001150| 20 28 58 20 3a 20 54 27 | 43 6c 61 73 73 29 20 69 | (X : T'|Class) i|
|00001160| 73 0a 20 20 20 20 20 20 | 20 2d 2d 20 43 6f 70 79 |s. | -- Copy|
|00001170| 20 58 2c 20 6d 61 6b 65 | 20 69 74 20 62 6f 6c 64 | X, make| it bold|
|00001180| 20 66 61 63 65 2c 20 61 | 6e 64 20 74 68 65 6e 20 | face, a|nd then |
|00001190| 70 72 69 6e 74 20 69 74 | 2e 0a 20 20 20 20 20 20 |print it|.. |
|000011a0| 20 43 6f 70 79 5f 4f 66 | 5f 58 20 3a 20 54 27 43 | Copy_Of|_X : T'C|
|000011b0| 6c 61 73 73 20 3a 3d 20 | 58 3b 0a 20 20 20 20 20 |lass := |X;. |
|000011c0| 62 65 67 69 6e 0a 20 20 | 20 20 20 20 20 20 4d 61 |begin. | Ma|
|000011d0| 6b 65 5f 42 6f 6c 64 20 | 28 43 6f 70 79 5f 4f 66 |ke_Bold |(Copy_Of|
|000011e0| 5f 58 29 3b 0a 20 20 20 | 20 20 20 20 20 50 72 69 |_X);. | Pri|
|000011f0| 6e 74 20 28 43 6f 70 79 | 5f 4f 66 5f 58 29 3b 0a |nt (Copy|_Of_X);.|
|00001200| 20 20 20 20 20 65 6e 64 | 20 50 3b 0a 0a 0a 20 20 | end| P;... |
|00001210| 20 49 6e 20 43 2b 2b 2c | 20 77 68 65 6e 20 79 6f | In C++,| when yo|
|00001220| 75 20 64 65 63 6c 61 72 | 65 20 61 6e 20 6f 62 6a |u declar|e an obj|
|00001230| 65 63 74 2c 20 79 6f 75 | 20 6d 75 73 74 20 73 70 |ect, you| must sp|
|00001240| 65 63 69 66 79 20 74 68 | 65 20 22 65 78 61 63 74 |ecify th|e "exact|
|00001250| 22 20 63 6c 61 73 73 0a | 20 20 20 6f 66 20 74 68 |" class.| of th|
|00001260| 65 20 6f 62 6a 65 63 74 | 20 2d 2d 20 69 74 20 63 |e object| -- it c|
|00001270| 61 6e 6e 6f 74 20 62 65 | 20 64 65 74 65 72 6d 69 |annot be| determi|
|00001280| 6e 65 64 20 62 79 20 74 | 68 65 20 75 6e 64 65 72 |ned by t|he under|
|00001290| 6c 79 69 6e 67 20 63 6c | 61 73 73 20 6f 66 0a 20 |lying cl|ass of. |
|000012a0| 20 20 74 68 65 20 69 6e | 69 74 69 61 6c 69 7a 69 | the in|itializi|
|000012b0| 6e 67 20 76 61 6c 75 65 | 2e 20 49 6d 70 6c 65 6d |ng value|. Implem|
|000012c0| 65 6e 74 69 6e 67 20 74 | 68 65 20 61 62 6f 76 65 |enting t|he above|
|000012d0| 20 70 72 6f 63 65 64 75 | 72 65 20 69 6e 20 61 20 | procedu|re in a |
|000012e0| 67 65 6e 65 72 61 6c 0a | 20 20 20 77 61 79 20 69 |general.| way i|
|000012f0| 6e 20 43 2b 2b 20 77 6f | 75 6c 64 20 62 65 20 73 |n C++ wo|uld be s|
|00001300| 6c 69 67 68 74 6c 79 20 | 6d 6f 72 65 20 74 65 64 |lightly |more ted|
|00001310| 69 6f 75 73 2e 0a 0a 20 | 20 20 53 69 6d 69 6c 61 |ious... | Simila|
|00001320| 72 6c 79 2c 20 69 6e 20 | 41 64 61 20 39 58 20 6f |rly, in |Ada 9X o|
|00001330| 6e 65 20 63 61 6e 20 64 | 65 66 69 6e 65 20 61 6e |ne can d|efine an|
|00001340| 20 61 63 63 65 73 73 20 | 74 79 70 65 20 74 68 61 | access |type tha|
|00001350| 74 20 64 65 73 69 67 6e | 61 74 65 73 0a 20 20 20 |t design|ates. |
|00001360| 6f 6e 6c 79 20 6f 6e 65 | 20 73 70 65 63 69 66 69 |only one| specifi|
|00001370| 63 20 74 79 70 65 2c 20 | 6f 72 20 61 6c 74 65 72 |c type, |or alter|
|00001380| 6e 61 74 69 76 65 6c 79 | 2c 20 6f 6e 65 20 63 61 |natively|, one ca|
|00001390| 6e 20 64 65 66 69 6e 65 | 20 6f 6e 65 20 74 68 61 |n define| one tha|
|000013a0| 74 20 63 61 6e 0a 20 20 | 20 64 65 73 69 67 6e 61 |t can. | designa|
|000013b0| 74 65 20 6f 62 6a 65 63 | 74 73 20 6f 66 20 61 6e |te objec|ts of an|
|000013c0| 79 20 74 79 70 65 20 69 | 6e 20 61 20 63 6c 61 73 |y type i|n a clas|
|000013d0| 73 20 28 61 20 22 63 6c | 61 73 73 2d 77 69 64 65 |s (a "cl|ass-wide|
|000013e0| 22 20 61 63 63 65 73 73 | 20 74 79 70 65 29 2e 0a |" access| type)..|
|000013f0| 20 20 20 46 6f 72 20 65 | 78 61 6d 70 6c 65 3a 0a | For e|xample:.|
|00001400| 0a 20 20 20 20 20 74 79 | 70 65 20 46 61 6e 63 79 |. ty|pe Fancy|
|00001410| 5f 57 69 6e 64 6f 77 5f | 50 74 72 20 69 73 20 61 |_Window_|Ptr is a|
|00001420| 63 63 65 73 73 20 46 61 | 6e 63 79 5f 57 69 6e 64 |ccess Fa|ncy_Wind|
|00001430| 6f 77 3b 0a 20 20 20 20 | 20 20 20 2d 2d 20 4f 6e |ow;. | -- On|
|00001440| 6c 79 20 70 6f 69 6e 74 | 73 20 61 74 20 46 61 6e |ly point|s at Fan|
|00001450| 63 79 20 57 69 6e 64 6f | 77 73 20 2d 2d 20 6e 6f |cy Windo|ws -- no|
|00001460| 20 64 65 72 69 76 61 74 | 69 76 65 73 20 61 6c 6c | derivat|ives all|
|00001470| 6f 77 65 64 0a 20 20 20 | 20 20 74 79 70 65 20 41 |owed. | type A|
|00001480| 6e 79 5f 57 69 6e 64 6f | 77 5f 50 74 72 20 69 73 |ny_Windo|w_Ptr is|
|00001490| 20 61 63 63 65 73 73 20 | 57 69 6e 64 6f 77 27 43 | access |Window'C|
|000014a0| 6c 61 73 73 3b 0a 20 20 | 20 20 20 20 20 2d 2d 20 |lass;. | -- |
|000014b0| 50 6f 69 6e 74 73 20 61 | 74 20 57 69 6e 64 6f 77 |Points a|t Window|
|000014c0| 73 2c 20 61 6e 64 20 61 | 6e 79 20 64 65 72 69 76 |s, and a|ny deriv|
|000014d0| 61 74 69 76 65 73 20 74 | 68 65 72 65 6f 66 2e 0a |atives t|hereof..|
|000014e0| 0a 0a 20 20 20 49 6e 20 | 43 2b 2b 2c 20 61 6c 6c |.. In |C++, all|
|000014f0| 20 70 6f 69 6e 74 65 72 | 73 2f 72 65 66 65 72 65 | pointer|s/refere|
|00001500| 6e 63 65 73 20 61 72 65 | 20 22 63 6c 61 73 73 2d |nces are| "class-|
|00001510| 77 69 64 65 22 20 69 6e | 20 74 68 69 73 20 73 65 |wide" in| this se|
|00001520| 6e 73 65 3b 20 79 6f 75 | 0a 20 20 20 63 61 6e 27 |nse; you|. can'|
|00001530| 74 20 72 65 73 74 72 69 | 63 74 20 74 68 65 6d 20 |t restri|ct them |
|00001540| 74 6f 20 70 6f 69 6e 74 | 20 61 74 20 6f 6e 6c 79 |to point| at only|
|00001550| 20 6f 6e 65 20 22 73 70 | 65 63 69 66 69 63 22 20 | one "sp|ecific" |
|00001560| 74 79 70 65 2e 0a 0a 20 | 20 20 49 6e 20 6f 74 68 |type... | In oth|
|00001570| 65 72 20 77 6f 72 64 73 | 2c 20 43 2b 2b 20 6d 61 |er words|, C++ ma|
|00001580| 6b 65 73 20 74 68 65 20 | 64 69 73 74 69 6e 63 74 |kes the |distinct|
|00001590| 69 6f 6e 20 62 65 74 77 | 65 65 6e 20 22 73 70 65 |ion betw|een "spe|
|000015a0| 63 69 66 69 63 22 20 61 | 6e 64 0a 20 20 20 22 63 |cific" a|nd. "c|
|000015b0| 6c 61 73 73 2d 77 69 64 | 65 22 20 62 61 73 65 64 |lass-wid|e" based|
|000015c0| 20 6f 6e 20 70 6f 69 6e | 74 65 72 2f 72 65 66 65 | on poin|ter/refe|
|000015d0| 72 65 6e 63 65 20 76 65 | 72 73 75 73 20 6f 62 6a |rence ve|rsus obj|
|000015e0| 65 63 74 2f 76 61 6c 75 | 65 2c 20 77 68 65 72 65 |ect/valu|e, where|
|000015f0| 61 73 0a 20 20 20 69 6e | 20 41 64 61 20 39 58 2c |as. in| Ada 9X,|
|00001600| 20 74 68 69 73 20 64 69 | 73 74 69 6e 63 74 69 6f | this di|stinctio|
|00001610| 6e 20 69 73 20 65 78 70 | 6c 69 63 69 74 2c 20 61 |n is exp|licit, a|
|00001620| 6e 64 20 63 6f 72 72 65 | 73 70 6f 6e 64 73 20 74 |nd corre|sponds t|
|00001630| 6f 20 74 68 65 0a 20 20 | 20 64 69 73 74 69 6e 63 |o the. | distinc|
|00001640| 74 69 6f 6e 20 62 65 74 | 77 65 65 6e 20 22 74 79 |tion bet|ween "ty|
|00001650| 70 65 22 20 28 6f 6e 65 | 20 73 70 65 63 69 66 69 |pe" (one| specifi|
|00001660| 63 20 74 79 70 65 29 20 | 61 6e 64 20 22 63 6c 61 |c type) |and "cla|
|00001670| 73 73 22 20 28 73 65 74 | 20 6f 66 0a 20 20 20 74 |ss" (set| of. t|
|00001680| 79 70 65 73 29 2e 0a 0a | 20 20 20 54 68 65 20 41 |ypes)...| The A|
|00001690| 64 61 20 39 58 20 61 70 | 70 72 6f 61 63 68 20 77 |da 9X ap|proach w|
|000016a0| 65 20 62 65 6c 69 65 76 | 65 20 28 68 6f 70 65 20 |e believ|e (hope |
|000016b0| 3b 2d 29 20 67 69 76 65 | 73 20 73 6f 6d 65 77 68 |;-) give|s somewh|
|000016c0| 61 74 20 62 65 74 74 65 | 72 20 63 6f 6e 74 72 6f |at bette|r contro|
|000016d0| 6c 0a 20 20 20 6f 76 65 | 72 20 73 74 61 74 69 63 |l. ove|r static|
|000016e0| 20 76 65 72 73 75 73 20 | 64 79 6e 61 6d 69 63 20 | versus |dynamic |
|000016f0| 62 69 6e 64 69 6e 67 2c | 20 61 6e 64 20 69 73 20 |binding,| and is |
|00001700| 6c 65 73 73 20 65 72 72 | 6f 72 20 70 72 6f 6e 65 |less err|or prone|
|00001710| 20 73 69 6e 63 65 20 69 | 74 0a 20 20 20 69 73 20 | since i|t. is |
|00001720| 74 79 70 65 2d 62 61 73 | 65 64 2c 20 72 61 74 68 |type-bas|ed, rath|
|00001730| 65 72 20 74 68 61 6e 20 | 62 65 69 6e 67 20 62 61 |er than |being ba|
|00001740| 73 65 64 20 6f 6e 20 72 | 65 66 65 72 65 6e 63 65 |sed on r|eference|
|00001750| 20 76 73 2e 20 76 61 6c | 75 65 2e 0a 0a 20 20 20 | vs. val|ue... |
|00001760| 49 6e 20 61 6e 79 20 63 | 61 73 65 2c 20 69 6e 20 |In any c|ase, in |
|00001770| 41 64 61 20 39 58 2c 20 | 43 2b 2b 2c 20 61 6e 64 |Ada 9X, |C++, and|
|00001780| 20 43 4c 4f 53 20 69 74 | 20 6d 61 6b 65 73 20 73 | CLOS it| makes s|
|00001790| 65 6e 73 65 20 74 6f 20 | 74 61 6c 6b 20 61 62 6f |ense to |talk abo|
|000017a0| 75 74 0a 20 20 20 22 63 | 6c 61 73 73 20 6c 69 62 |ut. "c|lass lib|
|000017b0| 72 61 72 69 65 73 2c 22 | 20 73 69 6e 63 65 20 61 |raries,"| since a|
|000017c0| 20 67 69 76 65 6e 20 6c | 69 62 72 61 72 79 20 77 | given l|ibrary w|
|000017d0| 69 6c 6c 20 67 65 6e 65 | 72 61 6c 6c 79 20 63 6f |ill gene|rally co|
|000017e0| 6e 73 69 73 74 20 6f 66 | 20 61 0a 20 20 20 73 65 |nsist of| a. se|
|000017f0| 74 20 6f 66 20 69 6e 74 | 65 72 72 65 6c 61 74 65 |t of int|errelate|
|00001800| 64 20 74 79 70 65 73 2e | 20 49 6e 20 41 64 61 20 |d types.| In Ada |
|00001810| 39 58 20 61 6e 64 20 43 | 4c 4f 53 2c 20 6f 6e 65 |9X and C|LOS, one|
|00001820| 20 63 6f 75 6c 64 20 61 | 6c 74 65 72 6e 61 74 69 | could a|lternati|
|00001830| 76 65 6c 79 0a 20 20 20 | 74 61 6c 6b 20 61 62 6f |vely. |talk abo|
|00001840| 75 74 20 61 20 73 65 74 | 20 6f 66 20 22 72 65 75 |ut a set| of "reu|
|00001850| 73 61 62 6c 65 20 70 61 | 63 6b 61 67 65 73 22 20 |sable pa|ckages" |
|00001860| 61 6e 64 20 6d 65 61 6e | 20 65 73 73 65 6e 74 69 |and mean| essenti|
|00001870| 61 6c 6c 79 20 74 68 65 | 20 73 61 6d 65 0a 20 20 |ally the| same. |
|00001880| 20 74 68 69 6e 67 2e 0a | 0a 0a 35 2e 32 3a 20 56 | thing..|..5.2: V|
|00001890| 61 72 69 61 6e 74 20 72 | 65 63 6f 72 64 73 20 73 |ariant r|ecords s|
|000018a0| 65 65 6d 20 6c 69 6b 65 | 20 61 20 64 65 61 64 20 |eem like| a dead |
|000018b0| 66 65 61 74 75 72 65 20 | 6e 6f 77 2e 20 57 68 65 |feature |now. Whe|
|000018c0| 6e 20 73 68 6f 75 6c 64 | 20 49 20 75 73 65 20 74 |n should| I use t|
|000018d0| 68 65 6d 0a 69 6e 73 74 | 65 61 64 20 6f 66 20 74 |hem.inst|ead of t|
|000018e0| 61 67 67 65 64 20 74 79 | 70 65 73 3f 0a 0a 20 20 |agged ty|pes?.. |
|000018f0| 20 54 68 69 73 20 69 73 | 20 61 6e 20 69 6e 73 74 | This is| an inst|
|00001900| 61 6e 63 65 20 6f 66 20 | 61 20 6d 75 63 68 20 6d |ance of |a much m|
|00001910| 6f 72 65 20 67 65 6e 65 | 72 61 6c 20 71 75 65 73 |ore gene|ral ques|
|00001920| 74 69 6f 6e 3a 20 22 57 | 68 65 6e 20 73 68 6f 75 |tion: "W|hen shou|
|00001930| 6c 64 20 49 0a 20 20 20 | 75 73 65 20 77 68 61 74 |ld I. |use what|
|00001940| 20 6b 69 6e 64 20 6f 66 | 20 74 79 70 65 3f 22 20 | kind of| type?" |
|00001950| 54 68 65 20 73 69 6d 70 | 6c 65 20 61 6e 73 77 65 |The simp|le answe|
|00001960| 72 20 69 73 3a 20 22 57 | 68 65 6e 20 69 74 20 6d |r is: "W|hen it m|
|00001970| 61 6b 65 73 20 73 65 6e | 73 65 20 74 6f 0a 20 20 |akes sen|se to. |
|00001980| 20 64 6f 20 73 6f 2e 22 | 20 54 68 65 20 72 65 61 | do so."| The rea|
|00001990| 6c 20 6b 65 79 20 74 6f | 20 63 68 6f 73 69 6e 67 |l key to| chosing|
|000019a0| 20 61 20 74 79 70 65 20 | 69 6e 20 41 64 61 20 69 | a type |in Ada i|
|000019b0| 73 20 74 6f 20 6c 6f 6f | 6b 20 61 74 20 74 68 65 |s to loo|k at the|
|000019c0| 0a 20 20 20 61 70 70 6c | 69 63 61 74 69 6f 6e 2c |. appl|ication,|
|000019d0| 20 61 6e 64 20 70 69 63 | 6b 20 74 68 65 20 74 79 | and pic|k the ty|
|000019e0| 70 65 20 74 68 61 74 20 | 6d 6f 73 74 20 63 6c 6f |pe that |most clo|
|000019f0| 73 65 6c 79 20 6d 6f 64 | 65 6c 73 20 74 68 65 20 |sely mod|els the |
|00001a00| 70 72 6f 62 6c 65 6d 2e | 0a 0a 20 20 20 46 6f 72 |problem.|.. For|
|00001a10| 20 69 6e 73 74 61 6e 63 | 65 2c 20 69 66 20 79 6f | instanc|e, if yo|
|00001a20| 75 20 61 72 65 20 6d 6f | 64 65 6c 6c 69 6e 67 20 |u are mo|delling |
|00001a30| 64 61 74 61 20 74 72 61 | 6e 73 6d 69 73 73 69 6f |data tra|nsmissio|
|00001a40| 6e 20 77 68 65 72 65 20 | 74 68 65 20 6d 65 73 73 |n where |the mess|
|00001a50| 61 67 65 0a 20 20 20 70 | 61 63 6b 65 74 73 20 6d |age. p|ackets m|
|00001a60| 61 79 20 63 6f 6e 74 61 | 69 6e 20 76 61 72 69 61 |ay conta|in varia|
|00001a70| 62 6c 65 20 66 6f 72 6d | 73 20 6f 66 20 64 61 74 |ble form|s of dat|
|00001a80| 61 2c 20 61 20 76 61 72 | 69 61 6e 74 20 72 65 63 |a, a var|iant rec|
|00001a90| 6f 72 64 20 2d 2d 6e 6f | 74 20 61 0a 20 20 20 68 |ord --no|t a. h|
|00001aa0| 69 65 72 61 72 63 68 79 | 20 6f 66 20 74 61 67 67 |ierarchy| of tagg|
|00001ab0| 65 64 20 74 79 70 65 73 | 2d 2d 20 69 73 20 61 6e |ed types|-- is an|
|00001ac0| 20 61 70 70 72 6f 70 72 | 69 61 74 65 20 6d 6f 64 | appropr|iate mod|
|00001ad0| 65 6c 2c 20 73 69 6e 63 | 65 20 74 68 65 72 65 20 |el, sinc|e there |
|00001ae0| 6d 61 79 0a 20 20 20 62 | 65 20 6e 6f 20 72 65 6c |may. b|e no rel|
|00001af0| 61 74 69 6f 6e 73 68 69 | 70 20 62 65 74 77 65 65 |ationshi|p betwee|
|00001b00| 6e 20 74 68 65 20 64 61 | 74 61 20 69 74 65 6d 73 |n the da|ta items|
|00001b10| 20 6f 74 68 65 72 20 74 | 68 61 6e 20 74 68 65 69 | other t|han thei|
|00001b20| 72 20 62 65 69 6e 67 0a | 20 20 20 74 72 61 6e 73 |r being.| trans|
|00001b30| 6d 69 74 74 65 64 20 6f | 76 65 72 20 6f 6e 65 20 |mitted o|ver one |
|00001b40| 63 68 61 6e 6e 65 6c 2e | 20 49 66 20 79 6f 75 20 |channel.| If you |
|00001b50| 63 68 6f 6f 73 65 20 74 | 6f 20 6d 6f 64 65 6c 20 |choose t|o model |
|00001b60| 74 68 65 20 62 61 73 65 | 20 74 79 70 65 20 6f 66 |the base| type of|
|00001b70| 0a 20 20 20 74 68 65 20 | 6d 65 73 73 61 67 65 73 |. the |messages|
|00001b80| 20 77 69 74 68 20 61 20 | 74 61 67 67 65 64 20 74 | with a |tagged t|
|00001b90| 79 70 65 2c 20 74 68 61 | 74 20 6d 61 79 20 70 72 |ype, tha|t may pr|
|00001ba0| 65 73 65 6e 74 20 6d 6f | 72 65 20 70 72 6f 62 6c |esent mo|re probl|
|00001bb0| 65 6d 73 20 74 68 61 6e | 0a 20 20 20 69 74 20 73 |ems than|. it s|
|00001bc0| 6f 6c 76 65 73 20 77 68 | 65 6e 20 63 6f 6d 6d 75 |olves wh|en commu|
|00001bd0| 6e 69 63 61 74 69 6e 67 | 20 61 63 72 6f 73 73 20 |nicating| across |
|00001be0| 64 69 73 74 69 6e 63 74 | 20 61 72 63 68 69 74 65 |distinct| archite|
|00001bf0| 63 74 75 72 65 73 2e 0a | 0a 20 20 20 5b 4d 6f 72 |ctures..|. [Mor|
|00001c00| 65 20 74 6f 20 62 65 20 | 73 61 69 64 20 61 62 6f |e to be |said abo|
|00001c10| 75 74 20 76 61 72 69 61 | 6e 74 20 70 72 6f 67 72 |ut varia|nt progr|
|00001c20| 61 6d 6d 69 6e 67 20 76 | 73 2e 20 69 6e 63 72 65 |amming v|s. incre|
|00001c30| 6d 65 6e 74 61 6c 0a 20 | 20 20 70 72 6f 67 72 61 |mental. | progra|
|00001c40| 6d 6d 69 6e 67 2e 5d 0a | 0a 0a 35 2e 33 3a 20 57 |mming.].|..5.3: W|
|00001c50| 68 61 74 20 69 73 20 6d | 65 61 6e 74 20 62 79 20 |hat is m|eant by |
|00001c60| 22 69 6e 74 65 72 66 61 | 63 65 20 69 6e 68 65 72 |"interfa|ce inher|
|00001c70| 69 74 61 6e 63 65 22 20 | 61 6e 64 20 68 6f 77 20 |itance" |and how |
|00001c80| 64 6f 65 73 20 41 64 61 | 20 73 75 70 70 6f 72 74 |does Ada| support|
|00001c90| 20 69 74 3f 0a 0a 20 20 | 20 54 68 69 73 20 61 6e | it?.. | This an|
|00001ca0| 73 77 65 72 20 69 6e 74 | 65 6e 74 69 6f 6e 61 6c |swer int|entional|
|00001cb0| 6c 79 20 6c 65 66 74 20 | 62 6c 61 6e 6b 2e 0a 0a |ly left |blank...|
|00001cc0| 0a 35 2e 34 3a 20 48 6f | 77 20 64 6f 20 79 6f 75 |.5.4: Ho|w do you|
|00001cd0| 20 64 6f 20 6d 75 6c 74 | 69 70 6c 65 20 69 6e 68 | do mult|iple inh|
|00001ce0| 65 72 69 74 61 6e 63 65 | 20 69 6e 20 41 64 61 20 |eritance| in Ada |
|00001cf0| 39 58 3f 0a 0a 20 20 20 | 54 68 65 72 65 20 69 73 |9X?.. |There is|
|00001d00| 20 61 20 6c 65 6e 67 74 | 68 79 20 70 61 70 65 72 | a lengt|hy paper|
|00001d10| 20 69 6e 20 66 69 6c 65 | 0a 20 20 20 66 74 70 3a | in file|. ftp:|
|00001d20| 2f 2f 73 77 2d 65 6e 67 | 2e 66 61 6c 6c 73 2d 63 |//sw-eng|.falls-c|
|00001d30| 68 75 72 63 68 2e 76 61 | 2e 75 73 2f 70 75 62 6c |hurch.va|.us/publ|
|00001d40| 69 63 2f 41 64 61 49 43 | 2f 66 6c 79 65 72 73 2f |ic/AdaIC|/flyers/|
|00001d50| 39 78 6d 2d 69 6e 68 2e | 74 78 74 0a 0a 20 20 20 |9xm-inh.|txt.. |
|00001d60| 54 68 61 74 20 64 6f 63 | 75 6d 65 6e 74 20 64 65 |That doc|ument de|
|00001d70| 73 63 72 69 62 65 73 20 | 73 65 76 65 72 61 6c 20 |scribes |several |
|00001d80| 6d 65 63 68 61 6e 69 73 | 6d 73 20 66 6f 72 20 61 |mechanis|ms for a|
|00001d90| 63 68 69 65 76 69 6e 67 | 20 4d 49 20 69 6e 20 41 |chieving| MI in A|
|00001da0| 64 61 2e 20 49 74 0a 20 | 20 20 69 73 20 6e 6f 74 |da. It. | is not|
|00001db0| 20 75 6e 75 73 75 61 6c | 2c 20 68 6f 77 65 76 65 | unusual|, howeve|
|00001dc0| 72 2c 20 74 6f 20 66 69 | 6e 64 20 63 6f 6d 70 6c |r, to fi|nd compl|
|00001dd0| 61 69 6e 74 73 20 61 62 | 6f 75 74 20 74 68 65 20 |aints ab|out the |
|00001de0| 73 79 6e 74 61 78 20 61 | 6e 64 20 74 68 65 0a 20 |syntax a|nd the. |
|00001df0| 20 20 70 65 72 63 65 69 | 76 65 64 20 62 75 72 64 | percei|ved burd|
|00001e00| 65 6e 20 69 74 20 70 6c | 61 63 65 73 20 6f 6e 20 |en it pl|aces on |
|00001e10| 74 68 65 20 64 65 76 65 | 6c 6f 70 65 72 2e 20 54 |the deve|loper. T|
|00001e20| 68 69 73 20 69 73 20 77 | 68 61 74 20 54 75 63 6b |his is w|hat Tuck|
|00001e30| 65 72 20 54 61 66 74 0a | 20 20 20 68 61 64 20 74 |er Taft.| had t|
|00001e40| 6f 20 73 61 79 20 77 68 | 65 6e 20 72 65 73 70 6f |o say wh|en respo|
|00001e50| 6e 67 69 6e 67 20 74 6f | 20 73 75 63 68 20 61 20 |nging to| such a |
|00001e60| 63 72 69 74 69 63 69 73 | 6d 20 6f 6e 20 63 6f 6d |criticis|m on com|
|00001e70| 70 2e 6c 61 6e 67 2e 61 | 64 61 3a 0a 0a 20 20 20 |p.lang.a|da:.. |
|00001e80| 43 6f 6d 69 6e 67 20 75 | 70 20 77 69 74 68 20 61 |Coming u|p with a|
|00001e90| 20 73 79 6e 74 61 78 20 | 66 6f 72 20 6d 75 6c 74 | syntax |for mult|
|00001ea0| 69 70 6c 65 20 69 6e 68 | 65 72 69 74 61 6e 63 65 |iple inh|eritance|
|00001eb0| 20 77 61 73 20 6e 6f 74 | 20 74 68 65 0a 20 20 20 | was not| the. |
|00001ec0| 63 68 61 6c 6c 65 6e 67 | 65 2e 20 54 68 65 20 63 |challeng|e. The c|
|00001ed0| 68 61 6c 6c 65 6e 67 65 | 20 77 61 73 20 63 6f 6d |hallenge| was com|
|00001ee0| 69 6e 67 20 75 70 20 77 | 69 74 68 20 61 20 73 65 |ing up w|ith a se|
|00001ef0| 74 20 6f 66 20 73 74 72 | 61 69 67 68 74 66 6f 72 |t of str|aightfor|
|00001f00| 77 61 72 64 0a 20 20 20 | 79 65 74 20 66 6c 65 78 |ward. |yet flex|
|00001f10| 69 62 6c 65 20 72 75 6c | 65 73 20 66 6f 72 20 72 |ible rul|es for r|
|00001f20| 65 73 6f 6c 76 69 6e 67 | 20 74 68 65 20 77 65 6c |esolving| the wel|
|00001f30| 6c 20 6b 6e 6f 77 6e 20 | 70 72 6f 62 6c 65 6d 73 |l known |problems|
|00001f40| 20 61 73 73 6f 63 69 61 | 74 65 64 0a 20 20 20 77 | associa|ted. w|
|00001f50| 69 74 68 20 6d 75 6c 74 | 69 70 6c 65 20 69 6e 68 |ith mult|iple inh|
|00001f60| 65 72 69 74 61 6e 63 65 | 2c 20 6e 61 6d 65 6c 79 |eritance|, namely|
|00001f70| 3a 0a 20 20 20 20 20 2a | 20 49 66 20 74 68 65 20 |:. *| If the |
|00001f80| 73 61 6d 65 20 74 79 70 | 65 20 61 70 70 65 61 72 |same typ|e appear|
|00001f90| 73 20 61 73 20 61 6e 20 | 61 6e 63 65 73 74 6f 72 |s as an |ancestor|
|00001fa0| 20 6d 6f 72 65 20 74 68 | 61 6e 20 6f 6e 63 65 2c | more th|an once,|
|00001fb0| 20 73 68 6f 75 6c 64 20 | 61 6c 6c 0a 20 20 20 20 | should |all. |
|00001fc0| 20 20 20 6f 72 20 73 6f | 6d 65 20 6f 66 20 69 74 | or so|me of it|
|00001fd0| 73 20 64 61 74 61 20 63 | 6f 6d 70 6f 6e 65 6e 74 |s data c|omponent|
|00001fe0| 73 20 62 65 20 64 75 70 | 6c 69 63 61 74 65 64 2c |s be dup|licated,|
|00001ff0| 20 6f 72 20 73 68 61 72 | 65 64 3f 20 49 66 20 61 | or shar|ed? If a|
|00002000| 6e 79 0a 20 20 20 20 20 | 20 20 61 72 65 20 64 75 |ny. | are du|
|00002010| 70 6c 69 63 61 74 65 64 | 2c 20 68 6f 77 20 61 72 |plicated|, how ar|
|00002020| 65 20 74 68 65 79 20 72 | 65 66 65 72 65 6e 63 65 |e they r|eference|
|00002030| 64 20 75 6e 61 6d 62 69 | 67 75 6f 75 73 6c 79 3f |d unambi|guously?|
|00002040| 0a 0a 20 20 20 20 20 2a | 20 49 66 20 74 68 65 20 |.. *| If the |
|00002050| 73 61 6d 65 2d 6e 61 6d | 65 64 20 28 69 6e 63 6c |same-nam|ed (incl|
|00002060| 75 64 69 6e 67 20 73 61 | 6d 65 20 70 61 72 61 6d |uding sa|me param|
|00002070| 65 74 65 72 2f 72 65 73 | 75 6c 74 20 70 72 6f 66 |eter/res|ult prof|
|00002080| 69 6c 65 29 0a 20 20 20 | 20 20 20 20 6f 70 65 72 |ile). | oper|
|00002090| 61 74 69 6f 6e 20 69 73 | 20 69 6e 68 65 72 69 74 |ation is| inherit|
|000020a0| 65 64 20 61 6c 6f 6e 67 | 20 74 77 6f 20 70 61 74 |ed along| two pat|
|000020b0| 68 73 2c 20 68 6f 77 20 | 69 73 20 74 68 65 20 61 |hs, how |is the a|
|000020c0| 6d 62 69 67 75 69 74 79 | 0a 20 20 20 20 20 20 20 |mbiguity|. |
|000020d0| 72 65 73 6f 6c 76 65 64 | 3f 20 43 61 6e 20 79 6f |resolved|? Can yo|
|000020e0| 75 20 6f 76 65 72 72 69 | 64 65 20 65 61 63 68 20 |u overri|de each |
|000020f0| 77 69 74 68 20 64 69 66 | 66 65 72 65 6e 74 20 63 |with dif|ferent c|
|00002100| 6f 64 65 3f 20 48 6f 77 | 20 64 6f 20 79 6f 75 0a |ode? How| do you.|
|00002110| 20 20 20 20 20 20 20 72 | 65 66 65 72 20 74 6f 20 | r|efer to |
|00002120| 74 68 65 6d 20 6c 61 74 | 65 72 3f 0a 0a 20 20 20 |them lat|er?.. |
|00002130| 20 20 2a 20 45 74 63 2e | 0a 0a 0a 20 20 20 46 6f | * Etc.|... Fo|
|00002140| 72 20 61 6e 73 77 65 72 | 73 2c 20 79 6f 75 20 63 |r answer|s, you c|
|00002150| 61 6e 20 6c 6f 6f 6b 20 | 61 74 20 74 68 65 20 76 |an look |at the v|
|00002160| 61 72 69 6f 75 73 20 6c | 61 6e 67 75 61 67 65 73 |arious l|anguages|
|00002170| 20 74 68 61 74 20 64 65 | 66 69 6e 65 20 61 0a 20 | that de|fine a. |
|00002180| 20 20 62 75 69 6c 74 2d | 69 6e 20 61 70 70 72 6f | built-|in appro|
|00002190| 61 63 68 20 74 6f 20 6d | 75 6c 74 69 70 6c 65 20 |ach to m|ultiple |
|000021a0| 69 6e 68 65 72 69 74 61 | 6e 63 65 2e 20 55 6e 66 |inherita|nce. Unf|
|000021b0| 6f 72 74 75 6e 61 74 65 | 6c 79 2c 20 79 6f 75 20 |ortunate|ly, you |
|000021c0| 77 69 6c 6c 0a 20 20 20 | 67 65 6e 65 72 61 6c 6c |will. |generall|
|000021d0| 79 20 67 65 74 20 61 20 | 64 69 66 66 65 72 65 6e |y get a |differen|
|000021e0| 74 20 61 6e 73 77 65 72 | 20 66 6f 72 20 65 61 63 |t answer| for eac|
|000021f0| 68 20 6c 61 6e 67 75 61 | 67 65 20 2d 2d 20 68 61 |h langua|ge -- ha|
|00002200| 72 64 6c 79 20 61 0a 20 | 20 20 73 69 74 75 61 74 |rdly a. | situat|
|00002210| 69 6f 6e 20 74 68 61 74 | 20 73 75 67 67 65 73 74 |ion that| suggest|
|00002220| 73 20 77 65 20 77 69 6c | 6c 20 62 65 20 61 62 6c |s we wil|l be abl|
|00002230| 65 20 74 6f 20 63 72 61 | 66 74 20 61 6e 20 69 6e |e to cra|ft an in|
|00002240| 74 65 72 6e 61 74 69 6f | 6e 61 6c 0a 20 20 20 63 |ternatio|nal. c|
|00002250| 6f 6e 73 65 6e 73 75 73 | 2e 20 45 69 66 66 65 6c |onsensus|. Eiffel|
|00002260| 20 75 73 65 73 20 72 65 | 6e 61 6d 69 6e 67 20 61 | uses re|naming a|
|00002270| 6e 64 20 6f 74 68 65 72 | 20 74 65 63 68 6e 69 71 |nd other| techniq|
|00002280| 75 65 73 2c 20 77 68 69 | 63 68 20 73 65 65 6d 20 |ues, whi|ch seem |
|00002290| 71 75 69 74 65 0a 20 20 | 20 66 6c 65 78 69 62 6c |quite. | flexibl|
|000022a0| 65 2c 20 62 75 74 20 61 | 74 20 6c 65 61 73 74 20 |e, but a|t least |
|000022b0| 69 6e 20 73 6f 6d 65 20 | 65 78 61 6d 70 6c 65 73 |in some |examples|
|000022c0| 2c 20 63 61 6e 20 62 65 | 20 71 75 69 74 65 20 63 |, can be| quite c|
|000022d0| 6f 6e 66 75 73 69 6e 67 | 20 28 77 68 65 72 65 0a |onfusing| (where.|
|000022e0| 20 20 20 79 6f 75 20 6f | 76 65 72 72 69 64 65 20 | you o|verride |
|000022f0| 22 42 22 20 74 6f 20 63 | 68 61 6e 67 65 20 77 68 |"B" to c|hange wh|
|00002300| 61 74 20 22 41 22 20 64 | 6f 65 73 20 69 6e 20 73 |at "A" d|oes in s|
|00002310| 6f 6d 65 20 64 69 73 74 | 61 6e 74 20 61 6e 63 65 |ome dist|ant ance|
|00002320| 73 74 6f 72 29 2e 0a 20 | 20 20 43 2b 2b 20 68 61 |stor).. | C++ ha|
|00002330| 73 20 62 6f 74 68 20 6e | 6f 6e 2d 76 69 72 74 75 |s both n|on-virtu|
|00002340| 61 6c 20 61 6e 64 20 76 | 69 72 74 75 61 6c 20 62 |al and v|irtual b|
|00002350| 61 73 65 20 63 6c 61 73 | 65 73 2c 20 77 69 74 68 |ase clas|es, with|
|00002360| 20 61 20 6e 75 6d 62 65 | 72 20 6f 66 0a 20 20 20 | a numbe|r of. |
|00002370| 72 75 6c 65 73 20 61 73 | 73 6f 63 69 61 74 65 64 |rules as|sociated|
|00002380| 20 77 69 74 68 20 65 61 | 63 68 2c 20 61 6e 64 20 | with ea|ch, and |
|00002390| 76 61 72 69 6f 75 73 20 | 6c 69 6d 69 74 61 74 69 |various |limitati|
|000023a0| 6f 6e 73 20 72 65 6c 61 | 74 69 6e 67 20 74 6f 0a |ons rela|ting to.|
|000023b0| 20 20 20 64 6f 77 6e 63 | 61 73 74 69 6e 67 20 61 | downc|asting a|
|000023c0| 6e 64 20 76 69 72 74 75 | 61 6c 20 62 61 73 65 20 |nd virtu|al base |
|000023d0| 63 6c 61 73 73 65 73 2e | 20 43 4c 4f 53 20 75 73 |classes.| CLOS us|
|000023e0| 65 73 20 73 69 6d 70 6c | 65 20 6e 61 6d 65 20 6d |es simpl|e name m|
|000023f0| 61 74 63 68 69 6e 67 0a | 20 20 20 74 6f 20 63 6f |atching.| to co|
|00002400| 6e 74 72 6f 6c 20 22 73 | 6c 6f 74 22 20 6d 65 72 |ntrol "s|lot" mer|
|00002410| 67 69 6e 67 2e 20 53 6f | 6d 65 20 6c 61 6e 67 75 |ging. So|me langu|
|00002420| 61 67 65 73 20 72 65 71 | 75 69 72 65 20 74 68 61 |ages req|uire tha|
|00002430| 74 20 61 6c 6c 20 62 75 | 74 20 6f 6e 65 20 6f 66 |t all bu|t one of|
|00002440| 0a 20 20 20 74 68 65 20 | 70 61 72 65 6e 74 20 74 |. the |parent t|
|00002450| 79 70 65 73 20 62 65 20 | 61 62 73 74 72 61 63 74 |ypes be |abstract|
|00002460| 2c 20 64 61 74 61 2d 6c | 65 73 73 20 74 79 70 65 |, data-l|ess type|
|00002470| 73 2c 20 73 6f 20 6f 6e | 6c 79 20 69 6e 74 65 72 |s, so on|ly inter|
|00002480| 66 61 63 65 73 20 61 72 | 65 0a 20 20 20 62 65 69 |faces ar|e. bei|
|00002490| 6e 67 20 69 6e 68 65 72 | 69 74 65 64 3b 20 68 6f |ng inher|ited; ho|
|000024a0| 77 65 76 65 72 20 69 66 | 20 74 68 65 20 69 6e 74 |wever if| the int|
|000024b0| 65 72 66 61 63 65 73 20 | 68 61 70 70 65 6e 20 74 |erfaces |happen t|
|000024c0| 6f 20 63 6f 6c 6c 69 64 | 65 2c 20 79 6f 75 0a 20 |o collid|e, you. |
|000024d0| 20 20 73 74 69 6c 6c 20 | 63 61 6e 20 65 6e 64 20 | still |can end |
|000024e0| 75 70 20 77 69 74 68 20 | 75 6e 64 65 73 69 72 61 |up with |undesira|
|000024f0| 62 6c 65 20 61 6e 64 20 | 70 6f 74 65 6e 74 69 61 |ble and |potentia|
|00002500| 6c 6c 79 20 75 6e 72 65 | 73 6f 6c 76 61 62 6c 65 |lly unre|solvable|
|00002510| 0a 20 20 20 63 6f 6c 6c | 69 73 69 6f 6e 73 20 28 |. coll|isions (|
|00002520| 77 68 65 72 65 20 79 6f | 75 20 72 65 61 6c 6c 79 |where yo|u really|
|00002530| 20 77 61 6e 74 20 64 69 | 66 66 65 72 65 6e 74 20 | want di|fferent |
|00002540| 63 6f 64 65 20 66 6f 72 | 20 73 61 6d 65 2d 6e 61 |code for| same-na|
|00002550| 6d 65 64 0a 20 20 20 69 | 6e 74 65 72 66 61 63 65 |med. i|nterface|
|00002560| 73 20 69 6e 68 65 72 69 | 74 65 64 20 66 72 6f 6d |s inheri|ted from|
|00002570| 20 64 69 66 66 65 72 65 | 6e 74 20 61 6e 63 65 73 | differe|nt ances|
|00002580| 74 6f 72 73 29 2e 0a 0a | 20 20 20 4f 6e 65 20 61 |tors)...| One a|
|00002590| 72 67 75 6d 65 6e 74 20 | 69 73 20 74 68 61 74 20 |rgument |is that |
|000025a0| 63 6f 6c 6c 69 73 69 6f | 6e 73 20 61 72 65 20 72 |collisio|ns are r|
|000025b0| 61 72 65 20 74 6f 20 62 | 65 67 69 6e 20 77 69 74 |are to b|egin wit|
|000025c0| 68 2c 20 73 6f 20 69 74 | 20 64 6f 65 73 6e 27 74 |h, so it| doesn't|
|000025d0| 0a 20 20 20 6d 61 6b 65 | 20 6d 75 63 68 20 64 69 |. make| much di|
|000025e0| 66 66 65 72 65 6e 74 20 | 68 6f 77 20 74 68 65 79 |fferent |how they|
|000025f0| 20 61 72 65 20 72 65 73 | 6f 6c 76 65 64 2e 20 54 | are res|olved. T|
|00002600| 68 61 74 20 69 73 20 70 | 72 6f 62 61 62 6c 79 20 |hat is p|robably |
|00002610| 74 72 75 65 2c 20 62 75 | 74 0a 20 20 20 74 68 65 |true, bu|t. the|
|00002620| 20 61 72 67 75 6d 65 6e | 74 20 64 6f 65 73 6e 27 | argumen|t doesn'|
|00002630| 74 20 77 6f 72 6b 20 74 | 6f 6f 20 77 65 6c 6c 20 |t work t|oo well |
|00002640| 64 75 72 69 6e 67 20 61 | 6e 20 6f 70 65 6e 20 6c |during a|n open l|
|00002650| 61 6e 67 75 61 67 65 20 | 64 65 73 69 67 6e 0a 20 |anguage |design. |
|00002660| 20 20 70 72 6f 63 65 73 | 73 20 2d 2d 20 70 65 6f | proces|s -- peo|
|00002670| 70 6c 65 20 67 65 74 20 | 75 70 73 65 74 20 61 74 |ple get |upset at|
|00002680| 20 74 68 65 20 6d 6f 73 | 74 20 75 6e 62 65 6c 69 | the mos|t unbeli|
|00002690| 65 76 61 62 6c 79 20 74 | 72 69 76 69 61 6c 20 61 |evably t|rivial a|
|000026a0| 6e 64 0a 20 20 20 72 61 | 72 65 6c 79 20 75 73 65 |nd. ra|rely use|
|000026b0| 64 20 66 65 61 74 75 72 | 65 73 20 69 66 20 6e 6f |d featur|es if no|
|000026c0| 74 20 22 63 6f 72 72 65 | 63 74 6c 79 22 20 64 65 |t "corre|ctly" de|
|000026d0| 73 69 67 6e 65 64 20 28 | 73 70 65 61 6b 69 6e 67 |signed (|speaking|
|000026e0| 20 66 72 6f 6d 0a 20 20 | 20 65 78 70 65 72 69 65 | from. | experie|
|000026f0| 6e 63 65 20 68 65 72 65 | 20 3b 2d 29 2e 0a 0a 20 |nce here| ;-)... |
|00002700| 20 20 46 75 72 74 68 65 | 72 6d 6f 72 65 2c 20 67 | Furthe|rmore, g|
|00002710| 69 76 65 6e 20 74 68 61 | 74 20 6d 61 6e 79 20 6f |iven tha|t many o|
|00002720| 66 20 74 68 65 20 70 72 | 65 64 6f 6d 69 6e 61 6e |f the pr|edominan|
|00002730| 74 20 75 73 65 73 20 6f | 66 20 4d 49 20 28 73 65 |t uses o|f MI (se|
|00002740| 70 61 72 61 74 69 6f 6e | 0a 20 20 20 6f 66 20 69 |paration|. of i|
|00002750| 6e 74 65 72 66 61 63 65 | 20 69 6e 68 65 72 69 74 |nterface| inherit|
|00002760| 61 6e 63 65 20 66 72 6f | 6d 20 69 6d 70 6c 65 6d |ance fro|m implem|
|00002770| 65 6e 74 61 74 69 6f 6e | 20 69 6e 68 65 72 69 74 |entation| inherit|
|00002780| 61 6e 63 65 2c 20 67 61 | 69 6e 69 6e 67 0a 20 20 |ance, ga|ining. |
|00002790| 20 63 6f 6e 76 65 6e 69 | 65 6e 74 20 61 63 63 65 | conveni|ent acce|
|000027a0| 73 73 20 74 6f 20 61 6e | 6f 74 68 65 72 20 63 6c |ss to an|other cl|
|000027b0| 61 73 73 27 73 20 66 65 | 61 74 75 72 65 73 2c 20 |ass's fe|atures, |
|000027c0| 68 61 73 2d 61 20 72 65 | 6c 61 74 69 6f 6e 73 68 |has-a re|lationsh|
|000027d0| 69 70 73 0a 20 20 20 62 | 65 69 6e 67 20 63 6f 64 |ips. b|eing cod|
|000027e0| 65 64 20 75 73 69 6e 67 | 20 4d 49 20 66 6f 72 20 |ed using| MI for |
|000027f0| 63 6f 6e 76 65 6e 69 65 | 6e 63 65 2c 20 65 74 63 |convenie|nce, etc|
|00002800| 2e 29 20 61 72 65 20 61 | 6c 72 65 61 64 79 20 68 |.) are a|lready h|
|00002810| 61 6e 64 6c 65 64 20 76 | 65 72 79 0a 20 20 20 77 |andled v|ery. w|
|00002820| 65 6c 6c 20 69 6e 20 41 | 64 61 20 39 58 2c 20 69 |ell in A|da 9X, i|
|00002830| 74 20 69 73 20 68 61 72 | 64 20 74 6f 20 6a 75 73 |t is har|d to jus|
|00002840| 74 69 66 79 20 67 65 74 | 74 69 6e 67 20 69 6e 74 |tify get|ting int|
|00002850| 6f 20 74 68 65 20 4d 49 | 20 6c 61 6e 67 75 61 67 |o the MI| languag|
|00002860| 65 0a 20 20 20 64 65 73 | 69 67 6e 20 66 72 61 79 |e. des|ign fray|
|00002870| 20 61 74 20 61 6c 6c 2e | 20 54 68 65 20 62 61 73 | at all.| The bas|
|00002880| 69 63 20 69 6e 68 65 72 | 69 74 61 6e 63 65 20 6d |ic inher|itance m|
|00002890| 6f 64 65 6c 20 69 6e 20 | 41 64 61 20 39 58 20 69 |odel in |Ada 9X i|
|000028a0| 73 20 73 69 6d 70 6c 65 | 0a 20 20 20 61 6e 64 20 |s simple|. and |
|000028b0| 65 6c 65 67 61 6e 74 2e | 20 57 68 79 20 63 6c 75 |elegant.| Why clu|
|000028c0| 74 74 65 72 20 69 74 20 | 75 70 20 77 69 74 68 20 |tter it |up with |
|000028d0| 61 20 6c 6f 74 20 6f 66 | 20 72 65 6c 61 74 69 76 |a lot of| relativ|
|000028e0| 65 6c 79 20 61 64 2d 68 | 6f 63 20 72 75 6c 65 73 |ely ad-h|oc rules|
|000028f0| 0a 20 20 20 74 6f 20 68 | 61 6e 64 6c 65 20 6f 6e |. to h|andle on|
|00002900| 65 20 70 61 72 74 69 63 | 75 6c 61 72 20 61 70 70 |e partic|ular app|
|00002910| 72 6f 61 63 68 20 74 6f | 20 4d 49 3f 20 46 6f 72 |roach to| MI? For|
|00002920| 20 74 68 65 20 72 61 72 | 65 20 63 61 73 65 73 20 | the rar|e cases |
|00002930| 77 68 65 72 65 20 4d 49 | 0a 20 20 20 69 73 20 72 |where MI|. is r|
|00002940| 65 61 6c 6c 79 20 63 72 | 69 74 69 63 61 6c 2c 20 |eally cr|itical, |
|00002950| 74 68 65 20 6c 61 73 74 | 20 74 68 69 6e 67 20 74 |the last| thing t|
|00002960| 68 65 20 70 72 6f 67 72 | 61 6d 6d 65 72 20 77 61 |he progr|ammer wa|
|00002970| 6e 74 73 20 69 6e 20 74 | 68 65 0a 20 20 20 6c 61 |nts in t|he. la|
|00002980| 6e 67 75 61 67 65 20 69 | 73 20 74 68 65 20 22 77 |nguage i|s the "w|
|00002990| 72 6f 6e 67 22 20 4d 49 | 20 61 70 70 72 6f 61 63 |rong" MI| approac|
|000029a0| 68 20 62 75 69 6c 74 20 | 69 6e 2e 0a 0a 20 20 20 |h built |in... |
|000029b0| 53 6f 20 74 68 65 20 62 | 61 73 69 63 20 61 6e 73 |So the b|asic ans|
|000029c0| 77 65 72 20 69 73 20 74 | 68 61 74 20 61 74 20 74 |wer is t|hat at t|
|000029d0| 68 69 73 20 70 6f 69 6e | 74 20 69 6e 20 74 68 65 |his poin|t in the|
|000029e0| 20 65 76 6f 6c 75 74 69 | 6f 6e 20 6f 66 20 4f 4f | evoluti|on of OO|
|000029f0| 0a 20 20 20 6c 61 6e 67 | 75 61 67 65 20 64 65 73 |. lang|uage des|
|00002a00| 69 67 6e 2c 20 69 74 20 | 73 65 65 6d 65 64 20 77 |ign, it |seemed w|
|00002a10| 69 73 65 72 20 74 6f 20 | 70 72 6f 76 69 64 65 20 |iser to |provide |
|00002a20| 4d 49 20 62 75 69 6c 64 | 69 6e 67 20 62 6c 6f 63 |MI build|ing bloc|
|00002a30| 6b 73 2c 20 72 61 74 68 | 65 72 0a 20 20 20 74 68 |ks, rath|er. th|
|00002a40| 61 6e 20 74 6f 20 66 6f | 69 73 74 20 74 68 65 20 |an to fo|ist the |
|00002a50| 77 72 6f 6e 67 20 61 70 | 70 72 6f 61 63 68 20 6f |wrong ap|proach o|
|00002a60| 6e 20 74 68 65 20 70 72 | 6f 67 72 61 6d 6d 65 72 |n the pr|ogrammer|
|00002a70| 2c 20 61 6e 64 20 62 65 | 20 72 65 67 72 65 74 74 |, and be| regrett|
|00002a80| 69 6e 67 0a 20 20 20 69 | 74 20 61 6e 64 20 77 6f |ing. i|t and wo|
|00002a90| 72 6b 69 6e 67 20 61 72 | 6f 75 6e 64 20 69 74 20 |rking ar|ound it |
|00002aa0| 66 6f 72 20 79 65 61 72 | 73 20 74 6f 20 63 6f 6d |for year|s to com|
|00002ab0| 65 2e 0a 0a 20 20 20 50 | 65 72 68 61 70 73 20 5b |e... P|erhaps [|
|00002ac0| 44 6f 75 67 6c 61 73 20 | 41 72 6e 64 74 5d 20 73 |Douglas |Arndt] s|
|00002ad0| 61 69 64 20 69 74 20 62 | 65 73 74 2e 2e 2e 0a 0a |aid it b|est.....|
|00002ae0| 20 20 20 20 20 46 69 6e | 61 6c 20 6e 6f 74 65 3a | Fin|al note:|
|00002af0| 20 69 6e 68 65 72 69 74 | 61 6e 63 65 20 69 73 20 | inherit|ance is |
|00002b00| 6f 76 65 72 72 61 74 65 | 64 2c 20 65 73 70 65 63 |overrate|d, espec|
|00002b10| 69 61 6c 6c 79 20 4d 49 | 2e 20 2e 2e 2e 0a 0a 0a |ially MI|. ......|
|00002b20| 20 20 20 49 66 20 74 68 | 65 20 6f 6e 6c 79 20 6f | If th|e only o|
|00002b30| 72 20 70 72 69 6d 61 72 | 79 20 74 79 70 65 20 63 |r primar|y type c|
|00002b40| 6f 6d 70 6f 73 69 74 69 | 6f 6e 20 6d 65 63 68 61 |ompositi|on mecha|
|00002b50| 6e 69 73 6d 20 69 6e 20 | 74 68 65 20 6c 61 6e 67 |nism in |the lang|
|00002b60| 75 61 67 65 20 69 73 0a | 20 20 20 62 61 73 65 64 |uage is.| based|
|00002b70| 20 6f 6e 20 69 6e 68 65 | 72 69 74 61 6e 63 65 2c | on inhe|ritance,|
|00002b80| 20 74 68 65 6e 20 62 79 | 20 61 6c 6c 20 6d 65 61 | then by| all mea|
|00002b90| 6e 73 2c 20 6c 6f 61 64 | 20 69 74 20 75 70 2e 20 |ns, load| it up. |
|00002ba0| 42 75 74 20 41 64 61 20 | 39 58 0a 20 20 20 70 72 |But Ada |9X. pr|
|00002bb0| 6f 76 69 64 65 73 20 73 | 65 76 65 72 61 6c 20 65 |ovides s|everal e|
|00002bc0| 66 66 69 63 69 65 6e 74 | 20 61 6e 64 20 66 6c 65 |fficient| and fle|
|00002bd0| 78 69 62 6c 65 20 74 79 | 70 65 20 63 6f 6d 70 6f |xible ty|pe compo|
|00002be0| 73 69 74 69 6f 6e 20 6d | 65 63 68 61 6e 69 73 6d |sition m|echanism|
|00002bf0| 73 2c 0a 20 20 20 61 6e | 64 20 74 68 65 72 65 20 |s,. an|d there |
|00002c00| 69 73 20 6e 6f 20 6e 65 | 65 64 20 74 6f 20 6f 76 |is no ne|ed to ov|
|00002c10| 65 72 62 75 72 64 65 6e | 20 69 6e 68 65 72 69 74 |erburden| inherit|
|00002c20| 61 6e 63 65 20 77 69 74 | 68 20 75 6e 6e 65 63 65 |ance wit|h unnece|
|00002c30| 73 73 61 72 79 20 61 6e | 64 0a 20 20 20 63 6f 6d |ssary an|d. com|
|00002c40| 70 6c 69 63 61 74 65 64 | 20 62 61 67 67 61 67 65 |plicated| baggage|
|00002c50| 2e 0a 0a 0a 35 2e 35 3a | 20 57 68 79 20 61 72 65 |....5.5:| Why are|
|00002c60| 20 43 6f 6e 74 72 6f 6c | 6c 65 64 20 74 79 70 65 | Control|led type|
|00002c70| 73 20 73 6f 2c 20 77 65 | 6c 6c 2c 20 73 74 72 61 |s so, we|ll, stra|
|00002c80| 6e 67 65 3f 0a 0a 20 20 | 20 28 54 75 63 6b 65 72 |nge?.. | (Tucker|
|00002c90| 20 54 61 66 74 20 72 65 | 73 70 6f 6e 64 73 29 3a | Taft re|sponds):|
|00002ca0| 0a 0a 20 20 20 57 65 20 | 63 6f 6e 73 69 64 65 72 |.. We |consider|
|00002cb0| 65 64 20 6d 61 6e 79 20 | 61 70 70 72 6f 61 63 68 |ed many |approach|
|00002cc0| 65 73 20 74 6f 20 75 73 | 65 72 2d 64 65 66 69 6e |es to us|er-defin|
|00002cd0| 65 64 20 66 69 6e 61 6c | 69 7a 61 74 69 6f 6e 20 |ed final|ization |
|00002ce0| 61 6e 64 0a 20 20 20 75 | 73 65 72 2d 64 65 66 69 |and. u|ser-defi|
|00002cf0| 6e 65 64 20 61 73 73 69 | 67 6e 6d 65 6e 74 2e 20 |ned assi|gnment. |
|00002d00| 41 64 61 20 70 72 65 73 | 65 6e 74 73 20 63 68 61 |Ada pres|ents cha|
|00002d10| 6c 6c 65 6e 67 65 73 20 | 74 68 61 74 20 6d 61 6b |llenges |that mak|
|00002d20| 65 20 69 74 20 68 61 72 | 64 65 72 0a 20 20 20 74 |e it har|der. t|
|00002d30| 6f 20 64 65 66 69 6e 65 | 20 61 73 73 69 67 6e 6d |o define| assignm|
|00002d40| 65 6e 74 20 74 68 61 6e | 20 69 6e 20 6f 74 68 65 |ent than| in othe|
|00002d50| 72 20 6c 61 6e 67 75 61 | 67 65 73 2c 20 62 65 63 |r langua|ges, bec|
|00002d60| 61 75 73 65 20 61 73 73 | 69 67 6e 6d 65 6e 74 20 |ause ass|ignment |
|00002d70| 69 73 0a 20 20 20 75 73 | 65 64 20 69 6d 70 6c 69 |is. us|ed impli|
|00002d80| 63 69 74 6c 79 20 69 6e | 20 73 65 76 65 72 61 6c |citly in| several|
|00002d90| 20 6f 70 65 72 61 74 69 | 6f 6e 73 20 28 62 79 2d | operati|ons (by-|
|00002da0| 63 6f 70 79 20 70 61 72 | 61 6d 65 74 65 72 20 70 |copy par|ameter p|
|00002db0| 61 73 73 69 6e 67 2c 0a | 20 20 20 66 75 6e 63 74 |assing,.| funct|
|00002dc0| 69 6f 6e 20 72 65 74 75 | 72 6e 2c 20 61 67 67 72 |ion retu|rn, aggr|
|00002dd0| 65 67 61 74 65 73 2c 20 | 6f 62 6a 65 63 74 20 69 |egates, |object i|
|00002de0| 6e 69 74 69 61 6c 69 7a | 61 74 69 6f 6e 2c 20 69 |nitializ|ation, i|
|00002df0| 6e 69 74 69 61 6c 69 7a | 65 64 0a 20 20 20 61 6c |nitializ|ed. al|
|00002e00| 6c 6f 63 61 74 6f 72 73 | 2c 20 65 74 63 2e 29 2c |locators|, etc.),|
|00002e10| 20 61 6e 64 20 62 65 63 | 61 75 73 65 20 41 64 61 | and bec|ause Ada|
|00002e20| 20 68 61 73 20 74 79 70 | 65 73 20 77 68 6f 73 65 | has typ|es whose|
|00002e30| 20 73 65 74 20 6f 66 20 | 63 6f 6d 70 6f 6e 65 6e | set of |componen|
|00002e40| 74 73 0a 20 20 20 63 61 | 6e 20 62 65 20 63 68 61 |ts. ca|n be cha|
|00002e50| 6e 67 65 64 20 61 73 20 | 61 20 72 65 73 75 6c 74 |nged as |a result|
|00002e60| 20 6f 66 20 61 6e 20 61 | 73 73 69 67 6e 6d 65 6e | of an a|ssignmen|
|00002e70| 74 2e 0a 0a 20 20 20 46 | 6f 72 20 65 78 61 6d 70 |t... F|or examp|
|00002e80| 6c 65 3a 0a 0a 20 20 20 | 20 20 74 79 70 65 20 54 |le:.. | type T|
|00002e90| 20 28 44 20 3a 20 42 6f | 6f 6c 65 61 6e 20 3a 3d | (D : Bo|olean :=|
|00002ea0| 20 46 61 6c 73 65 29 20 | 69 73 20 72 65 63 6f 72 | False) |is recor|
|00002eb0| 64 0a 20 20 20 20 20 20 | 20 63 61 73 65 20 44 20 |d. | case D |
|00002ec0| 69 73 0a 20 20 20 20 20 | 20 20 20 20 77 68 65 6e |is. | when|
|00002ed0| 20 46 61 6c 73 65 20 3d | 3e 20 6e 75 6c 6c 3b 0a | False =|> null;.|
|00002ee0| 20 20 20 20 20 20 20 20 | 20 77 68 65 6e 20 54 72 | | when Tr|
|00002ef0| 75 65 20 3d 3e 20 48 20 | 3a 20 49 6e 5f 48 61 6e |ue => H |: In_Han|
|00002f00| 64 73 3b 0a 20 20 20 20 | 20 20 20 65 6e 64 20 63 |ds;. | end c|
|00002f10| 61 73 65 3b 0a 20 20 20 | 20 20 65 6e 64 20 72 65 |ase;. | end re|
|00002f20| 63 6f 72 64 3b 0a 0a 20 | 20 20 20 20 58 2c 5a 20 |cord;.. | X,Z |
|00002f30| 3a 20 54 3b 0a 20 20 20 | 20 20 59 20 3a 20 54 20 |: T;. | Y : T |
|00002f40| 3a 3d 20 28 54 72 75 65 | 2c 20 48 20 3d 3e 20 2e |:= (True|, H => .|
|00002f50| 2e 2e 29 3b 0a 0a 20 20 | 20 20 20 2e 2e 2e 0a 0a |..);.. | .....|
|00002f60| 20 20 20 20 20 58 20 3a | 3d 20 59 3b 20 20 20 2d | X :|= Y; -|
|00002f70| 2d 20 22 58 2e 48 22 20 | 63 6f 6d 70 6f 6e 65 6e |- "X.H" |componen|
|00002f80| 74 20 63 6f 6d 69 6e 67 | 20 69 6e 74 6f 20 65 78 |t coming| into ex|
|00002f90| 69 73 74 65 6e 63 65 0a | 20 20 20 20 20 59 20 3a |istence.| Y :|
|00002fa0| 3d 20 5a 3b 20 20 20 2d | 2d 20 22 59 2e 48 22 20 |= Z; -|- "Y.H" |
|00002fb0| 63 6f 6d 70 6f 6e 65 6e | 74 20 67 6f 69 6e 67 20 |componen|t going |
|00002fc0| 6f 75 74 20 6f 66 20 65 | 78 69 73 74 65 6e 63 65 |out of e|xistence|
|00002fd0| 0a 0a 0a 20 20 20 57 69 | 74 68 20 61 20 74 79 70 |... Wi|th a typ|
|00002fe0| 65 20 6c 69 6b 65 20 74 | 68 65 20 6f 6e 65 20 61 |e like t|he one a|
|00002ff0| 62 6f 76 65 2c 20 74 68 | 65 72 65 20 61 72 65 20 |bove, th|ere are |
|00003000| 63 6f 6d 70 6f 6e 65 6e | 74 73 20 74 68 61 74 20 |componen|ts that |
|00003010| 63 61 6e 20 63 6f 6d 65 | 20 61 6e 64 0a 20 20 20 |can come| and. |
|00003020| 67 6f 20 61 73 20 61 20 | 72 65 73 75 6c 74 20 6f |go as a |result o|
|00003030| 66 20 61 73 73 69 67 6e | 6d 65 6e 74 2e 20 54 68 |f assign|ment. Th|
|00003040| 65 20 6d 6f 73 74 20 6f | 62 76 69 6f 75 73 20 64 |e most o|bvious d|
|00003050| 65 66 69 6e 69 74 69 6f | 6e 20 6f 66 0a 20 20 20 |efinitio|n of. |
|00003060| 61 73 73 69 67 6e 6d 65 | 6e 74 20 77 6f 75 6c 64 |assignme|nt would|
|00003070| 20 62 65 3a 0a 0a 20 20 | 20 20 20 70 72 6f 63 65 | be:.. | proce|
|00003080| 64 75 72 65 20 22 3a 3d | 22 20 28 4c 65 66 74 20 |dure ":=|" (Left |
|00003090| 3a 20 69 6e 20 6f 75 74 | 20 49 6e 5f 48 61 6e 64 |: in out| In_Hand|
|000030a0| 73 3b 20 52 69 67 68 74 | 20 3a 20 69 6e 20 49 6e |s; Right| : in In|
|000030b0| 5f 48 61 6e 64 73 29 3b | 0a 0a 0a 20 20 20 55 6e |_Hands);|... Un|
|000030c0| 66 6f 72 74 75 6e 61 74 | 65 6c 79 2c 20 74 68 69 |fortunat|ely, thi|
|000030d0| 73 20 77 6f 75 6c 64 6e | 27 74 20 77 6f 72 6b 20 |s wouldn|'t work |
|000030e0| 66 6f 72 20 74 68 65 20 | 22 48 22 20 63 6f 6d 70 |for the |"H" comp|
|000030f0| 6f 6e 65 6e 74 2c 20 62 | 65 63 61 75 73 65 20 74 |onent, b|ecause t|
|00003100| 68 65 72 65 0a 20 20 20 | 69 73 20 6e 6f 20 70 72 |here. |is no pr|
|00003110| 65 65 78 69 73 74 69 6e | 67 20 22 49 6e 5f 48 61 |eexistin|g "In_Ha|
|00003120| 6e 64 73 22 20 63 6f 6d | 70 6f 6e 65 6e 74 20 74 |nds" com|ponent t|
|00003130| 6f 20 62 65 20 61 73 73 | 69 67 6e 65 64 20 69 6e |o be ass|igned in|
|00003140| 74 6f 20 69 6e 20 74 68 | 65 0a 20 20 20 66 69 72 |to in th|e. fir|
|00003150| 73 74 20 63 61 73 65 2c | 20 61 6e 64 20 69 6e 20 |st case,| and in |
|00003160| 74 68 65 20 73 65 63 6f | 6e 64 20 63 61 73 65 2c |the seco|nd case,|
|00003170| 20 74 68 65 72 65 20 69 | 73 20 6e 6f 20 22 49 6e | there i|s no "In|
|00003180| 5f 48 61 6e 64 73 22 20 | 63 6f 6d 70 6f 6e 65 6e |_Hands" |componen|
|00003190| 74 0a 20 20 20 74 6f 20 | 61 73 73 69 67 6e 20 22 |t. to |assign "|
|000031a0| 66 72 6f 6d 2e 22 0a 0a | 20 20 20 54 68 65 72 65 |from."..| There|
|000031b0| 66 6f 72 65 2c 20 77 65 | 20 64 65 63 69 64 65 64 |fore, we| decided|
|000031c0| 20 74 6f 20 64 65 63 6f | 6d 70 6f 73 65 20 74 68 | to deco|mpose th|
|000031d0| 65 20 6f 70 65 72 61 74 | 69 6f 6e 20 6f 66 20 61 |e operat|ion of a|
|000031e0| 73 73 69 67 6e 6d 65 6e | 74 20 69 6e 74 6f 0a 20 |ssignmen|t into. |
|000031f0| 20 20 73 65 70 61 72 61 | 62 6c 65 20 70 69 65 63 | separa|ble piec|
|00003200| 65 73 3a 20 66 69 6e 61 | 6c 69 7a 61 74 69 6f 6e |es: fina|lization|
|00003210| 20 6f 66 20 74 68 65 20 | 6c 65 66 74 20 68 61 6e | of the |left han|
|00003220| 64 20 73 69 64 65 3b 20 | 73 69 6d 70 6c 65 20 63 |d side; |simple c|
|00003230| 6f 70 79 69 6e 67 0a 20 | 20 20 6f 66 20 74 68 65 |opying. | of the|
|00003240| 20 64 61 74 61 20 66 72 | 6f 6d 20 74 68 65 20 72 | data fr|om the r|
|00003250| 69 67 68 74 20 68 61 6e | 64 20 73 69 64 65 20 74 |ight han|d side t|
|00003260| 6f 20 74 68 65 20 6c 65 | 66 74 20 68 61 6e 64 20 |o the le|ft hand |
|00003270| 73 69 64 65 3b 20 61 6e | 64 20 74 68 65 6e 0a 20 |side; an|d then. |
|00003280| 20 20 61 64 6a 75 73 74 | 6d 65 6e 74 20 6f 66 20 | adjust|ment of |
|00003290| 74 68 65 20 6e 65 77 20 | 6c 65 66 74 20 68 61 6e |the new |left han|
|000032a0| 64 20 73 69 64 65 2e 20 | 4f 74 68 65 72 20 64 65 |d side. |Other de|
|000032b0| 63 6f 6d 70 6f 73 69 74 | 69 6f 6e 73 20 61 72 65 |composit|ions are|
|000032c0| 0a 20 20 20 70 72 6f 62 | 61 62 6c 79 20 70 6f 73 |. prob|ably pos|
|000032d0| 73 69 62 6c 65 2c 20 62 | 75 74 20 74 68 65 79 20 |sible, b|ut they |
|000032e0| 67 65 6e 65 72 61 6c 6c | 79 20 73 75 66 66 65 72 |generall|y suffer|
|000032f0| 20 66 72 6f 6d 20 6e 6f | 74 20 62 65 69 6e 67 20 | from no|t being |
|00003300| 65 61 73 69 6c 79 0a 20 | 20 20 63 6f 6d 70 6f 73 |easily. | compos|
|00003310| 61 62 6c 65 2c 20 6f 72 | 20 6e 6f 74 20 68 61 6e |able, or| not han|
|00003320| 64 6c 69 6e 67 20 73 69 | 74 75 61 74 69 6f 6e 73 |dling si|tuations|
|00003330| 20 6c 69 6b 65 20 74 68 | 65 20 76 61 72 69 61 6e | like th|e varian|
|00003340| 74 20 72 65 63 6f 72 64 | 20 61 62 6f 76 65 2e 0a |t record| above..|
|00003350| 0a 20 20 20 49 6d 61 67 | 69 6e 65 20 61 20 66 75 |. Imag|ine a fu|
|00003360| 6e 63 74 69 6f 6e 20 6e | 61 6d 65 64 20 22 3a 3d |nction n|amed ":=|
|00003370| 22 20 74 68 61 74 20 72 | 65 74 75 72 6e 73 20 61 |" that r|eturns a|
|00003380| 20 63 6f 70 79 20 6f 66 | 20 69 74 73 20 69 6e 20 | copy of| its in |
|00003390| 70 61 72 61 6d 65 74 65 | 72 2e 0a 20 20 20 54 6f |paramete|r.. To|
|000033a0| 20 64 6f 20 61 6e 79 74 | 68 69 6e 67 20 69 6e 74 | do anyt|hing int|
|000033b0| 65 72 65 73 74 69 6e 67 | 20 69 74 20 77 69 6c 6c |eresting| it will|
|000033c0| 20 68 61 76 65 20 74 6f | 20 63 6f 70 79 20 74 68 | have to| copy th|
|000033d0| 65 20 69 6e 20 70 61 72 | 61 6d 65 74 65 72 20 69 |e in par|ameter i|
|000033e0| 6e 74 6f 0a 20 20 20 61 | 20 6c 6f 63 61 6c 20 76 |nto. a| local v|
|000033f0| 61 72 69 61 62 6c 65 2c | 20 61 6e 64 20 74 68 65 |ariable,| and the|
|00003400| 6e 20 22 66 69 64 64 6c | 65 22 20 77 69 74 68 20 |n "fiddl|e" with |
|00003410| 74 68 61 74 20 6c 6f 63 | 61 6c 20 76 61 72 69 61 |that loc|al varia|
|00003420| 62 6c 65 0a 20 20 20 28 | 65 73 73 65 6e 74 69 61 |ble. (|essentia|
|00003430| 6c 6c 79 20 77 68 61 74 | 20 22 41 64 6a 75 73 74 |lly what| "Adjust|
|00003440| 22 20 64 6f 65 73 29 2c | 20 61 6e 64 20 74 68 65 |" does),| and the|
|00003450| 6e 20 72 65 74 75 72 6e | 20 74 68 61 74 20 6c 6f |n return| that lo|
|00003460| 63 61 6c 20 76 61 72 69 | 61 62 6c 65 0a 20 20 20 |cal vari|able. |
|00003470| 28 77 68 69 63 68 20 77 | 69 6c 6c 20 6d 61 6b 65 |(which w|ill make|
|00003480| 20 79 65 74 20 61 6e 6f | 74 68 65 72 20 63 6f 70 | yet ano|ther cop|
|00003490| 79 29 2e 20 54 68 65 20 | 72 65 74 75 72 6e 65 64 |y). The |returned|
|000034a0| 20 72 65 73 75 6c 74 20 | 77 69 6c 6c 20 68 61 76 | result |will hav|
|000034b0| 65 20 74 6f 0a 20 20 20 | 62 65 20 70 75 74 20 62 |e to. |be put b|
|000034c0| 61 63 6b 20 69 6e 74 6f | 20 74 68 65 20 64 65 73 |ack into| the des|
|000034d0| 69 72 65 64 20 70 6c 61 | 63 65 20 28 77 68 69 63 |ired pla|ce (whic|
|000034e0| 68 20 6d 69 67 68 74 20 | 6d 61 6b 65 20 79 65 74 |h might |make yet|
|000034f0| 20 61 6e 6f 74 68 65 72 | 0a 20 20 20 63 6f 70 79 | another|. copy|
|00003500| 29 2e 20 46 6f 72 20 61 | 20 6c 61 72 67 65 20 6f |). For a| large o|
|00003510| 62 6a 65 63 74 2c 20 74 | 68 69 73 20 6d 69 67 68 |bject, t|his migh|
|00003520| 74 20 69 6e 76 6f 6c 76 | 65 20 73 65 76 65 72 61 |t involv|e severa|
|00003530| 6c 20 65 78 74 72 61 20 | 63 6f 70 69 65 73 2e 0a |l extra |copies..|
|00003540| 0a 20 20 20 42 79 20 68 | 61 76 69 6e 67 20 74 68 |. By h|aving th|
|00003550| 65 20 75 73 65 72 20 77 | 72 69 74 65 20 6a 75 73 |e user w|rite jus|
|00003560| 74 20 74 68 61 74 20 70 | 61 72 74 20 6f 66 20 74 |t that p|art of t|
|00003570| 68 65 20 6f 70 65 72 61 | 74 69 6f 6e 20 74 68 61 |he opera|tion tha|
|00003580| 74 0a 20 20 20 22 66 69 | 64 64 6c 65 73 22 20 77 |t. "fi|ddles" w|
|00003590| 69 74 68 20 74 68 65 20 | 72 65 73 75 6c 74 20 61 |ith the |result a|
|000035a0| 66 74 65 72 20 6d 61 6b | 69 6e 67 20 61 20 63 6f |fter mak|ing a co|
|000035b0| 70 79 2c 20 77 65 20 61 | 6c 6c 6f 77 20 74 68 65 |py, we a|llow the|
|000035c0| 0a 20 20 20 69 6d 70 6c | 65 6d 65 6e 74 61 74 69 |. impl|ementati|
|000035d0| 6f 6e 20 74 6f 20 65 6c | 69 6d 69 6e 61 74 65 20 |on to el|iminate |
|000035e0| 72 65 64 75 6e 64 61 6e | 74 20 63 6f 70 79 69 6e |redundan|t copyin|
|000035f0| 67 2e 20 46 75 72 74 68 | 65 72 6d 6f 72 65 2c 20 |g. Furth|ermore, |
|00003600| 73 6f 6d 65 0a 20 20 20 | 75 73 65 72 2d 64 65 66 |some. |user-def|
|00003610| 69 6e 65 64 20 72 65 70 | 72 65 73 65 6e 74 61 74 |ined rep|resentat|
|00003620| 69 6f 6e 73 20 6d 69 67 | 68 74 20 62 65 20 70 6f |ions mig|ht be po|
|00003630| 73 69 74 69 6f 6e 20 64 | 65 70 65 6e 64 65 6e 74 |sition d|ependent|
|00003640| 2e 20 54 68 61 74 20 69 | 73 2c 20 74 68 65 0a 20 |. That i|s, the. |
|00003650| 20 20 66 69 6e 61 6c 20 | 22 66 69 64 64 6c 69 6e | final |"fiddlin|
|00003660| 67 22 20 68 61 73 20 74 | 6f 20 74 61 6b 65 20 70 |g" has t|o take p|
|00003670| 6c 61 63 65 20 6f 6e 20 | 74 68 65 20 6f 62 6a 65 |lace on |the obje|
|00003680| 63 74 20 69 6e 20 69 74 | 73 20 66 69 6e 61 6c 0a |ct in it|s final.|
|00003690| 20 20 20 6c 6f 63 61 74 | 69 6f 6e 2e 20 46 6f 72 | locat|ion. For|
|000036a0| 20 65 78 61 6d 70 6c 65 | 2c 20 6f 6e 65 20 6d 69 | example|, one mi|
|000036b0| 67 68 74 20 77 61 6e 74 | 20 74 68 65 20 6f 62 6a |ght want| the obj|
|000036c0| 65 63 74 20 74 6f 20 70 | 6f 69 6e 74 20 74 6f 20 |ect to p|oint to |
|000036d0| 69 74 73 65 6c 66 2e 0a | 20 20 20 49 66 20 74 68 |itself..| If th|
|000036e0| 65 20 69 6d 70 6c 65 6d | 65 6e 74 61 74 69 6f 6e |e implem|entation|
|000036f0| 20 63 6f 70 69 65 73 20 | 61 6e 20 6f 62 6a 65 63 | copies |an objec|
|00003700| 74 20 61 66 74 65 72 20 | 74 68 65 20 75 73 65 72 |t after |the user|
|00003710| 20 63 6f 64 65 20 68 61 | 73 0a 20 20 20 61 64 6a | code ha|s. adj|
|00003720| 75 73 74 65 64 20 69 74 | 2c 20 73 75 63 68 20 73 |usted it|, such s|
|00003730| 65 6c 66 2d 72 65 66 65 | 72 65 6e 63 65 73 20 77 |elf-refe|rences w|
|00003740| 69 6c 6c 20 6e 6f 20 6c | 6f 6e 67 65 72 20 70 6f |ill no l|onger po|
|00003750| 69 6e 74 20 74 6f 20 74 | 68 65 20 72 69 67 68 74 |int to t|he right|
|00003760| 0a 20 20 20 70 6c 61 63 | 65 2e 0a 0a 20 20 20 53 |. plac|e... S|
|00003770| 6f 2c 20 61 73 20 75 73 | 75 61 6c 2c 20 6f 6e 63 |o, as us|ual, onc|
|00003780| 65 20 6f 6e 65 20 67 65 | 74 73 20 69 6e 74 6f 20 |e one ge|ts into |
|00003790| 77 6f 72 6b 69 6e 67 20 | 6f 75 74 20 74 68 65 20 |working |out the |
|000037a0| 64 65 74 61 69 6c 73 20 | 61 6e 64 20 61 6c 6c 20 |details |and all |
|000037b0| 74 68 65 0a 20 20 20 69 | 6e 74 65 72 61 63 74 69 |the. i|nteracti|
|000037c0| 6f 6e 73 2c 20 74 68 65 | 20 22 6f 62 76 69 6f 75 |ons, the| "obviou|
|000037d0| 73 22 20 70 72 6f 70 6f | 73 61 6c 20 28 73 75 63 |s" propo|sal (suc|
|000037e0| 68 20 61 73 20 61 20 70 | 72 6f 63 65 64 75 72 65 |h as a p|rocedure|
|000037f0| 20 22 3a 3d 22 29 20 6e | 6f 0a 20 20 20 6c 6f 6e | ":=") n|o. lon|
|00003800| 67 65 72 20 6c 6f 6f 6b | 73 20 6c 69 6b 65 20 74 |ger look|s like t|
|00003810| 68 65 20 62 65 73 74 20 | 61 6e 73 77 65 72 2c 20 |he best |answer, |
|00003820| 61 6e 64 20 74 68 65 20 | 62 65 73 74 20 61 6e 73 |and the |best ans|
|00003830| 77 65 72 20 6f 6e 65 20 | 63 61 6e 20 66 69 6e 64 |wer one |can find|
|00003840| 0a 20 20 20 70 6f 74 65 | 6e 74 69 61 6c 6c 79 20 |. pote|ntially |
|00003850| 6c 6f 6f 6b 73 20 22 63 | 6c 75 6d 73 79 22 20 28 |looks "c|lumsy" (|
|00003860| 61 74 20 6c 65 61 73 74 | 20 62 65 66 6f 72 65 20 |at least| before |
|00003870| 79 6f 75 20 74 72 79 20 | 74 6f 20 77 6f 72 6b 20 |you try |to work |
|00003880| 6f 75 74 20 74 68 65 0a | 20 20 20 64 65 74 61 69 |out the.| detai|
|00003890| 6c 73 20 6f 66 20 74 68 | 65 20 61 6c 74 65 72 6e |ls of th|e altern|
|000038a0| 61 74 69 76 65 73 29 2e | 0a 0a 0a 35 2e 36 3a 20 |atives).|...5.6: |
|000038b0| 57 68 61 74 20 64 6f 20 | 22 63 6f 76 61 72 69 61 |What do |"covaria|
|000038c0| 6e 63 65 22 20 61 6e 64 | 20 22 63 6f 6e 74 72 61 |nce" and| "contra|
|000038d0| 76 61 72 69 61 6e 63 65 | 22 20 6d 65 61 6e 2c 20 |variance|" mean, |
|000038e0| 61 6e 64 20 64 6f 65 73 | 20 41 64 61 20 73 75 70 |and does| Ada sup|
|000038f0| 70 6f 72 74 0a 65 69 74 | 68 65 72 20 6f 72 20 62 |port.eit|her or b|
|00003900| 6f 74 68 3f 0a 0a 20 20 | 20 28 46 72 6f 6d 20 52 |oth?.. | (From R|
|00003910| 6f 62 65 72 74 20 4d 61 | 72 74 69 6e 29 20 5b 54 |obert Ma|rtin) [T|
|00003920| 68 69 73 20 69 73 20 43 | 2b 2b 20 73 74 75 66 66 |his is C|++ stuff|
|00003930| 2c 20 69 74 20 73 68 6f | 75 6c 64 20 62 65 20 63 |, it sho|uld be c|
|00003940| 6f 6d 70 6c 65 74 65 6c | 79 0a 20 20 20 72 65 2d |ompletel|y. re-|
|00003950| 77 72 69 74 74 65 6e 20 | 66 6f 72 20 41 64 61 2e |written |for Ada.|
|00003960| 20 2d 2d 4d 4b 5d 0a 0a | 0a 20 52 3e 20 63 6f 76 | --MK]..|. R> cov|
|00003970| 61 72 69 61 6e 63 65 3a | 20 20 22 63 68 61 6e 67 |ariance:| "chang|
|00003980| 65 73 20 77 69 74 68 22 | 0a 20 52 3e 20 63 6f 6e |es with"|. R> con|
|00003990| 74 72 61 76 61 72 69 61 | 6e 63 65 3a 20 22 63 68 |travaria|nce: "ch|
|000039a0| 61 6e 67 65 73 20 61 67 | 61 69 6e 73 74 22 0a 0a |anges ag|ainst"..|
|000039b0| 20 52 3e 20 63 6c 61 73 | 73 20 41 0a 20 52 3e 20 | R> clas|s A. R> |
|000039c0| 7b 0a 20 52 3e 20 20 20 | 20 70 75 62 6c 69 63 3a |{. R> | public:|
|000039d0| 0a 20 52 3e 20 20 20 20 | 20 20 41 2a 20 66 28 41 |. R> | A* f(A|
|000039e0| 2a 29 3b 20 20 20 2f 2f | 20 6d 65 74 68 6f 64 20 |*); //| method |
|000039f0| 6f 66 20 63 6c 61 73 73 | 20 41 2c 20 74 61 6b 65 |of class| A, take|
|00003a00| 73 20 41 20 61 72 67 75 | 6d 65 6e 74 20 61 6e 64 |s A argu|ment and|
|00003a10| 20 72 65 74 75 72 6e 73 | 20 41 0a 20 52 3e 20 20 | returns| A. R> |
|00003a20| 20 20 20 20 41 2a 20 67 | 28 41 2a 29 3b 20 20 20 | A* g|(A*); |
|00003a30| 2f 2f 20 73 61 6d 65 2e | 0a 20 52 3e 20 7d 3b 0a |// same.|. R> };.|
|00003a40| 0a 20 52 3e 20 63 6c 61 | 73 73 20 42 20 3a 20 70 |. R> cla|ss B : p|
|00003a50| 75 62 6c 69 63 20 41 20 | 2f 2f 20 63 6c 61 73 73 |ublic A |// class|
|00003a60| 20 42 20 69 73 20 61 20 | 73 75 62 63 6c 61 73 73 | B is a |subclass|
|00003a70| 20 6f 66 20 63 6c 61 73 | 73 20 41 0a 20 52 3e 20 | of clas|s A. R> |
|00003a80| 7b 0a 20 52 3e 20 20 20 | 70 75 62 6c 69 63 3a 0a |{. R> |public:.|
|00003a90| 20 52 3e 20 20 20 20 20 | 42 2a 20 66 28 42 2a 29 | R> |B* f(B*)|
|00003aa0| 3b 20 20 2f 2f 20 6d 65 | 74 68 6f 64 20 6f 66 20 |; // me|thod of |
|00003ab0| 63 6c 61 73 73 20 42 20 | 6f 76 65 72 72 69 64 65 |class B |override|
|00003ac0| 73 20 66 20 61 6e 64 20 | 69 73 20 63 6f 76 61 72 |s f and |is covar|
|00003ad0| 69 61 6e 74 2e 0a 20 52 | 3e 20 20 20 20 20 41 2a |iant.. R|> A*|
|00003ae0| 20 67 28 41 2a 29 3b 20 | 20 2f 2f 20 6d 65 74 68 | g(A*); | // meth|
|00003af0| 6f 64 20 6f 66 20 63 6c | 61 73 73 20 42 20 6f 76 |od of cl|ass B ov|
|00003b00| 65 72 72 69 64 65 73 20 | 67 20 61 6e 64 20 69 73 |errides |g and is|
|00003b10| 20 63 6f 6e 74 72 61 76 | 61 72 69 61 6e 74 2e 0a | contrav|ariant..|
|00003b20| 20 52 3e 20 7d 3b 0a 0a | 20 52 3e 20 54 68 65 20 | R> };..| R> The |
|00003b30| 66 75 6e 63 74 69 6f 6e | 20 66 20 69 73 20 63 6f |function| f is co|
|00003b40| 76 61 72 69 61 6e 74 20 | 62 65 63 61 75 73 65 20 |variant |because |
|00003b50| 74 68 65 20 74 79 70 65 | 20 6f 66 20 69 74 73 20 |the type| of its |
|00003b60| 72 65 74 75 72 6e 20 76 | 61 6c 75 65 20 61 6e 64 |return v|alue and|
|00003b70| 0a 20 52 3e 20 61 72 67 | 75 6d 65 6e 74 20 63 68 |. R> arg|ument ch|
|00003b80| 61 6e 67 65 73 20 77 69 | 74 68 20 74 68 65 20 63 |anges wi|th the c|
|00003b90| 6c 61 73 73 20 69 74 20 | 62 65 6c 6f 6e 67 73 20 |lass it |belongs |
|00003ba0| 74 6f 2e 20 20 54 68 65 | 20 66 75 6e 63 74 69 6f |to. The| functio|
|00003bb0| 6e 20 67 20 69 73 0a 20 | 52 3e 20 63 6f 6e 74 72 |n g is. |R> contr|
|00003bc0| 61 76 61 72 69 61 6e 74 | 20 62 65 63 61 75 73 65 |avariant| because|
|00003bd0| 20 74 68 65 20 74 79 70 | 65 73 20 6f 66 20 69 74 | the typ|es of it|
|00003be0| 73 20 72 65 74 75 72 6e | 20 76 61 6c 75 65 20 61 |s return| value a|
|00003bf0| 6e 64 20 61 72 67 75 6d | 65 6e 74 73 20 64 6f 65 |nd argum|ents doe|
|00003c00| 73 20 6e 6f 74 0a 20 52 | 3e 20 63 68 61 6e 67 65 |s not. R|> change|
|00003c10| 20 77 69 74 68 20 74 68 | 65 20 63 6c 61 73 73 20 | with th|e class |
|00003c20| 69 74 20 62 65 6c 6f 6e | 67 73 20 74 6f 2e 0a 0a |it belon|gs to...|
|00003c30| 0a 20 20 20 41 63 74 75 | 61 6c 6c 79 2c 20 49 20 |. Actu|ally, I |
|00003c40| 77 6f 75 6c 64 20 63 61 | 6c 6c 20 67 28 29 20 69 |would ca|ll g() i|
|00003c50| 6e 76 61 72 69 61 6e 74 | 2e 20 49 66 20 79 6f 75 |nvariant|. If you|
|00003c60| 20 6c 6f 6f 6b 20 69 6e | 20 53 61 74 68 65 72 2c | look in| Sather,|
|00003c70| 20 28 6f 6e 65 20 6f 66 | 0a 20 20 20 74 68 65 20 | (one of|. the |
|00003c80| 70 72 69 6e 63 69 70 6c | 65 20 6c 61 6e 67 75 61 |principl|e langua|
|00003c90| 67 65 73 20 77 69 74 68 | 20 63 6f 6e 74 72 61 76 |ges with| contrav|
|00003ca0| 61 72 69 61 6e 63 65 29 | 2c 20 79 6f 75 20 77 69 |ariance)|, you wi|
|00003cb0| 6c 6c 20 73 65 65 20 74 | 68 61 74 20 74 68 65 0a |ll see t|hat the.|
|00003cc0| 20 20 20 6d 65 74 68 6f | 64 20 69 6e 20 74 68 65 | metho|d in the|
|00003cd0| 20 64 65 73 63 65 6e 64 | 61 6e 74 20 63 6c 61 73 | descend|ant clas|
|00003ce0| 73 20 61 63 74 75 61 6c | 6c 79 20 63 61 6e 20 68 |s actual|ly can h|
|00003cf0| 61 76 65 20 61 72 67 75 | 6d 65 6e 74 73 20 74 68 |ave argu|ments th|
|00003d00| 61 74 20 61 72 65 0a 20 | 20 20 73 75 70 65 72 63 |at are. | superc|
|00003d10| 6c 61 73 73 65 73 20 6f | 66 20 74 68 65 20 61 72 |lasses o|f the ar|
|00003d20| 67 75 6d 65 6e 74 73 20 | 6f 66 20 69 74 73 20 70 |guments |of its p|
|00003d30| 61 72 65 6e 74 2e 20 53 | 6f 20 66 6f 72 20 65 78 |arent. S|o for ex|
|00003d40| 61 6d 70 6c 65 3a 0a 0a | 63 6c 61 73 73 20 41 20 |ample:..|class A |
|00003d50| 3a 20 70 75 62 6c 69 63 | 20 52 4f 4f 54 0a 7b 0a |: public| ROOT.{.|
|00003d60| 20 20 20 70 75 62 6c 69 | 63 3a 0a 20 20 20 20 20 | publi|c:. |
|00003d70| 41 2a 20 66 28 41 2a 29 | 3b 20 20 20 2f 2f 20 6d |A* f(A*)|; // m|
|00003d80| 65 74 68 6f 64 20 6f 66 | 20 63 6c 61 73 73 20 41 |ethod of| class A|
|00003d90| 2c 20 74 61 6b 65 73 20 | 41 20 61 72 67 75 6d 65 |, takes |A argume|
|00003da0| 6e 74 20 61 6e 64 20 72 | 65 74 75 72 6e 73 20 41 |nt and r|eturns A|
|00003db0| 0a 20 20 20 20 20 41 2a | 20 67 28 41 2a 29 3b 20 |. A*| g(A*); |
|00003dc0| 20 20 2f 2f 20 73 61 6d | 65 2e 0a 7d 3b 0a 0a 63 | // sam|e..};..c|
|00003dd0| 6c 61 73 73 20 42 20 3a | 20 70 75 62 6c 69 63 20 |lass B :| public |
|00003de0| 41 20 2f 2f 20 63 6c 61 | 73 73 20 42 20 69 73 20 |A // cla|ss B is |
|00003df0| 61 20 73 75 62 63 6c 61 | 73 73 20 6f 66 20 63 6c |a subcla|ss of cl|
|00003e00| 61 73 73 20 41 0a 7b 0a | 20 20 70 75 62 6c 69 63 |ass A.{.| public|
|00003e10| 3a 0a 20 20 20 20 42 2a | 20 66 28 42 2a 29 3b 20 |:. B*| f(B*); |
|00003e20| 20 2f 2f 20 6d 65 74 68 | 6f 64 20 6f 66 20 63 6c | // meth|od of cl|
|00003e30| 61 73 73 20 42 20 6f 76 | 65 72 72 69 64 65 73 20 |ass B ov|errides |
|00003e40| 66 20 61 6e 64 20 69 73 | 20 63 6f 76 61 72 69 61 |f and is| covaria|
|00003e50| 6e 74 2e 0a 20 20 20 20 | 52 4f 4f 54 2a 20 67 28 |nt.. |ROOT* g(|
|00003e60| 52 4f 4f 54 2a 29 3b 20 | 20 2f 2f 20 6d 65 74 68 |ROOT*); | // meth|
|00003e70| 6f 64 20 6f 66 20 63 6c | 61 73 73 20 42 20 6f 76 |od of cl|ass B ov|
|00003e80| 65 72 72 69 64 65 73 20 | 67 20 61 6e 64 20 69 73 |errides |g and is|
|00003e90| 20 63 6f 6e 74 72 61 76 | 61 72 69 61 6e 74 2e 0a | contrav|ariant..|
|00003ea0| 7d 3b 0a 0a 0a 20 20 20 | 54 6f 20 6d 79 20 6b 6e |};... |To my kn|
|00003eb0| 6f 77 6c 65 64 67 65 20 | 74 68 65 20 75 73 65 73 |owledge |the uses|
|00003ec0| 20 66 6f 72 20 63 6f 6e | 74 72 61 76 61 72 69 61 | for con|travaria|
|00003ed0| 6e 63 65 20 61 72 65 20 | 72 61 72 65 20 6f 72 20 |nce are |rare or |
|00003ee0| 6e 6f 6e 65 78 69 73 74 | 65 6e 74 2e 0a 20 20 20 |nonexist|ent.. |
|00003ef0| 28 41 6e 79 6f 6e 65 3f | 29 2e 20 49 74 20 6a 75 |(Anyone?|). It ju|
|00003f00| 73 74 20 6d 61 6b 65 73 | 20 74 68 65 20 72 75 6c |st makes| the rul|
|00003f10| 65 73 20 65 61 73 79 20 | 66 6f 72 20 74 68 65 20 |es easy |for the |
|00003f20| 63 6f 6d 70 69 6c 65 72 | 20 74 6f 20 74 79 70 65 |compiler| to type|
|00003f30| 0a 20 20 20 63 68 65 63 | 6b 2e 20 4f 6e 20 74 68 |. chec|k. On th|
|00003f40| 65 20 6f 74 68 65 72 20 | 68 61 6e 64 2c 20 63 6f |e other |hand, co|
|00003f50| 2d 76 61 72 69 61 6e 63 | 65 20 69 73 20 65 78 74 |-varianc|e is ext|
|00003f60| 72 65 6d 65 6c 79 20 75 | 73 65 66 75 6c 2e 20 53 |remely u|seful. S|
|00003f70| 75 70 70 6f 73 65 20 79 | 6f 75 0a 20 20 20 77 61 |uppose y|ou. wa|
|00003f80| 6e 74 20 74 6f 20 74 65 | 73 74 20 66 6f 72 20 65 |nt to te|st for e|
|00003f90| 71 75 61 6c 69 74 79 2c | 20 6f 72 20 63 72 65 61 |quality,| or crea|
|00003fa0| 74 65 20 61 20 6e 65 77 | 20 6f 62 6a 65 63 74 20 |te a new| object |
|00003fb0| 6f 66 20 74 68 65 20 73 | 61 6d 65 20 74 79 70 65 |of the s|ame type|
|00003fc0| 20 61 73 0a 20 20 20 74 | 68 65 20 6f 6e 65 20 69 | as. t|he one i|
|00003fd0| 6e 20 68 61 6e 64 3a 0a | 0a 63 6c 61 73 73 20 41 |n hand:.|.class A|
|00003fe0| 0a 7b 0a 20 20 20 70 75 | 62 6c 69 63 3a 0a 20 20 |.{. pu|blic:. |
|00003ff0| 20 20 20 20 42 4f 4f 4c | 45 41 4e 20 65 71 75 61 | BOOL|EAN equa|
|00004000| 6c 28 41 2a 29 3b 0a 20 | 20 20 20 20 20 41 2a 20 |l(A*);. | A* |
|00004010| 63 72 65 61 74 65 28 29 | 3b 0a 7d 0a 0a 63 6c 61 |create()|;.}..cla|
|00004020| 73 73 20 42 3a 20 70 75 | 62 6c 69 63 20 41 0a 7b |ss B: pu|blic A.{|
|00004030| 0a 20 20 20 70 75 62 6c | 69 63 3a 0a 20 20 20 20 |. publ|ic:. |
|00004040| 20 20 42 4f 4f 4c 45 41 | 4e 20 65 71 75 61 6c 28 | BOOLEA|N equal(|
|00004050| 42 2a 29 3b 0a 20 20 20 | 20 20 20 42 2a 20 63 72 |B*);. | B* cr|
|00004060| 65 61 74 65 28 29 3b 0a | 7d 0a 0a 0a 20 20 20 48 |eate();.|}... H|
|00004070| 65 72 65 20 63 6f 76 61 | 72 69 61 6e 63 65 20 69 |ere cova|riance i|
|00004080| 73 20 65 78 61 63 74 6c | 79 20 77 68 61 74 20 79 |s exactl|y what y|
|00004090| 6f 75 20 77 61 6e 74 2e | 20 45 69 66 66 65 6c 20 |ou want.| Eiffel |
|000040a0| 67 69 76 65 73 20 74 68 | 69 73 20 74 6f 20 79 6f |gives th|is to yo|
|000040b0| 75 2c 0a 20 20 20 62 75 | 74 20 74 68 65 20 63 6f |u,. bu|t the co|
|000040c0| 73 74 20 69 73 20 67 69 | 76 69 6e 67 20 75 70 20 |st is gi|ving up |
|000040d0| 31 30 30 25 20 63 6f 6d | 70 69 6c 65 20 74 69 6d |100% com|pile tim|
|000040e0| 65 20 74 79 70 65 20 73 | 61 66 65 74 79 2e 20 54 |e type s|afety. T|
|000040f0| 68 69 73 20 73 65 65 6d | 0a 20 20 20 6e 65 63 65 |his seem|. nece|
|00004100| 73 73 61 72 79 20 69 6e | 20 63 61 73 65 73 20 6c |ssary in| cases l|
|00004110| 69 6b 65 20 74 68 65 73 | 65 2e 0a 0a 20 20 20 49 |ike thes|e... I|
|00004120| 6e 20 66 61 63 74 2c 20 | 45 69 66 66 65 6c 20 67 |n fact, |Eiffel g|
|00004130| 69 76 65 73 20 79 6f 75 | 20 61 75 74 6f 6d 61 74 |ives you| automat|
|00004140| 69 63 20 77 61 79 73 20 | 74 6f 20 6d 61 6b 65 20 |ic ways |to make |
|00004150| 61 20 6d 65 74 68 6f 64 | 20 63 6f 76 61 72 69 61 |a method| covaria|
|00004160| 6e 74 2c 0a 20 20 20 63 | 61 6c 6c 65 64 20 22 61 |nt,. c|alled "a|
|00004170| 6e 63 68 6f 72 65 64 20 | 74 79 70 65 73 22 2e 20 |nchored |types". |
|00004180| 53 6f 20 79 6f 75 20 63 | 6f 75 6c 64 20 64 65 63 |So you c|ould dec|
|00004190| 6c 61 72 65 2c 20 28 69 | 6e 20 43 2b 2b 2f 65 69 |lare, (i|n C++/ei|
|000041a0| 66 66 65 73 65 29 3a 0a | 0a 63 6c 61 73 73 20 41 |ffese):.|.class A|
|000041b0| 0a 7b 0a 20 20 20 70 75 | 62 6c 69 63 3a 0a 20 20 |.{. pu|blic:. |
|000041c0| 20 20 20 20 42 4f 4f 4c | 45 41 4e 20 65 71 75 61 | BOOL|EAN equa|
|000041d0| 6c 28 6c 69 6b 65 20 43 | 75 72 72 65 6e 74 20 2a |l(like C|urrent *|
|000041e0| 29 3b 0a 20 20 20 20 20 | 20 6c 69 6b 65 20 43 75 |);. | like Cu|
|000041f0| 72 72 65 6e 74 20 2a 20 | 63 72 65 61 74 65 28 29 |rrent * |create()|
|00004200| 3b 0a 7d 0a 0a 0a 20 20 | 20 57 68 69 63 68 20 73 |;.}... | Which s|
|00004210| 61 79 73 20 65 71 75 61 | 6c 20 74 61 6b 65 73 20 |ays equa|l takes |
|00004220| 61 6e 20 61 72 67 75 6d | 65 6e 74 20 74 68 65 20 |an argum|ent the |
|00004230| 73 61 6d 65 20 74 79 70 | 65 20 61 73 20 74 68 65 |same typ|e as the|
|00004240| 20 63 75 72 72 65 6e 74 | 0a 20 20 20 6f 62 6a 65 | current|. obje|
|00004250| 63 74 2c 20 61 6e 64 20 | 63 72 65 61 74 65 20 72 |ct, and |create r|
|00004260| 65 74 75 72 6e 73 20 61 | 6e 20 6f 62 6a 65 63 74 |eturns a|n object|
|00004270| 20 6f 66 20 74 68 65 20 | 73 61 6d 65 20 74 79 70 | of the |same typ|
|00004280| 65 20 61 73 20 63 75 72 | 72 65 6e 74 2e 20 4e 6f |e as cur|rent. No|
|00004290| 77 2c 0a 20 20 20 74 68 | 65 72 65 20 69 73 20 6e |w,. th|ere is n|
|000042a0| 6f 74 20 65 76 65 6e 20 | 61 6e 79 20 6e 65 65 64 |ot even |any need|
|000042b0| 20 74 6f 20 72 65 64 65 | 63 6c 61 72 65 20 74 68 | to rede|clare th|
|000042c0| 65 73 65 20 69 6e 20 63 | 6c 61 73 73 20 42 2e 20 |ese in c|lass B. |
|000042d0| 54 68 6f 73 65 0a 20 20 | 20 74 72 61 6e 73 66 6f |Those. | transfo|
|000042e0| 72 6d 61 74 69 6f 6e 73 | 20 68 61 70 70 65 6e 20 |rmations| happen |
|000042f0| 66 6f 72 20 66 72 65 65 | 21 0a 0a 0a 35 2e 37 3a |for free|!...5.7:|
|00004300| 20 57 68 61 74 20 69 73 | 20 6d 65 61 6e 74 20 62 | What is| meant b|
|00004310| 79 20 75 70 63 61 73 74 | 69 6e 67 2f 65 78 70 61 |y upcast|ing/expa|
|00004320| 6e 64 69 6e 67 20 61 6e | 64 20 64 6f 77 6e 63 61 |nding an|d downca|
|00004330| 73 74 69 6e 67 2f 6e 61 | 72 72 6f 77 69 6e 67 3f |sting/na|rrowing?|
|00004340| 0a 0a 20 20 20 28 54 75 | 63 6b 65 72 20 54 61 66 |.. (Tu|cker Taf|
|00004350| 74 20 72 65 70 6c 69 65 | 73 29 3a 0a 0a 20 20 20 |t replie|s):.. |
|00004360| 48 65 72 65 20 69 73 20 | 74 68 65 20 73 79 6d 6d |Here is |the symm|
|00004370| 65 74 72 69 63 20 63 61 | 73 65 20 74 6f 20 69 6c |etric ca|se to il|
|00004380| 6c 75 73 74 72 61 74 65 | 20 75 70 63 61 73 74 69 |lustrate| upcasti|
|00004390| 6e 67 20 61 6e 64 20 64 | 6f 77 6e 63 61 73 74 69 |ng and d|owncasti|
|000043a0| 6e 67 2e 0a 0a 20 20 20 | 20 20 74 79 70 65 20 41 |ng... | type A|
|000043b0| 20 69 73 20 74 61 67 67 | 65 64 20 2e 2e 2e 3b 20 | is tagg|ed ...; |
|000043c0| 20 20 2d 2d 20 6f 6e 65 | 20 70 61 72 65 6e 74 20 | -- one| parent |
|000043d0| 74 79 70 65 0a 0a 20 20 | 20 20 20 74 79 70 65 20 |type.. | type |
|000043e0| 42 20 69 73 20 74 61 67 | 67 65 64 20 2e 2e 2e 3b |B is tag|ged ...;|
|000043f0| 20 20 20 2d 2d 20 61 6e | 6f 74 68 65 72 20 70 61 | -- an|other pa|
|00004400| 72 65 6e 74 20 74 79 70 | 65 0a 0a 20 20 20 20 20 |rent typ|e.. |
|00004410| 2e 2e 2e 0a 0a 20 20 20 | 20 20 74 79 70 65 20 43 |..... | type C|
|00004420| 3b 20 20 20 2d 2d 20 74 | 68 65 20 6e 65 77 20 74 |; -- t|he new t|
|00004430| 79 70 65 2c 20 74 6f 20 | 62 65 20 61 20 6d 69 78 |ype, to |be a mix|
|00004440| 74 75 72 65 20 6f 66 20 | 41 20 61 6e 64 20 42 0a |ture of |A and B.|
|00004450| 0a 20 20 20 20 20 74 79 | 70 65 20 41 43 20 28 4f |. ty|pe AC (O|
|00004460| 62 6a 20 3a 20 61 63 63 | 65 73 73 20 43 27 43 6c |bj : acc|ess C'Cl|
|00004470| 61 73 73 29 20 69 73 0a | 20 20 20 20 20 20 20 6e |ass) is.| n|
|00004480| 65 77 20 41 0a 20 20 20 | 20 20 20 20 77 69 74 68 |ew A. | with|
|00004490| 20 2e 2e 2e 3b 0a 20 20 | 20 20 20 20 20 2d 2d 20 | ...;. | -- |
|000044a0| 61 6e 20 65 78 74 65 6e | 73 69 6f 6e 20 6f 66 20 |an exten|sion of |
|000044b0| 41 20 74 6f 20 62 65 20 | 6d 69 78 65 64 20 69 6e |A to be |mixed in|
|000044c0| 74 6f 20 43 0a 0a 20 20 | 20 20 20 74 79 70 65 20 |to C.. | type |
|000044d0| 42 43 20 28 4f 62 6a 20 | 3a 20 61 63 63 65 73 73 |BC (Obj |: access|
|000044e0| 20 43 27 43 6c 61 73 73 | 29 20 69 73 0a 20 20 20 | C'Class|) is. |
|000044f0| 20 20 20 20 6e 65 77 20 | 42 0a 20 20 20 20 20 20 | new |B. |
|00004500| 20 77 69 74 68 20 2e 2e | 2e 3b 0a 20 20 20 20 20 | with ..|.;. |
|00004510| 20 20 2d 2d 20 61 6e 20 | 65 78 74 65 6e 73 69 6f | -- an |extensio|
|00004520| 6e 20 6f 66 20 42 20 74 | 6f 20 62 65 20 6d 69 78 |n of B t|o be mix|
|00004530| 65 64 20 69 6e 74 6f 20 | 43 0a 0a 20 20 20 20 20 |ed into |C.. |
|00004540| 74 79 70 65 20 43 20 69 | 73 0a 20 20 20 20 20 20 |type C i|s. |
|00004550| 20 74 61 67 67 65 64 20 | 6c 69 6d 69 74 65 64 20 | tagged |limited |
|00004560| 72 65 63 6f 72 64 0a 20 | 20 20 20 20 20 20 20 20 |record. | |
|00004570| 41 20 3a 20 41 43 20 28 | 43 27 41 63 63 65 73 73 |A : AC (|C'Access|
|00004580| 29 3b 0a 20 20 20 20 20 | 20 20 20 20 42 20 3a 20 |);. | B : |
|00004590| 42 43 20 28 43 27 41 63 | 63 65 73 73 29 3b 0a 20 |BC (C'Ac|cess);. |
|000045a0| 20 20 20 20 20 20 20 20 | 2e 2e 2e 20 2d 2d 20 6f | |... -- o|
|000045b0| 74 68 65 72 20 73 74 75 | 66 66 20 69 66 20 64 65 |ther stu|ff if de|
|000045c0| 73 69 72 65 64 0a 20 20 | 20 20 20 20 20 65 6e 64 |sired. | end|
|000045d0| 20 72 65 63 6f 72 64 3b | 0a 0a 0a 20 20 20 57 65 | record;|... We|
|000045e0| 20 63 61 6e 20 6e 6f 77 | 20 70 61 73 73 20 61 6e | can now| pass an|
|000045f0| 20 6f 62 6a 65 63 74 20 | 6f 66 20 74 79 70 65 20 | object |of type |
|00004600| 43 20 74 6f 20 61 6e 79 | 74 68 69 6e 67 20 74 68 |C to any|thing th|
|00004610| 61 74 20 74 61 6b 65 73 | 20 61 6e 20 41 20 6f 72 |at takes| an A or|
|00004620| 20 42 0a 20 20 20 61 73 | 20 66 6f 6c 6c 6f 77 73 | B. as| follows|
|00004630| 20 28 74 68 69 73 20 70 | 72 65 73 75 6d 65 73 20 | (this p|resumes |
|00004640| 74 68 61 74 20 46 6f 6f | 62 61 72 20 61 6e 64 20 |that Foo|bar and |
|00004650| 51 42 65 72 74 20 61 72 | 65 20 70 72 69 6d 69 74 |QBert ar|e primit|
|00004660| 69 76 65 73 20 6f 66 20 | 41 0a 20 20 20 61 6e 64 |ives of |A. and|
|00004670| 20 42 2c 20 72 65 73 70 | 65 63 74 69 76 65 6c 79 | B, resp|ectively|
|00004680| 2c 20 73 6f 20 74 68 65 | 79 20 61 72 65 20 69 6e |, so the|y are in|
|00004690| 68 65 72 69 74 65 64 3b | 20 69 66 20 6e 6f 74 2c |herited;| if not,|
|000046a0| 20 74 68 65 6e 20 61 6e | 20 65 78 70 6c 69 63 69 | then an| explici|
|000046b0| 74 0a 20 20 20 63 6f 6e | 76 65 72 73 69 6f 6e 20 |t. con|version |
|000046c0| 28 75 70 63 61 73 74 29 | 20 74 6f 20 41 20 61 6e |(upcast)| to A an|
|000046d0| 64 20 42 20 63 6f 75 6c | 64 20 62 65 20 75 73 65 |d B coul|d be use|
|000046e0| 64 20 74 6f 20 63 61 6c | 6c 20 74 68 65 20 6f 72 |d to cal|l the or|
|000046f0| 69 67 69 6e 61 6c 0a 20 | 20 20 46 6f 6f 62 61 72 |iginal. | Foobar|
|00004700| 20 61 6e 64 20 51 42 65 | 72 74 29 2e 0a 0a 20 20 | and QBe|rt)... |
|00004710| 20 20 20 58 43 20 3a 20 | 43 3b 0a 20 20 20 2e 2e | XC : |C;. ..|
|00004720| 2e 0a 20 20 20 20 20 46 | 6f 6f 62 61 72 20 28 58 |.. F|oobar (X|
|00004730| 43 2e 41 29 3b 0a 20 20 | 20 20 20 51 42 65 72 74 |C.A);. | QBert|
|00004740| 20 28 58 43 2e 42 29 3b | 0a 0a 0a 20 20 20 49 66 | (XC.B);|... If|
|00004750| 20 77 65 20 77 61 6e 74 | 20 74 6f 20 6f 76 65 72 | we want| to over|
|00004760| 72 69 64 65 20 77 68 61 | 74 20 46 6f 6f 62 61 72 |ride wha|t Foobar|
|00004770| 20 64 6f 65 73 2c 20 74 | 68 65 6e 20 77 65 20 6f | does, t|hen we o|
|00004780| 76 65 72 72 69 64 65 20 | 46 6f 6f 62 61 72 20 6f |verride |Foobar o|
|00004790| 6e 0a 20 20 20 41 43 2e | 20 49 66 20 77 65 20 77 |n. AC.| If we w|
|000047a0| 61 6e 74 20 74 6f 20 6f | 76 65 72 72 69 64 65 20 |ant to o|verride |
|000047b0| 77 68 61 74 20 51 42 65 | 72 74 20 64 6f 65 73 2c |what QBe|rt does,|
|000047c0| 20 74 68 65 6e 20 77 65 | 20 6f 76 65 72 72 69 64 | then we| overrid|
|000047d0| 65 20 51 42 65 72 74 20 | 6f 6e 0a 20 20 20 42 43 |e QBert |on. BC|
|000047e0| 2e 0a 0a 20 20 20 4e 6f | 74 65 20 74 68 61 74 20 |... No|te that |
|000047f0| 74 68 65 72 65 20 61 72 | 65 20 6e 6f 20 6e 61 6d |there ar|e no nam|
|00004800| 69 6e 67 20 63 6f 6e 66 | 6c 69 63 74 73 2c 20 73 |ing conf|licts, s|
|00004810| 69 6e 63 65 20 41 43 20 | 61 6e 64 20 42 43 20 61 |ince AC |and BC a|
|00004820| 72 65 20 64 69 73 74 69 | 6e 63 74 0a 20 20 20 74 |re disti|nct. t|
|00004830| 79 70 65 73 2c 20 73 6f | 20 65 76 65 6e 20 69 66 |ypes, so| even if|
|00004840| 20 41 20 61 6e 64 20 42 | 20 68 61 76 65 20 73 61 | A and B| have sa|
|00004850| 6d 65 2d 6e 61 6d 65 64 | 20 63 6f 6d 70 6f 6e 65 |me-named| compone|
|00004860| 6e 74 73 20 6f 72 20 6f | 70 65 72 61 74 69 6f 6e |nts or o|peration|
|00004870| 73 2c 20 77 65 0a 20 20 | 20 63 61 6e 20 74 61 6c |s, we. | can tal|
|00004880| 6b 20 61 62 6f 75 74 20 | 74 68 65 6d 20 61 6e 64 |k about |them and|
|00004890| 2f 6f 72 20 6f 76 65 72 | 72 69 64 65 20 74 68 65 |/or over|ride the|
|000048a0| 6d 20 69 6e 64 69 76 69 | 64 75 61 6c 6c 79 20 75 |m indivi|dually u|
|000048b0| 73 69 6e 67 20 41 43 20 | 61 6e 64 20 42 43 2e 0a |sing AC |and BC..|
|000048c0| 0a 0a 20 20 20 55 70 63 | 61 73 74 69 6e 67 20 28 |.. Upc|asting (|
|000048d0| 66 72 6f 6d 20 43 20 74 | 6f 20 41 20 6f 72 20 43 |from C t|o A or C|
|000048e0| 20 74 6f 20 42 29 20 69 | 73 20 74 72 69 76 69 61 | to B) i|s trivia|
|000048f0| 6c 20 2d 2d 20 41 28 58 | 43 2e 41 29 20 75 70 63 |l -- A(X|C.A) upc|
|00004900| 61 73 74 73 20 74 6f 20 | 41 3b 0a 20 20 20 42 28 |asts to |A;. B(|
|00004910| 58 43 2e 42 29 20 75 70 | 63 61 73 74 73 20 74 6f |XC.B) up|casts to|
|00004920| 20 42 2e 0a 0a 20 20 20 | 44 6f 77 6e 63 61 73 74 | B... |Downcast|
|00004930| 69 6e 67 20 28 6e 61 72 | 72 6f 77 69 6e 67 29 20 |ing (nar|rowing) |
|00004940| 69 73 20 61 6c 73 6f 20 | 73 74 72 61 69 67 68 74 |is also |straight|
|00004950| 66 6f 72 77 61 72 64 20 | 61 6e 64 20 73 61 66 65 |forward |and safe|
|00004960| 2e 20 50 72 65 73 75 6d | 69 6e 67 20 58 41 0a 20 |. Presum|ing XA. |
|00004970| 20 20 6f 66 20 74 79 70 | 65 20 41 27 43 6c 61 73 | of typ|e A'Clas|
|00004980| 73 2c 20 61 6e 64 20 58 | 42 20 6f 66 20 74 79 70 |s, and X|B of typ|
|00004990| 65 20 42 27 43 6c 61 73 | 73 3a 0a 0a 20 20 20 20 |e B'Clas|s:.. |
|000049a0| 20 41 43 28 58 41 29 2e | 4f 62 6a 2e 61 6c 6c 20 | AC(XA).|Obj.all |
|000049b0| 64 6f 77 6e 63 61 73 74 | 73 20 74 6f 20 43 27 43 |downcast|s to C'C|
|000049c0| 6c 61 73 73 20 28 61 6e | 64 20 76 65 72 69 66 69 |lass (an|d verifi|
|000049d0| 65 73 20 58 41 20 69 6e | 20 41 43 27 43 6c 61 73 |es XA in| AC'Clas|
|000049e0| 73 29 0a 20 20 20 20 20 | 42 43 28 58 42 29 2e 4f |s). |BC(XB).O|
|000049f0| 62 6a 2e 61 6c 6c 20 64 | 6f 77 6e 63 61 73 74 73 |bj.all d|owncasts|
|00004a00| 20 74 6f 20 43 27 43 6c | 61 73 73 20 28 61 6e 64 | to C'Cl|ass (and|
|00004a10| 20 76 65 72 69 66 69 65 | 73 20 58 42 20 69 6e 20 | verifie|s XB in |
|00004a20| 42 43 27 43 6c 61 73 73 | 29 0a 0a 0a 20 20 20 59 |BC'Class|)... Y|
|00004a30| 6f 75 20 63 61 6e 20 63 | 68 65 63 6b 20 62 65 66 |ou can c|heck bef|
|00004a40| 6f 72 65 20 74 68 65 20 | 64 6f 77 6e 63 61 73 74 |ore the |downcast|
|00004a50| 20 74 6f 20 61 76 6f 69 | 64 20 61 20 43 6f 6e 73 | to avoi|d a Cons|
|00004a60| 74 72 61 69 6e 74 5f 45 | 72 72 6f 72 3a 0a 0a 20 |traint_E|rror:.. |
|00004a70| 20 20 20 20 69 66 20 58 | 41 20 6e 6f 74 20 69 6e | if X|A not in|
|00004a80| 20 41 43 27 43 6c 61 73 | 73 20 74 68 65 6e 20 2d | AC'Clas|s then -|
|00004a90| 2d 20 61 70 70 72 6f 70 | 72 69 61 74 65 20 63 6f |- approp|riate co|
|00004aa0| 6d 70 6c 61 69 6e 74 0a | 0a 20 20 20 20 20 69 66 |mplaint.|. if|
|00004ab0| 20 58 42 20 6e 6f 74 20 | 69 6e 20 42 43 27 43 6c | XB not |in BC'Cl|
|00004ac0| 61 73 73 20 74 68 65 6e | 20 2d 2d 20 64 69 74 74 |ass then| -- ditt|
|00004ad0| 6f 0a 0a 0a 20 20 20 54 | 68 65 20 61 70 70 72 6f |o... T|he appro|
|00004ae0| 61 63 68 20 69 73 20 73 | 6c 69 67 68 74 6c 79 20 |ach is s|lightly |
|00004af0| 73 69 6d 70 6c 65 72 20 | 28 74 68 6f 75 67 68 20 |simpler |(though |
|00004b00| 6c 65 73 73 20 73 79 6d | 6d 65 74 72 69 63 29 20 |less sym|metric) |
|00004b10| 69 66 20 77 65 20 63 68 | 6f 6f 73 65 0a 20 20 20 |if we ch|oose. |
|00004b20| 74 6f 20 6d 61 6b 65 20 | 41 20 74 68 65 20 22 70 |to make |A the "p|
|00004b30| 72 69 6d 61 72 79 22 20 | 70 61 72 65 6e 74 20 61 |rimary" |parent a|
|00004b40| 6e 64 20 42 20 61 20 22 | 73 65 63 6f 6e 64 61 72 |nd B a "|secondar|
|00004b50| 79 22 20 70 61 72 65 6e | 74 3a 0a 0a 20 20 20 20 |y" paren|t:.. |
|00004b60| 20 74 79 70 65 20 41 20 | 69 73 20 2e 2e 2e 0a 20 | type A |is .... |
|00004b70| 20 20 20 20 74 79 70 65 | 20 42 20 69 73 20 2e 2e | type| B is ..|
|00004b80| 2e 0a 0a 20 20 20 20 20 | 74 79 70 65 20 43 3b 0a |... |type C;.|
|00004b90| 0a 20 20 20 20 20 74 79 | 70 65 20 42 43 20 28 4f |. ty|pe BC (O|
|00004ba0| 62 6a 20 3a 20 61 63 63 | 65 73 73 20 43 27 43 6c |bj : acc|ess C'Cl|
|00004bb0| 61 73 73 29 20 69 73 0a | 20 20 20 20 20 20 20 6e |ass) is.| n|
|00004bc0| 65 77 20 42 0a 20 20 20 | 20 20 20 20 77 69 74 68 |ew B. | with|
|00004bd0| 20 2e 2e 2e 0a 0a 20 20 | 20 20 20 74 79 70 65 20 | ..... | type |
|00004be0| 43 20 69 73 0a 20 20 20 | 20 20 20 20 6e 65 77 20 |C is. | new |
|00004bf0| 41 0a 20 20 20 20 20 20 | 20 77 69 74 68 20 72 65 |A. | with re|
|00004c00| 63 6f 72 64 0a 20 20 20 | 20 20 20 20 20 20 42 20 |cord. | B |
|00004c10| 3a 20 42 43 20 28 43 27 | 41 63 63 65 73 73 29 3b |: BC (C'|Access);|
|00004c20| 0a 20 20 20 20 20 20 20 | 20 20 2e 2e 2e 20 2d 2d |. | ... --|
|00004c30| 20 6f 74 68 65 72 20 73 | 74 75 66 66 20 69 66 20 | other s|tuff if |
|00004c40| 64 65 73 69 72 65 64 0a | 20 20 20 20 20 20 20 65 |desired.| e|
|00004c50| 6e 64 20 72 65 63 6f 72 | 64 3b 0a 0a 0a 20 20 20 |nd recor|d;... |
|00004c60| 4e 6f 77 20 43 20 69 73 | 20 61 20 22 6e 6f 72 6d |Now C is| a "norm|
|00004c70| 61 6c 22 20 65 78 74 65 | 6e 73 69 6f 6e 20 6f 66 |al" exte|nsion of|
|00004c80| 20 41 2c 20 61 6e 64 20 | 75 70 63 61 73 74 69 6e | A, and |upcastin|
|00004c90| 67 20 66 72 6f 6d 20 43 | 20 74 6f 20 41 20 61 6e |g from C| to A an|
|00004ca0| 64 0a 20 20 20 28 63 68 | 65 63 6b 65 64 29 20 64 |d. (ch|ecked) d|
|00004cb0| 6f 77 6e 63 61 73 74 69 | 6e 67 20 66 72 6f 6d 20 |owncasti|ng from |
|00004cc0| 43 27 43 6c 61 73 73 20 | 74 6f 20 41 20 28 6f 72 |C'Class |to A (or|
|00004cd0| 20 41 27 43 6c 61 73 73 | 29 20 69 73 20 64 6f 6e | A'Class|) is don|
|00004ce0| 65 20 77 69 74 68 0a 20 | 20 20 73 69 6d 70 6c 65 |e with. | simple|
|00004cf0| 20 74 79 70 65 20 63 6f | 6e 76 65 72 73 69 6f 6e | type co|nversion|
|00004d00| 73 2e 20 54 68 65 20 72 | 65 6c 61 74 69 6f 6e 73 |s. The r|elations|
|00004d10| 68 69 70 20 62 65 74 77 | 65 65 6e 20 43 20 61 6e |hip betw|een C an|
|00004d20| 64 20 42 20 69 73 20 61 | 73 20 61 62 6f 76 65 0a |d B is a|s above.|
|00004d30| 20 20 20 69 6e 20 74 68 | 65 20 73 79 6d 6d 65 74 | in th|e symmet|
|00004d40| 72 69 63 20 61 70 70 72 | 6f 61 63 68 2e 0a 0a 20 |ric appr|oach... |
|00004d50| 20 20 4e 6f 74 20 73 75 | 72 70 72 69 73 69 6e 67 | Not su|rprising|
|00004d60| 6c 79 2c 20 75 73 69 6e | 67 20 62 75 69 6c 64 69 |ly, usin|g buildi|
|00004d70| 6e 67 20 62 6c 6f 63 6b | 73 20 69 73 20 6d 6f 72 |ng block|s is mor|
|00004d80| 65 20 77 6f 72 6b 20 74 | 68 61 6e 20 75 73 69 6e |e work t|han usin|
|00004d90| 67 20 61 0a 20 20 20 22 | 62 75 69 6c 74 69 6e 22 |g a. "|builtin"|
|00004da0| 20 61 70 70 72 6f 61 63 | 68 20 66 6f 72 20 73 69 | approac|h for si|
|00004db0| 6d 70 6c 65 20 63 61 73 | 65 73 20 74 68 61 74 20 |mple cas|es that |
|00004dc0| 68 61 70 70 65 6e 20 74 | 6f 20 6d 61 74 63 68 20 |happen t|o match |
|00004dd0| 74 68 65 20 62 75 69 6c | 74 69 6e 0a 20 20 20 61 |the buil|tin. a|
|00004de0| 70 70 72 6f 61 63 68 2c | 20 62 75 74 20 68 61 76 |pproach,| but hav|
|00004df0| 69 6e 67 20 62 75 69 6c | 64 69 6e 67 20 62 6c 6f |ing buil|ding blo|
|00004e00| 63 6b 73 20 64 6f 65 73 | 20 75 6c 74 69 6d 61 74 |cks does| ultimat|
|00004e10| 65 6c 79 20 6d 65 61 6e | 20 6d 6f 72 65 0a 20 20 |ely mean| more. |
|00004e20| 20 66 6c 65 78 69 62 69 | 6c 69 74 79 20 66 6f 72 | flexibi|lity for|
|00004e30| 20 74 68 65 20 70 72 6f | 67 72 61 6d 6d 65 72 20 | the pro|grammer |
|00004e40| 2d 2d 20 74 68 65 72 65 | 20 61 72 65 20 6d 61 6e |-- there| are man|
|00004e50| 79 20 6f 74 68 65 72 20 | 73 74 72 75 63 74 75 72 |y other |structur|
|00004e60| 65 73 20 74 68 61 74 0a | 20 20 20 61 72 65 20 70 |es that.| are p|
|00004e70| 6f 73 73 69 62 6c 65 20 | 69 6e 20 61 64 64 69 74 |ossible |in addit|
|00004e80| 69 6f 6e 20 74 6f 20 74 | 68 65 20 74 77 6f 20 69 |ion to t|he two i|
|00004e90| 6c 6c 75 73 74 72 61 74 | 65 64 20 61 62 6f 76 65 |llustrat|ed above|
|00004ea0| 2c 20 75 73 69 6e 67 20 | 74 68 65 0a 20 20 20 61 |, using |the. a|
|00004eb0| 63 63 65 73 73 20 64 69 | 73 63 72 69 6d 69 6e 61 |ccess di|scrimina|
|00004ec0| 6e 74 20 62 75 69 6c 64 | 69 6e 67 20 62 6c 6f 63 |nt build|ing bloc|
|00004ed0| 6b 2e 0a 0a 20 20 20 46 | 6f 72 20 65 78 61 6d 70 |k... F|or examp|
|00004ee0| 6c 65 2c 20 66 6f 72 20 | 6d 69 78 69 6e 73 2c 20 |le, for |mixins, |
|00004ef0| 65 61 63 68 20 6d 69 78 | 69 6e 20 22 66 6c 61 76 |each mix|in "flav|
|00004f00| 6f 72 22 20 77 6f 75 6c | 64 20 68 61 76 65 20 61 |or" woul|d have a|
|00004f10| 6e 20 61 63 63 65 73 73 | 0a 20 20 20 64 69 73 63 |n access|. disc|
|00004f20| 72 69 6d 69 6e 61 6e 74 | 20 61 6c 72 65 61 64 79 |riminant| already|
|00004f30| 3a 0a 0a 20 20 20 20 20 | 74 79 70 65 20 57 69 6e |:.. |type Win|
|00004f40| 64 6f 77 20 69 73 20 2e | 2e 2e 20 20 2d 2d 20 54 |dow is .|.. -- T|
|00004f50| 68 65 20 62 61 73 69 63 | 20 22 76 61 6e 69 6c 6c |he basic| "vanill|
|00004f60| 61 22 20 77 69 6e 64 6f | 77 0a 0a 20 20 20 20 20 |a" windo|w.. |
|00004f70| 2d 2d 20 56 61 72 69 6f | 75 73 20 6d 69 78 69 6e |-- Vario|us mixin|
|00004f80| 73 0a 20 20 20 20 20 74 | 79 70 65 20 57 69 6e 5f |s. t|ype Win_|
|00004f90| 4d 69 78 69 6e 5f 31 20 | 28 57 20 3a 20 61 63 63 |Mixin_1 |(W : acc|
|00004fa0| 65 73 73 20 57 69 6e 64 | 6f 77 27 43 6c 61 73 73 |ess Wind|ow'Class|
|00004fb0| 29 20 69 73 20 2e 2e 2e | 0a 0a 20 20 20 20 20 74 |) is ...|.. t|
|00004fc0| 79 70 65 20 57 69 6e 5f | 4d 69 78 69 6e 5f 32 20 |ype Win_|Mixin_2 |
|00004fd0| 28 57 20 3a 20 61 63 63 | 65 73 73 20 57 69 6e 64 |(W : acc|ess Wind|
|00004fe0| 6f 77 27 43 6c 61 73 73 | 29 20 69 73 20 2e 2e 2e |ow'Class|) is ...|
|00004ff0| 0a 0a 20 20 20 20 20 74 | 79 70 65 20 57 69 6e 5f |.. t|ype Win_|
|00005000| 4d 69 78 69 6e 5f 33 20 | 28 57 20 3a 20 61 63 63 |Mixin_3 |(W : acc|
|00005010| 65 73 73 20 57 69 6e 64 | 6f 77 27 43 6c 61 73 73 |ess Wind|ow'Class|
|00005020| 29 20 69 73 20 2e 2e 2e | 0a 0a 0a 20 20 20 47 69 |) is ...|... Gi|
|00005030| 76 65 6e 20 74 68 65 20 | 61 62 6f 76 65 20 76 61 |ven the |above va|
|00005040| 6e 69 6c 6c 61 20 77 69 | 6e 64 6f 77 2c 20 70 6c |nilla wi|ndow, pl|
|00005050| 75 73 20 61 6e 79 20 6e | 75 6d 62 65 72 20 6f 66 |us any n|umber of|
|00005060| 20 77 69 6e 64 6f 77 20 | 6d 69 78 69 6e 73 2c 20 | window |mixins, |
|00005070| 6f 6e 65 0a 20 20 20 63 | 61 6e 20 63 6f 6e 73 74 |one. c|an const|
|00005080| 72 75 63 74 20 61 20 64 | 65 73 69 72 65 64 20 77 |ruct a d|esired w|
|00005090| 69 6e 64 6f 77 20 62 79 | 20 69 6e 63 6c 75 64 69 |indow by| includi|
|000050a0| 6e 67 20 61 73 20 6d 61 | 6e 79 20 6d 69 78 69 6e |ng as ma|ny mixin|
|000050b0| 73 20 61 73 20 77 61 6e | 74 65 64 3a 0a 0a 20 20 |s as wan|ted:.. |
|000050c0| 20 20 20 74 79 70 65 20 | 4d 79 5f 57 69 6e 64 6f | type |My_Windo|
|000050d0| 77 20 69 73 0a 20 20 20 | 20 20 20 20 6e 65 77 20 |w is. | new |
|000050e0| 57 69 6e 64 6f 77 0a 20 | 20 20 20 20 20 20 77 69 |Window. | wi|
|000050f0| 74 68 20 72 65 63 6f 72 | 64 0a 20 20 20 20 20 20 |th recor|d. |
|00005100| 20 20 20 4d 31 20 3a 20 | 57 69 6e 5f 4d 69 78 69 | M1 : |Win_Mixi|
|00005110| 6e 5f 31 20 28 4d 79 5f | 57 69 6e 64 6f 77 27 61 |n_1 (My_|Window'a|
|00005120| 63 63 65 73 73 29 3b 0a | 20 20 20 20 20 20 20 20 |ccess);.| |
|00005130| 20 4d 33 20 3a 20 57 69 | 6e 5f 4d 69 78 69 6e 5f | M3 : Wi|n_Mixin_|
|00005140| 33 20 28 4d 79 5f 57 69 | 6e 64 6f 77 27 61 63 63 |3 (My_Wi|ndow'acc|
|00005150| 65 73 73 29 3b 0a 20 20 | 20 20 20 20 20 20 20 4d |ess);. | M|
|00005160| 31 31 20 3a 20 57 69 6e | 5f 4d 69 78 69 6e 5f 31 |11 : Win|_Mixin_1|
|00005170| 28 4d 79 5f 57 69 6e 64 | 6f 77 27 61 63 63 65 73 |(My_Wind|ow'acces|
|00005180| 73 29 3b 0a 20 20 20 20 | 20 20 20 20 20 2e 2e 2e |s);. | ...|
|00005190| 20 2d 2d 20 70 6c 75 73 | 20 61 64 64 69 74 69 6f | -- plus| additio|
|000051a0| 6e 61 6c 20 73 74 75 66 | 66 2c 20 61 73 20 64 65 |nal stuf|f, as de|
|000051b0| 73 69 72 65 64 2e 0a 20 | 20 20 20 20 20 20 65 6e |sired.. | en|
|000051c0| 64 20 72 65 63 6f 72 64 | 3b 0a 0a 0a 20 20 20 41 |d record|;... A|
|000051d0| 73 20 69 6c 6c 75 73 74 | 72 61 74 65 64 20 61 62 |s illust|rated ab|
|000051e0| 6f 76 65 2c 20 79 6f 75 | 20 63 61 6e 20 69 6e 63 |ove, you| can inc|
|000051f0| 6f 72 70 6f 72 61 74 65 | 20 74 68 65 20 73 61 6d |orporate| the sam|
|00005200| 65 20 22 6d 69 78 69 6e | 22 20 6d 75 6c 74 69 70 |e "mixin|" multip|
|00005210| 6c 65 0a 20 20 20 74 69 | 6d 65 73 2c 20 77 69 74 |le. ti|mes, wit|
|00005220| 68 20 6e 6f 20 6e 61 6d | 69 6e 67 20 63 6f 6e 66 |h no nam|ing conf|
|00005230| 6c 69 63 74 73 2e 20 45 | 76 65 72 79 20 6d 69 78 |licts. E|very mix|
|00005240| 69 6e 20 63 61 6e 20 67 | 65 74 20 61 63 63 65 73 |in can g|et acces|
|00005250| 73 20 74 6f 20 74 68 65 | 0a 20 20 20 65 6e 63 6c |s to the|. encl|
|00005260| 6f 73 69 6e 67 20 6f 62 | 6a 65 63 74 2e 20 4f 70 |osing ob|ject. Op|
|00005270| 65 72 61 74 69 6f 6e 73 | 20 6f 66 20 69 6e 64 69 |erations| of indi|
|00005280| 76 69 64 75 61 6c 20 6d | 69 78 69 6e 73 20 63 61 |vidual m|ixins ca|
|00005290| 6e 20 62 65 20 6f 76 65 | 72 72 69 64 64 65 6e 20 |n be ove|rridden |
|000052a0| 62 79 0a 20 20 20 63 72 | 65 61 74 69 6e 67 20 61 |by. cr|eating a|
|000052b0| 6e 20 65 78 74 65 6e 73 | 69 6f 6e 20 6f 66 20 74 |n extens|ion of t|
|000052c0| 68 65 20 6d 69 78 69 6e | 20 66 69 72 73 74 2c 20 |he mixin| first, |
|000052d0| 6f 76 65 72 72 69 64 69 | 6e 67 20 74 68 65 20 6f |overridi|ng the o|
|000052e0| 70 65 72 61 74 69 6f 6e | 20 69 6e 0a 20 20 20 74 |peration| in. t|
|000052f0| 68 61 74 2c 20 61 6e 64 | 20 74 68 65 6e 20 69 6e |hat, and| then in|
|00005300| 63 6f 72 70 6f 72 61 74 | 69 6e 67 20 74 68 61 74 |corporat|ing that|
|00005310| 20 74 77 65 61 6b 65 64 | 20 6d 69 78 69 6e 20 69 | tweaked| mixin i|
|00005320| 6e 74 6f 20 74 68 65 20 | 75 6c 74 69 6d 61 74 65 |nto the |ultimate|
|00005330| 0a 20 20 20 77 69 6e 64 | 6f 77 2e 0a 0a 20 20 20 |. wind|ow... |
|00005340| 49 20 68 6f 70 65 20 74 | 68 65 20 61 62 6f 76 65 |I hope t|he above|
|00005350| 20 68 65 6c 70 73 20 62 | 65 74 74 65 72 20 69 6c | helps b|etter il|
|00005360| 6c 75 73 74 72 61 74 65 | 20 74 68 65 20 75 73 65 |lustrate| the use|
|00005370| 20 61 6e 64 20 66 6c 65 | 78 69 62 69 6c 69 74 79 | and fle|xibility|
|00005380| 20 6f 66 0a 20 20 20 74 | 68 65 20 41 64 61 20 39 | of. t|he Ada 9|
|00005390| 58 20 74 79 70 65 20 63 | 6f 6d 70 6f 73 69 74 69 |X type c|ompositi|
|000053a0| 6f 6e 20 62 75 69 6c 64 | 69 6e 67 20 62 6c 6f 63 |on build|ing bloc|
|000053b0| 6b 73 2e 0a 0a 0a 35 2e | 38 3a 20 48 6f 77 20 64 |ks....5.|8: How d|
|000053c0| 6f 65 73 20 41 64 61 20 | 64 6f 20 22 6e 61 72 72 |oes Ada |do "narr|
|000053d0| 6f 77 69 6e 67 22 3f 0a | 0a 20 20 20 44 61 76 65 |owing"?.|. Dave|
|000053e0| 20 47 72 69 66 66 69 74 | 68 20 73 61 69 64 0a 0a | Griffit|h said..|
|000053f0| 20 20 20 20 20 2e 20 2e | 20 2e 20 4e 6f 6e 65 74 | . .| . Nonet|
|00005400| 68 65 6c 65 73 73 2c 20 | 54 68 65 20 41 64 61 39 |heless, |The Ada9|
|00005410| 78 20 63 6f 6d 6d 69 74 | 74 65 65 20 63 68 6f 73 |x commit|tee chos|
|00005420| 65 20 61 20 73 74 72 75 | 63 74 75 72 65 2d 62 61 |e a stru|cture-ba|
|00005430| 73 65 64 0a 20 20 20 20 | 20 73 75 62 74 79 70 69 |sed. | subtypi|
|00005440| 6e 67 2c 20 77 69 74 68 | 20 61 6c 6c 20 6f 66 20 |ng, with| all of |
|00005450| 74 68 65 20 70 72 6f 62 | 6c 65 6d 73 20 74 68 61 |the prob|lems tha|
|00005460| 74 20 74 68 61 74 20 69 | 73 20 6b 6e 6f 77 6e 20 |t that i|s known |
|00005470| 74 6f 20 63 61 75 73 65 | 2e 20 41 73 0a 20 20 20 |to cause|. As. |
|00005480| 20 20 74 68 65 20 70 72 | 6f 62 6c 65 6d 73 20 6f | the pr|oblems o|
|00005490| 66 20 73 74 72 75 63 74 | 75 72 65 20 62 61 73 65 |f struct|ure base|
|000054a0| 64 20 73 75 62 74 79 70 | 69 6e 67 20 75 73 75 61 |d subtyp|ing usua|
|000054b0| 6c 6c 79 20 6d 61 6e 69 | 66 65 73 74 20 6f 6e 6c |lly mani|fest onl|
|000054c0| 79 20 69 6e 0a 20 20 20 | 20 20 6c 61 72 67 65 20 |y in. | large |
|000054d0| 70 72 6f 6a 65 63 74 73 | 20 6d 61 69 6e 74 61 69 |projects| maintai|
|000054e0| 6e 65 64 20 62 79 20 6c | 61 72 67 65 20 67 72 6f |ned by l|arge gro|
|000054f0| 75 70 73 2c 20 74 68 69 | 73 20 69 73 20 5f 70 72 |ups, thi|s is _pr|
|00005500| 65 63 69 73 65 6c 79 5f | 20 74 68 65 0a 20 20 20 |ecisely_| the. |
|00005510| 20 20 73 75 62 74 79 70 | 65 20 70 61 72 61 64 69 | subtyp|e paradi|
|00005520| 67 6d 20 74 68 61 74 20 | 41 64 61 39 78 20 73 68 |gm that |Ada9x sh|
|00005530| 6f 75 6c 64 20 68 61 76 | 65 20 61 76 6f 69 64 65 |ould hav|e avoide|
|00005540| 64 2e 20 41 64 61 39 78 | 27 73 20 6d 6f 64 65 6c |d. Ada9x|'s model|
|00005550| 20 69 73 2c 0a 20 20 20 | 20 20 61 73 20 54 75 63 | is,. | as Tuc|
|00005560| 6b 65 72 20 54 61 66 74 | 20 70 6f 69 6e 74 65 64 |ker Taft| pointed|
|00005570| 20 6f 75 74 2c 20 71 75 | 69 74 65 20 65 61 73 79 | out, qu|ite easy|
|00005580| 20 74 6f 20 75 73 65 20 | 66 6f 72 20 73 69 6d 70 | to use |for simp|
|00005590| 6c 65 20 4f 4f 0a 20 20 | 20 20 20 70 72 6f 67 72 |le OO. | progr|
|000055a0| 61 6d 6d 69 6e 67 2e 20 | 54 68 65 72 65 20 69 73 |amming. |There is|
|000055b0| 2c 20 68 6f 77 65 76 65 | 72 2c 20 6e 6f 20 67 6f |, howeve|r, no go|
|000055c0| 6f 64 20 72 65 61 73 6f | 6e 20 74 6f 20 5f 64 6f |od reaso|n to _do|
|000055d0| 5f 20 73 69 6d 70 6c 65 | 20 4f 4f 0a 20 20 20 20 |_ simple| OO. |
|000055e0| 20 70 72 6f 67 72 61 6d | 6d 69 6e 67 2e 20 4f 4f | program|ming. OO|
|000055f0| 20 70 72 6f 67 72 61 6d | 6d 69 6e 67 73 20 67 61 | program|mings ga|
|00005600| 69 6e 73 20 63 6c 69 63 | 6b 20 69 6e 20 73 6f 6d |ins clic|k in som|
|00005610| 65 77 68 65 72 65 20 61 | 72 6f 75 6e 64 20 31 30 |ewhere a|round 10|
|00005620| 2c 30 30 30 0a 20 20 20 | 20 20 4c 4f 43 2c 20 77 |,000. | LOC, w|
|00005630| 69 74 68 20 67 72 65 61 | 74 65 73 74 20 67 61 69 |ith grea|test gai|
|00005640| 6e 73 20 61 74 20 6f 76 | 65 72 20 31 30 30 2c 30 |ns at ov|er 100,0|
|00005650| 30 30 2e 20 41 74 20 74 | 68 65 73 65 20 73 69 7a |00. At t|hese siz|
|00005660| 65 73 2c 20 22 6a 75 73 | 74 0a 20 20 20 20 20 64 |es, "jus|t. d|
|00005670| 65 63 6c 61 72 65 20 69 | 74 20 74 61 67 67 65 64 |eclare i|t tagged|
|00005680| 22 20 77 69 6c 6c 20 72 | 65 73 75 6c 74 20 69 6e |" will r|esult in|
|00005690| 20 75 6e 6d 61 69 6e 74 | 61 69 6e 61 62 6c 65 20 | unmaint|ainable |
|000056a0| 6d 65 73 73 65 73 2e 20 | 4f 4f 0a 20 20 20 20 20 |messes. |OO. |
|000056b0| 70 72 6f 67 72 61 6d 6d | 69 6e 67 20 69 6e 20 74 |programm|ing in t|
|000056c0| 68 65 20 6c 61 72 67 65 | 20 72 61 70 69 64 6c 79 |he large| rapidly|
|000056d0| 20 67 65 74 73 20 64 69 | 66 66 69 63 75 6c 74 20 | gets di|fficult |
|000056e0| 77 69 74 68 20 73 74 72 | 75 63 74 75 72 65 20 62 |with str|ucture b|
|000056f0| 61 73 65 64 0a 20 20 20 | 20 20 73 75 62 74 79 70 |ased. | subtyp|
|00005700| 69 6e 67 2e 20 41 6c 6c | 6f 77 69 6e 67 20 62 79 |ing. All|owing by|
|00005710| 2d 76 61 6c 75 65 20 73 | 65 6d 61 6e 74 69 63 73 |-value s|emantics|
|00005720| 20 66 6f 72 20 6f 62 6a | 65 63 74 73 20 63 6f 6d | for obj|ects com|
|00005730| 70 6f 75 6e 64 73 20 74 | 68 65 73 65 0a 20 20 20 |pounds t|hese. |
|00005740| 20 20 70 72 6f 62 6c 65 | 6d 73 2e 20 41 6c 6c 20 | proble|ms. All |
|00005750| 6f 66 20 74 68 69 73 20 | 69 73 20 6b 6e 6f 77 6e |of this |is known|
|00005760| 2e 20 41 6c 6c 20 6f 66 | 20 74 68 69 73 20 77 61 |. All of| this wa|
|00005770| 73 2c 20 73 65 65 6d 69 | 6e 67 6c 79 2c 20 69 67 |s, seemi|ngly, ig|
|00005780| 6e 6f 72 65 64 0a 20 20 | 20 20 20 62 79 20 41 64 |nored. | by Ad|
|00005790| 61 39 78 2e 0a 0a 0a 20 | 20 20 28 54 75 63 6b 65 |a9x.... | (Tucke|
|000057a0| 72 20 54 61 66 74 20 61 | 6e 73 77 65 72 73 29 0a |r Taft a|nswers).|
|000057b0| 0a 20 20 20 41 73 20 65 | 78 70 6c 61 69 6e 65 64 |. As e|xplained|
|000057c0| 20 69 6e 20 61 20 70 72 | 65 76 69 6f 75 73 20 6e | in a pr|evious n|
|000057d0| 6f 74 65 2c 20 41 64 61 | 20 39 58 20 73 75 70 70 |ote, Ada| 9X supp|
|000057e0| 6f 72 74 73 20 74 68 65 | 20 61 62 69 6c 69 74 79 |orts the| ability|
|000057f0| 20 74 6f 20 68 69 64 65 | 0a 20 20 20 74 68 65 20 | to hide|. the |
|00005800| 69 6d 70 6c 65 6d 65 6e | 74 61 74 69 6f 6e 20 68 |implemen|tation h|
|00005810| 65 72 69 74 61 67 65 20 | 6f 66 20 61 20 74 79 70 |eritage |of a typ|
|00005820| 65 2c 20 61 6e 64 20 6f | 6e 6c 79 20 65 78 70 6f |e, and o|nly expo|
|00005830| 73 65 20 74 68 65 20 64 | 65 73 69 72 65 64 0a 20 |se the d|esired. |
|00005840| 20 20 69 6e 74 65 72 66 | 61 63 65 20 68 65 72 69 | interf|ace heri|
|00005850| 74 61 67 65 2e 20 53 6f | 20 77 65 20 61 72 65 20 |tage. So| we are |
|00005860| 6e 6f 74 20 73 74 75 63 | 6b 20 77 69 74 68 20 73 |not stuc|k with s|
|00005870| 74 72 69 63 74 6c 79 20 | 22 73 74 72 75 63 74 75 |trictly |"structu|
|00005880| 72 65 2d 62 61 73 65 64 | 0a 20 20 20 73 75 62 74 |re-based|. subt|
|00005890| 79 70 69 6e 67 2e 22 20 | 53 65 63 6f 6e 64 6c 79 |yping." |Secondly|
|000058a0| 2c 20 62 79 2d 72 65 66 | 65 72 65 6e 63 65 20 73 |, by-ref|erence s|
|000058b0| 65 6d 61 6e 74 69 63 73 | 20 68 61 76 65 20 6d 61 |emantics| have ma|
|000058c0| 6e 79 20 22 77 65 6c 6c | 20 6b 6e 6f 77 6e 22 0a |ny "well| known".|
|000058d0| 20 20 20 70 72 6f 62 6c | 65 6d 73 20 61 73 20 77 | probl|ems as w|
|000058e0| 65 6c 6c 2c 20 61 6e 64 | 20 74 68 65 20 64 65 73 |ell, and| the des|
|000058f0| 69 67 6e 65 72 73 20 6f | 66 20 4d 6f 64 75 6c 61 |igners o|f Modula|
|00005900| 2d 33 20 63 68 6f 73 65 | 20 74 6f 2c 20 73 65 65 |-3 chose| to, see|
|00005910| 6d 69 6e 67 6c 79 2c 0a | 20 20 20 69 67 6e 6f 72 |mingly,.| ignor|
|00005920| 65 20 74 68 6f 73 65 20 | 3b 2d 29 20 3b 2d 29 2e |e those |;-) ;-).|
|00005930| 20 4f 66 20 63 6f 75 72 | 73 65 2c 20 69 6e 20 72 | Of cour|se, in r|
|00005940| 65 61 6c 69 74 79 2c 20 | 6e 65 69 74 68 65 72 20 |eality, |neither |
|00005950| 73 65 74 20 6f 66 20 6c | 61 6e 67 75 61 67 65 0a |set of l|anguage.|
|00005960| 20 20 20 64 65 73 69 67 | 6e 65 72 73 20 69 67 6e | desig|ners ign|
|00005970| 6f 72 65 64 20 65 69 74 | 68 65 72 20 6f 66 20 74 |ored eit|her of t|
|00005980| 68 65 73 65 20 69 73 73 | 75 65 73 2e 20 4c 61 6e |hese iss|ues. Lan|
|00005990| 67 75 61 67 65 20 64 65 | 73 69 67 6e 20 69 6e 76 |guage de|sign inv|
|000059a0| 6f 6c 76 65 73 0a 20 20 | 20 74 72 61 64 65 6f 66 |olves. | tradeof|
|000059b0| 66 73 2e 20 59 6f 75 20 | 63 61 6e 20 63 6f 6d 70 |fs. You |can comp|
|000059c0| 6c 61 69 6e 20 77 65 20 | 6d 61 64 65 20 74 68 65 |lain we |made the|
|000059d0| 20 77 72 6f 6e 67 20 74 | 72 61 64 65 6f 66 66 2c | wrong t|radeoff,|
|000059e0| 20 62 75 74 20 74 6f 0a | 20 20 20 63 6f 6e 74 69 | but to.| conti|
|000059f0| 6e 75 65 20 74 6f 20 68 | 61 72 70 20 6f 6e 20 74 |nue to h|arp on t|
|00005a00| 68 65 20 63 6c 61 69 6d | 20 74 68 61 74 20 77 65 |he claim| that we|
|00005a10| 20 22 69 67 6e 6f 72 65 | 64 22 20 74 68 69 6e 67 | "ignore|d" thing|
|00005a20| 73 20 69 73 20 73 69 6c | 6c 79 2e 20 57 65 0a 20 |s is sil|ly. We. |
|00005a30| 20 20 73 74 75 64 69 65 | 64 20 65 76 65 72 79 20 | studie|d every |
|00005a40| 4f 4f 50 20 6c 61 6e 67 | 75 61 67 65 20 75 6e 64 |OOP lang|uage und|
|00005a50| 65 72 20 74 68 65 20 73 | 75 6e 20 6f 6e 20 77 68 |er the s|un on wh|
|00005a60| 69 63 68 20 77 65 20 63 | 6f 75 6c 64 20 66 69 6e |ich we c|ould fin|
|00005a70| 64 20 61 6e 79 0a 20 20 | 20 77 72 69 74 74 65 6e |d any. | written|
|00005a80| 20 6f 72 20 65 6c 65 63 | 74 72 6f 6e 69 63 20 6d | or elec|tronic m|
|00005a90| 61 74 65 72 69 61 6c 2e | 20 57 65 20 63 68 6f 73 |aterial.| We chos|
|00005aa0| 65 20 76 61 6c 75 65 2d | 62 61 73 65 64 20 73 65 |e value-|based se|
|00005ab0| 6d 61 6e 74 69 63 73 20 | 66 6f 72 0a 20 20 20 77 |mantics |for. w|
|00005ac0| 68 61 74 20 77 65 20 62 | 65 6c 69 65 76 65 20 61 |hat we b|elieve a|
|00005ad0| 72 65 20 67 6f 6f 64 20 | 72 65 61 73 6f 6e 73 2c |re good |reasons,|
|00005ae0| 20 62 61 73 65 64 20 6f | 6e 20 72 65 61 73 6f 6e | based o|n reason|
|00005af0| 61 62 6c 65 20 74 72 61 | 64 65 6f 66 66 73 2e 0a |able tra|deoffs..|
|00005b00| 0a 20 20 20 46 69 72 73 | 74 20 6f 66 20 61 6c 6c |. Firs|t of all|
|00005b10| 2c 20 69 6e 20 74 68 65 | 20 61 62 73 65 6e 63 65 |, in the| absence|
|00005b20| 20 6f 66 20 61 6e 20 69 | 6e 74 65 67 72 61 74 65 | of an i|ntegrate|
|00005b30| 64 20 67 61 72 62 61 67 | 65 20 63 6f 6c 6c 65 63 |d garbag|e collec|
|00005b40| 74 6f 72 2c 0a 20 20 20 | 62 79 2d 72 65 66 65 72 |tor,. |by-refer|
|00005b50| 65 6e 63 65 20 73 65 6d | 61 6e 74 69 63 73 20 64 |ence sem|antics d|
|00005b60| 6f 65 73 6e 27 74 20 6d | 61 6b 65 20 6d 75 63 68 |oesn't m|ake much|
|00005b70| 20 73 65 6e 73 65 2e 20 | 42 61 73 65 64 20 6f 6e | sense. |Based on|
|00005b80| 20 76 61 72 69 6f 75 73 | 0a 20 20 20 74 72 61 64 | various|. trad|
|00005b90| 65 6f 66 66 73 2c 20 77 | 65 20 64 65 63 69 64 65 |eoffs, w|e decide|
|00005ba0| 64 20 61 67 61 69 6e 73 | 74 20 72 65 71 75 69 72 |d agains|t requir|
|00005bb0| 69 6e 67 20 61 6e 20 69 | 6e 74 65 67 72 61 74 65 |ing an i|ntegrate|
|00005bc0| 64 20 67 61 72 62 61 67 | 65 0a 20 20 20 63 6f 6c |d garbag|e. col|
|00005bd0| 6c 65 63 74 6f 72 20 66 | 6f 72 20 41 64 61 20 39 |lector f|or Ada 9|
|00005be0| 58 2e 0a 0a 20 20 20 53 | 65 63 6f 6e 64 6c 79 2c |X... S|econdly,|
|00005bf0| 20 6d 61 6e 79 20 6f 66 | 20 74 68 65 20 22 6b 6e | many of| the "kn|
|00005c00| 6f 77 6e 22 20 70 72 6f | 62 6c 65 6d 73 20 77 69 |own" pro|blems wi|
|00005c10| 74 68 20 62 79 2d 76 61 | 6c 75 65 20 73 65 6d 61 |th by-va|lue sema|
|00005c20| 6e 74 69 63 73 20 77 65 | 0a 20 20 20 61 76 6f 69 |ntics we|. avoi|
|00005c30| 64 65 64 2c 20 62 79 20 | 65 6c 69 6d 69 6e 61 74 |ded, by |eliminat|
|00005c40| 69 6e 67 20 65 73 73 65 | 6e 74 69 61 6c 6c 79 20 |ing esse|ntially |
|00005c50| 61 6c 6c 20 63 61 73 65 | 73 20 6f 66 20 22 69 6d |all case|s of "im|
|00005c60| 70 6c 69 63 69 74 0a 20 | 20 20 74 72 75 6e 63 61 |plicit. | trunca|
|00005c70| 74 69 6f 6e 2e 22 20 4f | 6e 65 20 6f 66 20 74 68 |tion." O|ne of th|
|00005c80| 65 20 70 72 6f 62 6c 65 | 6d 73 20 77 69 74 68 20 |e proble|ms with |
|00005c90| 74 68 65 20 43 2b 2b 20 | 76 65 72 73 69 6f 6e 20 |the C++ |version |
|00005ca0| 6f 66 20 22 76 61 6c 75 | 65 0a 20 20 20 73 65 6d |of "valu|e. sem|
|00005cb0| 61 6e 74 69 63 73 22 20 | 69 73 20 74 68 61 74 20 |antics" |is that |
|00005cc0| 6f 6e 20 61 73 73 69 67 | 6e 6d 65 6e 74 20 61 6e |on assig|nment an|
|00005cd0| 64 20 70 61 72 61 6d 65 | 74 65 72 20 70 61 73 73 |d parame|ter pass|
|00005ce0| 69 6e 67 2c 20 69 6d 70 | 6c 69 63 69 74 0a 20 20 |ing, imp|licit. |
|00005cf0| 20 74 72 75 6e 63 61 74 | 69 6f 6e 20 63 61 6e 20 | truncat|ion can |
|00005d00| 74 61 6b 65 20 70 6c 61 | 63 65 20 6d 79 73 74 65 |take pla|ce myste|
|00005d10| 72 69 6f 75 73 6c 79 2c | 20 6d 65 61 6e 69 6e 67 |riously,| meaning|
|00005d20| 20 74 68 61 74 20 61 20 | 76 61 6c 75 65 20 74 68 | that a |value th|
|00005d30| 61 74 0a 20 20 20 73 74 | 61 72 74 65 64 20 69 74 |at. st|arted it|
|00005d40| 73 20 6c 69 66 65 20 72 | 65 70 72 65 73 65 6e 74 |s life r|epresent|
|00005d50| 69 6e 67 20 6f 6e 65 20 | 6b 69 6e 64 20 6f 66 20 |ing one |kind of |
|00005d60| 74 68 69 6e 67 20 67 65 | 74 73 20 74 72 75 6e 63 |thing ge|ts trunc|
|00005d70| 61 74 65 64 0a 20 20 20 | 75 6e 69 6e 74 65 6e 74 |ated. |unintent|
|00005d80| 69 6f 6e 61 6c 6c 79 20 | 73 6f 20 74 68 61 74 20 |ionally |so that |
|00005d90| 69 74 20 6c 6f 6f 6b 73 | 20 6c 69 6b 65 20 61 20 |it looks| like a |
|00005da0| 76 61 6c 75 65 20 6f 66 | 20 73 6f 6d 65 20 61 6e |value of| some an|
|00005db0| 63 65 73 74 6f 72 20 74 | 79 70 65 2e 0a 20 20 20 |cestor t|ype.. |
|00005dc0| 54 68 69 73 20 69 73 20 | 6c 61 72 67 65 6c 79 20 |This is |largely |
|00005dd0| 62 65 63 61 75 73 65 20 | 74 68 65 20 6e 61 6d 65 |because |the name|
|00005de0| 20 6f 66 20 61 20 43 2b | 2b 20 63 6c 61 73 73 20 | of a C+|+ class |
|00005df0| 6d 65 61 6e 73 20 64 69 | 66 66 65 72 6e 74 20 74 |means di|ffernt t|
|00005e00| 68 69 6e 67 73 0a 20 20 | 20 64 65 70 65 6e 64 69 |hings. | dependi|
|00005e10| 6e 67 20 6f 6e 20 74 68 | 65 20 63 6f 6e 74 65 78 |ng on th|e contex|
|00005e20| 74 2e 20 57 68 65 6e 20 | 79 6f 75 20 64 65 63 6c |t. When |you decl|
|00005e30| 61 72 65 20 61 6e 20 6f | 62 6a 65 63 74 2c 20 74 |are an o|bject, t|
|00005e40| 68 65 20 6e 61 6d 65 20 | 6f 66 20 74 68 65 0a 20 |he name |of the. |
|00005e50| 20 20 63 6c 61 73 73 20 | 64 65 74 65 72 6d 69 6e | class |determin|
|00005e60| 65 73 20 74 68 65 20 22 | 65 78 61 63 74 20 63 6c |es the "|exact cl|
|00005e70| 61 73 73 22 20 6f 66 20 | 74 68 65 20 6f 62 6a 65 |ass" of |the obje|
|00005e80| 63 74 2e 20 54 68 65 20 | 73 61 6d 65 20 74 68 69 |ct. The |same thi|
|00005e90| 6e 67 0a 20 20 20 61 70 | 70 6c 69 65 73 20 74 6f |ng. ap|plies to|
|00005ea0| 20 61 20 62 79 2d 76 61 | 6c 75 65 20 70 61 72 61 | a by-va|lue para|
|00005eb0| 6d 65 74 65 72 2e 20 48 | 6f 77 65 76 65 72 2c 20 |meter. H|owever, |
|00005ec0| 66 6f 72 20 72 65 66 65 | 72 65 6e 63 65 73 20 61 |for refe|rences a|
|00005ed0| 6e 64 20 70 6f 69 6e 74 | 65 72 73 2c 0a 20 20 20 |nd point|ers,. |
|00005ee0| 74 68 65 20 6e 61 6d 65 | 20 6f 66 20 61 20 63 6c |the name| of a cl|
|00005ef0| 61 73 73 20 73 74 61 6e | 64 73 20 66 6f 72 20 74 |ass stan|ds for t|
|00005f00| 68 61 74 20 63 6c 61 73 | 73 20 61 6e 64 20 61 6c |hat clas|s and al|
|00005f10| 6c 20 6f 66 20 69 74 73 | 20 64 65 72 69 76 61 74 |l of its| derivat|
|00005f20| 69 76 65 73 2e 0a 20 20 | 20 42 75 74 20 73 69 6e |ives.. | But sin|
|00005f30| 63 65 2c 20 69 6e 20 43 | 2b 2b 2c 20 61 20 76 61 |ce, in C|++, a va|
|00005f40| 6c 75 65 20 6f 66 20 61 | 20 73 75 62 63 6c 61 73 |lue of a| subclas|
|00005f50| 73 20 69 73 20 61 6c 77 | 61 79 73 20 61 63 63 65 |s is alw|ays acce|
|00005f60| 70 74 61 62 6c 65 20 77 | 68 65 72 65 20 61 0a 20 |ptable w|here a. |
|00005f70| 20 20 76 61 6c 75 65 20 | 6f 66 20 61 20 67 69 76 | value |of a giv|
|00005f80| 65 6e 20 63 6c 61 73 73 | 20 69 73 20 65 78 70 65 |en class| is expe|
|00005f90| 63 74 65 64 2c 20 79 6f | 75 20 63 61 6e 20 67 65 |cted, yo|u can ge|
|00005fa0| 74 20 69 6d 70 6c 69 63 | 69 74 20 74 72 75 6e 63 |t implic|it trunc|
|00005fb0| 61 74 69 6f 6e 20 61 73 | 0a 20 20 20 70 61 72 74 |ation as|. part|
|00005fc0| 20 6f 66 20 61 73 73 69 | 67 6e 6d 65 6e 74 20 61 | of assi|gnment a|
|00005fd0| 6e 64 20 62 79 2d 76 61 | 6c 75 65 20 70 61 72 61 |nd by-va|lue para|
|00005fe0| 6d 65 74 65 72 20 70 61 | 73 73 69 6e 67 2e 20 49 |meter pa|ssing. I|
|00005ff0| 6e 20 41 64 61 20 39 58 | 2c 20 77 65 20 61 76 6f |n Ada 9X|, we avo|
|00006000| 69 64 0a 20 20 20 74 68 | 65 20 69 6d 70 6c 69 63 |id. th|e implic|
|00006010| 69 74 20 74 72 75 6e 63 | 61 74 69 6f 6e 20 62 65 |it trunc|ation be|
|00006020| 63 61 75 73 65 20 77 65 | 20 73 75 70 70 6f 72 74 |cause we| support|
|00006030| 20 61 73 73 69 67 6e 6d | 65 6e 74 20 66 6f 72 20 | assignm|ent for |
|00006040| 22 63 6c 61 73 73 2d 77 | 69 64 65 22 0a 20 20 20 |"class-w|ide". |
|00006050| 74 79 70 65 73 2c 20 77 | 68 69 63 68 20 6e 65 76 |types, w|hich nev|
|00006060| 65 72 20 69 6d 70 6c 69 | 63 69 74 6c 79 20 74 72 |er impli|citly tr|
|00006070| 75 6e 63 61 74 65 73 2c | 20 61 6e 64 20 6f 6e 65 |uncates,| and one|
|00006080| 20 6d 75 73 74 20 64 6f | 20 61 6e 20 65 78 70 6c | must do| an expl|
|00006090| 69 63 69 74 0a 20 20 20 | 63 6f 6e 76 65 72 73 69 |icit. |conversi|
|000060a0| 6f 6e 20 74 6f 20 64 6f | 20 61 6e 20 61 73 73 69 |on to do| an assi|
|000060b0| 67 6e 6d 65 6e 74 20 74 | 68 61 74 20 74 72 75 6e |gnment t|hat trun|
|000060c0| 63 61 74 65 73 2e 20 50 | 61 72 61 6d 65 74 65 72 |cates. P|arameter|
|000060d0| 20 70 61 73 73 69 6e 67 | 20 6e 65 76 65 72 0a 20 | passing| never. |
|000060e0| 20 20 69 6d 70 6c 69 63 | 69 74 6c 79 20 74 72 75 | implic|itly tru|
|000060f0| 6e 63 61 74 65 73 2c 20 | 65 76 65 6e 20 69 66 20 |ncates, |even if |
|00006100| 61 6e 20 69 6d 70 6c 69 | 63 69 74 20 63 6f 6e 76 |an impli|cit conv|
|00006110| 65 72 73 69 6f 6e 20 69 | 73 20 70 65 72 66 6f 72 |ersion i|s perfor|
|00006120| 6d 65 64 20 61 73 0a 20 | 20 20 70 61 72 74 20 6f |med as. | part o|
|00006130| 66 20 63 61 6c 6c 69 6e | 67 20 61 6e 20 69 6e 68 |f callin|g an inh|
|00006140| 65 72 69 74 65 64 20 73 | 75 62 70 72 6f 67 72 61 |erited s|ubprogra|
|00006150| 6d 2e 0a 0a 0a 35 2e 39 | 3a 20 57 68 61 74 20 69 |m....5.9|: What i|
|00006160| 73 20 74 68 65 20 64 69 | 66 66 65 72 65 6e 63 65 |s the di|fference|
|00006170| 20 62 65 74 77 65 65 6e | 20 61 20 63 6c 61 73 73 | between| a class|
|00006180| 2d 77 69 64 65 20 61 63 | 63 65 73 73 20 74 79 70 |-wide ac|cess typ|
|00006190| 65 20 61 6e 64 20 61 20 | 22 67 65 6e 65 72 61 6c |e and a |"general|
|000061a0| 22 0a 63 6c 61 73 73 2d | 77 69 64 65 20 61 63 63 |".class-|wide acc|
|000061b0| 65 73 73 20 74 79 70 65 | 3f 0a 0a 20 20 20 20 20 |ess type|?.. |
|000061c0| 57 68 61 74 20 69 73 20 | 65 78 61 63 74 6c 79 20 |What is |exactly |
|000061d0| 74 68 65 20 64 69 66 66 | 65 72 65 6e 63 65 20 62 |the diff|erence b|
|000061e0| 65 74 77 65 65 6e 0a 0a | 74 79 70 65 20 41 20 69 |etween..|type A i|
|000061f0| 73 20 61 63 63 65 73 73 | 20 4f 62 6a 65 63 74 27 |s access| Object'|
|00006200| 43 6c 61 73 73 3b 0a 0a | 20 20 20 20 20 61 6e 64 |Class;..| and|
|00006210| 0a 0a 74 79 70 65 20 42 | 20 69 73 20 61 63 63 65 |..type B| is acce|
|00006220| 73 73 20 61 6c 6c 20 4f | 62 6a 65 63 74 27 43 6c |ss all O|bject'Cl|
|00006230| 61 73 73 3b 0a 0a 20 20 | 20 20 20 49 6e 20 74 68 |ass;.. | In th|
|00006240| 65 20 52 4d 20 61 6e 64 | 20 52 61 74 69 6f 6e 61 |e RM and| Rationa|
|00006250| 6c 65 20 6f 6e 6c 79 20 | 64 65 66 69 6e 69 74 69 |le only |definiti|
|00006260| 6f 6e 73 20 6c 69 6b 65 | 20 42 20 61 72 65 20 75 |ons like| B are u|
|00006270| 73 65 64 2e 20 57 68 61 | 74 27 73 20 74 68 65 0a |sed. Wha|t's the.|
|00006280| 20 20 20 20 20 75 73 65 | 20 66 6f 72 20 41 2d 6c | use| for A-l|
|00006290| 69 6b 65 20 64 65 66 69 | 6e 69 74 69 6f 6e 73 20 |ike defi|nitions |
|000062a0| 3f 0a 0a 0a 20 20 20 28 | 54 75 63 6b 65 72 20 54 |?... (|Tucker T|
|000062b0| 61 66 74 20 61 6e 73 77 | 65 72 73 29 0a 0a 20 20 |aft answ|ers).. |
|000062c0| 20 54 68 65 20 6f 6e 6c | 79 20 64 69 66 66 65 72 | The onl|y differ|
|000062d0| 65 6e 63 65 20 69 73 20 | 74 68 61 74 20 41 20 69 |ence is |that A i|
|000062e0| 73 20 6d 6f 72 65 20 72 | 65 73 74 72 69 63 74 69 |s more r|estricti|
|000062f0| 76 65 2c 20 61 6e 64 20 | 73 6f 20 70 72 65 73 75 |ve, and |so presu|
|00006300| 6d 61 62 6c 79 0a 20 20 | 20 6d 69 67 68 74 20 63 |mably. | might c|
|00006310| 61 74 63 68 20 62 75 67 | 73 20 74 68 61 74 20 42 |atch bug|s that B|
|00006320| 20 77 6f 75 6c 64 20 6e | 6f 74 2e 20 41 20 69 73 | would n|ot. A is|
|00006330| 20 61 20 22 70 6f 6f 6c | 2d 73 70 65 63 69 66 69 | a "pool|-specifi|
|00006340| 63 22 20 61 63 63 65 73 | 73 20 74 79 70 65 2c 0a |c" acces|s type,.|
|00006350| 20 20 20 61 6e 64 20 61 | 73 20 73 75 63 68 2c 20 | and a|s such, |
|00006360| 79 6f 75 20 63 61 6e 6e | 6f 74 20 63 6f 6e 76 65 |you cann|ot conve|
|00006370| 72 74 20 76 61 6c 75 65 | 73 20 6f 66 20 6f 74 68 |rt value|s of oth|
|00006380| 65 72 20 61 63 63 65 73 | 73 20 74 79 70 65 73 20 |er acces|s types |
|00006390| 74 6f 20 69 74 2c 0a 20 | 20 20 6e 6f 72 20 63 61 |to it,. | nor ca|
|000063a0| 6e 20 79 6f 75 20 75 73 | 65 20 27 41 63 63 65 73 |n you us|e 'Acces|
|000063b0| 73 20 74 6f 20 63 72 65 | 61 74 65 20 76 61 6c 75 |s to cre|ate valu|
|000063c0| 65 73 20 6f 66 20 74 79 | 70 65 20 41 2e 20 56 61 |es of ty|pe A. Va|
|000063d0| 6c 75 65 73 20 6f 66 20 | 74 79 70 65 20 41 0a 20 |lues of |type A. |
|000063e0| 20 20 6d 61 79 20 6f 6e | 6c 79 20 70 6f 69 6e 74 | may on|ly point|
|000063f0| 20 69 6e 74 6f 20 69 74 | 73 20 22 6f 77 6e 22 20 | into it|s "own" |
+--------+-------------------------+-------------------------+--------+--------+
Only 25.0 KB of data is shown above.