Object-oriented concepts

William S. Davis
{"title":"Object-oriented concepts","authors":"William S. Davis","doi":"10.1201/9781420049107.CH6","DOIUrl":null,"url":null,"abstract":"See Mitchell Chapter 10 for content covered in the first part of lecture. An electronic copy of the textbook is available through the Harvard Library website. See the course web page for details. 1 Object encodings We've just informally described object-oriented concepts. How do these concepts relate to language features and mechanisms that we have already examined during this course? 1.1 Records Records provide both dynamic lookup and subtyping. For dynamic lookup, given value v of record type, the expression v.l will evaluate to a value determined by v, not by the record type. If v.l is a function, then this is like dynamic dispatch: the code to invoke depends on the object v. Moreover, we defined subtyping on record types, which permits both reuse and extension: code that expects a value of type τ can be re-used with a value of any subtype of τ ; new subtypes can be created, allowing code to be extended. Recursive records allow us to express records that can perform functional updates. For example, consider a representation of a 2 dimensional point, which has a method to move the point in one dimension. In this example, we use a recursive function new to construct a record value. The record contains fields x and y, which record the point's coordinates, and a method mvx, which takes a number d as input, and returns a point that is d units to the right of the original point. In order to construct the new point, the method mvx calls the function new, and gives it the original x coordinate plus d, and the original y coordinate. To access the original coordinates, the method mvx must access the fields x and y of the record of which it is a field; we achieve this by using a fix point operator on the record, with the variable name this being used to refer (recursively) to the record. Existential types can be used to enforce abstraction and information hiding. We saw this last lecture, when we considered a simple module mechanism based on existential types, which allowed the module to export an interface that abstracted the implementation details. It is possible to combine recursive records and existential types: see \" Comparing Object Encodings \" , by Bruce, Cardelli, and Pierce, Information and Computation 155(1/2):108–133, 1999. However, rather than encoding objects on top of the lambda calculus, it is possible …","PeriodicalId":243054,"journal":{"name":"The Information System Consultant’s Handbook","volume":"16 1","pages":"0"},"PeriodicalIF":0.0000,"publicationDate":"1998-12-28","publicationTypes":"Journal Article","fieldsOfStudy":null,"isOpenAccess":false,"openAccessPdf":"","citationCount":"2","resultStr":null,"platform":"Semanticscholar","paperid":null,"PeriodicalName":"The Information System Consultant’s Handbook","FirstCategoryId":"1085","ListUrlMain":"https://doi.org/10.1201/9781420049107.CH6","RegionNum":0,"RegionCategory":null,"ArticlePicture":[],"TitleCN":null,"AbstractTextCN":null,"PMCID":null,"EPubDate":"","PubModel":"","JCR":"","JCRName":"","Score":null,"Total":0}
引用次数: 2

Abstract

See Mitchell Chapter 10 for content covered in the first part of lecture. An electronic copy of the textbook is available through the Harvard Library website. See the course web page for details. 1 Object encodings We've just informally described object-oriented concepts. How do these concepts relate to language features and mechanisms that we have already examined during this course? 1.1 Records Records provide both dynamic lookup and subtyping. For dynamic lookup, given value v of record type, the expression v.l will evaluate to a value determined by v, not by the record type. If v.l is a function, then this is like dynamic dispatch: the code to invoke depends on the object v. Moreover, we defined subtyping on record types, which permits both reuse and extension: code that expects a value of type τ can be re-used with a value of any subtype of τ ; new subtypes can be created, allowing code to be extended. Recursive records allow us to express records that can perform functional updates. For example, consider a representation of a 2 dimensional point, which has a method to move the point in one dimension. In this example, we use a recursive function new to construct a record value. The record contains fields x and y, which record the point's coordinates, and a method mvx, which takes a number d as input, and returns a point that is d units to the right of the original point. In order to construct the new point, the method mvx calls the function new, and gives it the original x coordinate plus d, and the original y coordinate. To access the original coordinates, the method mvx must access the fields x and y of the record of which it is a field; we achieve this by using a fix point operator on the record, with the variable name this being used to refer (recursively) to the record. Existential types can be used to enforce abstraction and information hiding. We saw this last lecture, when we considered a simple module mechanism based on existential types, which allowed the module to export an interface that abstracted the implementation details. It is possible to combine recursive records and existential types: see " Comparing Object Encodings " , by Bruce, Cardelli, and Pierce, Information and Computation 155(1/2):108–133, 1999. However, rather than encoding objects on top of the lambda calculus, it is possible …
面向对象的概念
请参阅Mitchell第10章,了解讲座第一部分所涵盖的内容。这本教科书的电子版可以在哈佛图书馆的网站上找到。详见课程网页。我们刚刚非正式地描述了面向对象的概念。这些概念是如何与我们在本课程中已经研究过的语言特性和机制联系起来的?1.1记录记录提供动态查找和子类型。对于动态查找,给定记录类型的值v,表达式v.l将计算为由v决定的值,而不是由记录类型决定的值。如果v.l是一个函数,那么这就像动态调度:调用的代码取决于对象v.此外,我们在记录类型上定义了子类型,这允许重用和扩展:期望类型值为τ的代码可以与τ的任何子类型的值一起重用;可以创建新的子类型,从而扩展代码。递归记录允许我们表达可以执行功能更新的记录。例如,考虑一个二维点的表示,它具有在一维中移动该点的方法。在本例中,我们使用递归函数new来构造一个记录值。该记录包含字段x和y,它们记录了点的坐标,以及一个方法mvx,该方法接受数字d作为输入,并返回在原始点右侧d个单位的点。为了构造新的点,方法mvx调用函数new,并给它原始的x坐标加上d,以及原始的y坐标。要访问原始坐标,方法mvx必须访问其为字段的记录的字段x和y;我们通过在记录上使用定点操作符来实现这一点,变量名this用于(递归地)引用记录。存在类型可用于强制抽象和信息隐藏。在上一讲中,我们考虑了基于存在类型的简单模块机制,该机制允许模块导出抽象实现细节的接口。可以将递归记录和存在类型结合起来:参见Bruce, Cardelli和Pierce的“比较对象编码”,信息与计算155(1/2):108-133,1999。然而,与其在lambda演算上编码对象,还不如…
本文章由计算机程序翻译,如有差异,请以英文原文为准。
求助全文
约1分钟内获得全文 求助全文
来源期刊
自引率
0.00%
发文量
0
×
引用
GB/T 7714-2015
复制
MLA
复制
APA
复制
导出至
BibTeX EndNote RefMan NoteFirst NoteExpress
×
提示
您的信息不完整,为了账户安全,请先补充。
现在去补充
×
提示
您因"违规操作"
具体请查看互助需知
我知道了
×
提示
确定
请完成安全验证×
copy
已复制链接
快去分享给好友吧!
我知道了
右上角分享
点击右上角分享
0
联系我们:info@booksci.cn Book学术提供免费学术资源搜索服务,方便国内外学者检索中英文文献。致力于提供最便捷和优质的服务体验。 Copyright © 2023 布克学术 All rights reserved.
京ICP备2023020795号-1
ghs 京公网安备 11010802042870号
Book学术文献互助
Book学术文献互助群
群 号:481959085
Book学术官方微信