{"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 …