吃什么补营养最快| 翕什么意思| venes保温杯是什么品牌| 伤口不结痂是什么原因| 左侧卵巢囊性包块是什么意思| 唐僧是什么生肖| 高血糖适合吃什么水果| 大校是什么级别| 窦性心动过速吃什么药| 什么是三界五行| 肝脑涂地是什么意思| 维生素b什么时候吃效果最好| 极乐是什么意思| 五月二十九是什么日子| 佩戴朱砂有什么好处| 咖啡什么时候喝最好| 胃强脾弱吃什么中成药| 安痛定又叫什么| 溶血症是什么意思| 推测是什么意思| 乳腺钼靶是什么意思| 0中间有一横是什么字体| 爱我永不变是什么歌| 欧巴什么意思| 翘嘴鱼是什么鱼| 覆盖的意思是什么| 谪仙是什么意思| 西藏有什么特产| 司马迁属什么生肖| 头不由自主的轻微晃动是什么病| 指鼻试验阳性代表什么| 黄喉是什么部位| 肠化是什么意思| 刮痧和拔罐有什么区别| 血小板分布宽度偏高是什么意思| 长庚是什么意思| hbr是什么意思| 六月初一是什么日子| 一到晚上就咳嗽是什么原因| 你是我的楼兰是什么意思| 心脏有早搏吃什么药好| 什么是冰晶| cro是什么意思| 吃什么能化解肾结石| 早搏吃什么药最管用| 2月24日是什么星座| esim卡是什么| cv是什么意思| 什么叫桥本甲状腺炎| 肝火郁结是什么症状| 唇炎用什么药| 为什么空腹血糖比餐后血糖高| 林黛玉是什么病| 寻常疣用什么药膏除根| 圣女是什么生肖| 梦见着火了是什么征兆| 胸口痛挂什么科| 上海为什么叫上海| 尿酸高吃什么中药能降下来| 吕布属什么生肖| 小孩说梦话是什么原因引起的| 吃山楂有什么好处| 老豆腐和嫩豆腐有什么区别| 处女膜是什么颜色| 动车与高铁有什么区别| 踏雪寻梅是什么意思| 烧心是什么原因造成的| 疣是什么病毒| 肩胛骨突出是什么原因| 山东有什么好吃的| tommy什么牌子| 信誓旦旦是什么意思| 胃酸反流是什么原因| 中国国菜是什么菜| 深闺是什么意思| 石钟乳是什么意思| 胰腺是什么器官| 发烧白细胞高是什么原因| 上身胖下身瘦是什么原因| 睡眠不足会引起什么症状| 高原反应什么症状| 梦到捡金子首饰是什么意思| 什么情况下会宫外孕| 神经元特异性烯醇化酶是什么意思| 什么叫贫血| 辅警和协警有什么区别| 脾胃不好吃什么水果| 寄居蟹吃什么食物| 发烧拉肚子吃什么药| id医学上是什么意思| 太阳是什么星| 男人腰痛吃什么药| 胚胎停育有什么症状| 干咳 吃什么药| 哈密瓜苦是什么原因| 高血糖适合吃什么水果| 1965属什么生肖| 抖机灵是什么意思| 肾囊性灶是什么意思| 男性一般检查什么| 蛋白过敏是什么症状| 首套房有什么优惠政策| 洪都拉斯为什么不与中国建交| 梦到和老公离婚了是什么征兆| 腋毛癣用什么药膏最好| 六月初一有什么讲究| 什么的树叶| 咖啡喝多了有什么危害| 桃子不能和什么一起吃| blk是什么意思| 什么叫淋巴结转移| 咳嗽挂什么科| 宋朝后面是什么朝代| 剌是什么意思| 什么是偏印| 4.23是什么星座| 马蹄铁什么时候发明的| 血糖高适合喝什么牛奶| 两个人一个且念什么| 木樨是什么意思| 农历5月20日是什么星座| 牙龈炎吃什么消炎药| 莲子心和什么搭配最佳治失眠| 北京市长属于什么级别| 牙龈出血缺什么维生素| 早上九点半是什么时辰| electrolux是什么牌子| 乳蛾是什么意思| 导演是干什么的| 鞘膜积液挂什么科| 肛裂用什么药治最好效果最快| 深情款款什么意思| 金棕色是什么颜色| 吃什么能消除囊肿| 闭日是什么意思| 看肝挂什么科| 嗓子疼吃什么| 健身吃什么长肌肉最快| 九肚鱼是什么鱼| 护理是做什么的| 主观意识是什么意思| 他克莫司软膏治疗什么| 吃什么减脂肪最快最有效的方法| lining是什么意思| 淋球菌是什么| 7点至9点是什么时辰| 芥末是什么植物做的| 爱发朋友圈的女人是什么心态| 扁平足是什么样的| 什么是早教机| 吃什么东西对胃好| 降龙十八掌最后一掌叫什么| 豆蔻年华是什么意思| 访谈是什么意思| 淀粉可以用什么代替| 脾挂什么科| 根尖周炎吃什么药| 中暑用什么药| 肠胃不好拉肚子吃什么药| 脚麻是什么原因引起的| 观落阴是什么意思| 翠玉是什么玉| 师范类是什么意思| 鹦鹉吃什么食物| vvip是什么意思| 出汗多吃什么好| 为什么会缺钾| 为什么会基因突变| 身上痒但是什么都没有| 急性咽炎吃什么药| 心季是什么原因| 手抖是什么症状| 慢慢地什么| 小孩手指头脱皮是什么原因| 生酮是什么意思| 耳鸣什么原因| 做人流挂什么科| 最大的荔枝是什么品种| 十八岁是什么年华| 上环什么时候去最合适| 交警支队长是什么级别| 2.4号是什么星座| 胆囊炎吃什么药效果最好| 维生素c十一什么意思| 农历8月15是什么节日| 早上起床口苦口干是什么原因| 节瓜是什么瓜| 蛇为什么怕鹅| 孟子名什么| 孙悟空原名叫什么| 织锦缎是什么面料| 白带什么味道| 14年婚姻是什么婚| 梦见朋友怀孕了是什么意思| hcv是什么病| 牛魔王是什么生肖| 肝硬化吃什么好| 什么地流淌| 西瓜汁加什么好喝| 神经是什么| 结节是什么原因引起的| 低钾会出现什么症状| 人参吃了有什么好处| 丝光棉是什么材质| 肺部肿瘤3cm什么期| 勿忘我是什么意思| 什么是碱性磷酸酶高怎么回事| 令是什么生肖| 欧阳修是什么居士| 大暑是什么时候| 糖尿病患者适合吃什么水果| 前列腺炎是什么原因引起| 媾是什么意思| 非布司他片是什么药| 滇红属于什么茶| 河北有什么山| 什么中药可以减肥| 胃不舒服吃什么好| 什么情况下打破伤风针| 逍遥丸什么时候吃最好| 梦见亲人哭是什么征兆| 胃不舒服吃什么药| 女生自慰什么感觉| 西葫芦不能和什么一起吃| 嘴唇发紫什么原因| 梦见脱发是什么征兆| 甲状腺2类是什么意思| 佛珠断了有什么预兆| Fine什么意思中文| 手心烫是什么原因| 天然气什么味道| 被蚊子咬了涂什么| 胸闷气短吃什么药效果好| 肠溶片和缓释片有什么区别| 肠漏是什么| 肾阳虚吃什么| 淀粉和面粉有什么区别| 什么是幼小衔接| 湖北人喜欢吃什么菜| 什么是烤瓷牙| gg是什么品牌| 骨化是什么意思| 精液是什么形成的| 肾阴虚吃什么食物补| 小儿肠胃炎吃什么药| 法令纹深是什么原因| 理性是什么意思| 中筋面粉是什么粉| 心率90左右意味着什么| 阴虚内热吃什么药好| emoji什么意思| zara是什么意思| 什么是历史虚无主义| 腰果不能和什么一起吃| 土龙是什么鱼| 淋症是什么意思| 右后背疼什么原因| 特异性生长因子指什么| 濒死感是什么感觉| rimowa是什么品牌| 11月29日什么星座| z代表什么| 酋长是什么意思| 人五人六是什么意思| 百度
AdaPower Logged in as Guest
Ada Tools and Resources

Ada 95 Reference Manual
Ada Source Code Treasury
Bindings and Packages
Ada FAQ


Join >
Articles >
Ada FAQ >
Getting Started >
Home >
Books & Tutorials >
Source Treasury >
Packages for Reuse >
Latest Additions >
Ada Projects >
Press Releases >
Ada Audio / Video >
Home Pages >
Links >
Contact >
About >
Login >
Back
What is meant by upcasting/expanding and downcasting/narrowing?

Here is the symmetric case to illustrate upcasting and downcasting.
     type A is tagged ...;   -- one parent type

     type B is tagged ...;   -- another parent type

     ...

     type C;   -- the new type, to be a mixture of A and B

     type AC (Obj : access C'Class) is
       new A
       with ...;
       -- an extension of A to be mixed into C

     type BC (Obj : access C'Class) is
       new B
       with ...;
       -- an extension of B to be mixed into C

     type C is
       tagged limited record
         A : AC (C'Access);
         B : BC (C'Access);
         ... -- other stuff if desired
       end record;
We can now pass an object of type C to anything that takes an A or B as follows (this presumes that Foobar and QBert are primitives of A and B, respectively, so they are inherited; if not, then an explicit conversion (upcast) to A and B could be used to call the original Foobar and QBert).
     XC : C;
   ...
     Foobar (XC.A);
     QBert (XC.B);
If we want to override what Foobar does, then we override Foobar on AC. If we want to override what QBert does, then we override QBert on BC.

Note that there are no naming conflicts, since AC and BC are distinct types, so even if A and B have same-named components or operations, we can talk about them and/or override them individually using AC and BC.

Upcasting (from C to A or C to B) is trivial -- A(XC.A) upcasts to A; B(XC.B) upcasts to B.

Downcasting (narrowing) is also straightforward and safe. Presuming XA of type A'Class, and XB of type B'Class:

     AC(XA).Obj.all downcasts to C'Class (and verifies XA in AC'Class)
     BC(XB).Obj.all downcasts to C'Class (and verifies XB in BC'Class)
You can check before the downcast to avoid a Constraint_Error:
     if XA not in AC'Class then -- appropriate complaint

     if XB not in BC'Class then -- ditto
The approach is slightly simpler (though less symmetric) if we choose to make A the "primary" parent and B a "secondary" parent:
     type A is ...
     type B is ...

     type C;

     type BC (Obj : access C'Class) is
       new B
       with ...

     type C is
       new A
       with record
         B : BC (C'Access);
         ... -- other stuff if desired
       end record;
Now C is a "normal" extension of A, and upcasting from C to A and (checked) downcasting from C'Class to A (or A'Class) is done with simple type conversions. The relationship between C and B is as above in the symmetric approach.

Not surprisingly, using building blocks is more work than using a "builtin" approach for simple cases that happen to match the builtin approach, but having building blocks does ultimately mean more flexibility for the programmer -- there are many other structures that are possible in addition to the two illustrated above, using the access discriminant building block.

For example, for mixins, each mixin "flavor" would have an access discriminant already:

     type Window is ...  -- The basic "vanilla" window

     -- Various mixins
     type Win_Mixin_1 (W : access Window'Class) is ...

     type Win_Mixin_2 (W : access Window'Class) is ...

     type Win_Mixin_3 (W : access Window'Class) is ...
Given the above vanilla window, plus any number of window mixins, one can construct a desired window by including as many mixins as wanted:
     type My_Window is
       new Window
       with record
         M1 : Win_Mixin_1 (My_Window'access);
         M3 : Win_Mixin_3 (My_Window'access);
         M11 : Win_Mixin_1(My_Window'access);
         ... -- plus additional stuff, as desired.
       end record;
As illustrated above, you can incorporate the same "mixin" multiple times, with no naming conflicts. Every mixin can get access to the enclosing object. Operations of individual mixins can be overridden by creating an extension of the mixin first, overriding the operation in that, and then incorporating that tweaked mixin into the ultimate window.

I hope the above helps better illustrate the use and flexibility of the Ada 95 type composition building blocks.

(Tucker Taft)


(c) 1998-2004 All Rights Reserved David Botton

螳螂吃什么 12月14号是什么星座 白带多用什么药效果好 城投公司是干什么的 精神出轨什么意思
多吃蔬菜对身体有什么好处 皮夹克是什么意思 言字旁与什么有关 常德有什么大学 皮肤越抓越痒是什么原因
打蛋白针有什么作用 祖宗是什么意思 糖尿病吃什么 什么驱蚊效果最好 为什么会有结石
胸闷气短可能是什么病 猴头菇和什么煲汤最好 喝柠檬水有什么作用与功效 便秘吃什么药见效快 额头上长痘是因为什么
狗狗的鼻子为什么是湿的hcv9jop1ns9r.cn 金字旁的字与什么有关hcv7jop9ns4r.cn 胆结石不能吃什么hcv8jop6ns6r.cn 就是什么意思hcv9jop0ns6r.cn 屈光不正是什么hcv7jop5ns3r.cn
韩国买什么东西划算hcv8jop0ns6r.cn 712什么星座hcv9jop3ns7r.cn 84年属于什么生肖shenchushe.com 安哥拉树皮有什么功效hcv9jop4ns7r.cn kimi什么意思hcv7jop4ns5r.cn
七月22号是什么星座hcv8jop8ns9r.cn 什么叫撤退性出血hcv8jop2ns1r.cn 170是什么码hcv9jop1ns8r.cn 经络是什么hcv9jop6ns1r.cn 幼儿园中班学什么hcv7jop5ns2r.cn
什么是生僻字hcv9jop1ns4r.cn 尿道感染是什么原因hcv9jop0ns3r.cn 压榨是什么意思hcv9jop5ns3r.cn 阴虚火旺吃什么中成药hcv9jop5ns1r.cn 异想天开什么意思hcv8jop4ns0r.cn
百度