Seminar in Database Systems
Seminar in Database Systems CMPS 280
Popular in Course
Popular in ComputerScienence
This 7 page Class Notes was uploaded by Dr. Elyssa Ratke on Monday September 7, 2015. The Class Notes belongs to CMPS 280 at University of California - Santa Cruz taught by Staff in Fall. Since its upload, it has received 25 views. For similar materials see /class/182256/cmps-280-university-of-california-santa-cruz in ComputerScienence at University of California - Santa Cruz.
Reviews for Seminar in Database Systems
Report this Material
What is Karma?
Karma is the currency of StudySoup.
Date Created: 09/07/15
Kim Bruce Williams College n leave at U ofCai jmla at Santa Cruz Luca Cardelli quotIf there is no 39self in a language then it is not objectorientedquot public class Squares private Framedkeci cute1 musr publ Willghan fd can 9 an 0 mow inr 17 int d7 on r v dx Lumenmovragr5lyl purnie void moveT0 ini y cinemavery er H Objects encapsulate state amp methods Subtyping Inheritance Selfreference Provides dynamic method invocation with more power Are objects more than records with function components What provides real power How can semantics and type theory help Focus on classbased OO languages like Smalltalk Eiffel amp Java Multimethod languages are quite different ass v39 k s FramedReet outer inner 12 lri lrore l Of inquot Jul IE nlll39 class Sqiia wai 1 FramedRect outer inner public SquaresLocation upleft int size DrawingCanvas canvas public void moveint dx int dy outer movedx dy inner movex dy public void uoveToint x int y I this movex outergetX outergety Squares fst new Squarescorner 10 canvas Squares snd new Squares middle 40 canvas II abjed s are references fstmoveTo2030 snd fst II snd amp t refer ta same abject sndmove3050 0 Classes serve many roles Types Generators of new objects Extensible to form new generators public void moveint dx outermovedxdy innermovedxdy public void moveToint x int y thismovex outergetx y outergety First naive view afabjects new Squares u this auter II na mentian afthis inner X move fundxdy thisautermave0 maveTa funxy thismave De nes mutually recursive methods public class ovalSquares extends Squares private Framedoval center public ovalSquaresLocation upleft int size DrawingCanvas canvas superupleft size canvas center new FramedOval lic void moveint dx int dy supermovedx dy 01d move centernovedx dy gt What happens to moveTo S cquot it c U539 lll 1lly u 0 Meaning of this is not bound in classes Semantics of moveTo changes indirectly in Sq new Squares 39 39 39 Ovalsquares sq 1 this SQthis 0 class Squares A this SQthis 0 egg new ovalsquares 0 class OvalSquares A this OSQthlS osq J this39 OSQthis39 meaning ofthis changed where OSQ extends SQ where super SQthis39 uses new tth39 in body 0 Objects formed as xed paints of SQ and OSQ 0 T lt U i any object of type T can extruding Ield masquerade as object of type U 0 More formally subsumptian rule bread BreadTp lling CheeseTp sauce SauceTp lt Recards withmn eld update anly operatian is f 39 s lling T lt U amp o T gt 0 U bread BreadType lling FoodType 0 Java Interfaces amp extension m CheeseTp lt FoodType l a lffS gtTand sSthen fsT 11 12 13 T1 T2 T3 WhenisS gt T ltS gt T l1T2isinltiliTiigigk If f S gtT and 55 need f s T I k S n and far all S i S k T ltT sT S gtT ltS gtT I S lt S and T ltT Contravariantfar parameter types avariantfar result types l 9 0 Java 4 doesn t allow any changes to types of methods in subclass 0 C ampJava 5 allow covariant changes to return types 0 Suppose you don t care if subclass gives a subtype Do you still need restrictions In Smalltalk subclass and subtype hierarchies sometimes reverse 0 Method type in subclass must be subtype of method type in superclass for safety Covariant change allowed in return type Conti avariant change in parameter type ObiTyPe m T i lt ObiTyPe m T i W k S n and for all S i S k T ltT assuming methods not updatable at runtime Method parameters can vary contravariantly return types covariantly class Example void m thisns T nS x class SubExample extends Example T39 nS39 x void newMeth i What is relationship of new type of n to old if want type safety 0 Methods must be meaningful in all possible subclasses classiImM VM lt MVIR lt I efn i x Nthis R x IR 39 M mii metb ads new Squares auter ref inner ref X Wm IrefJJ 39 M Minst I efn mave fundxdy instauter maveTa funxy ltinstfmgt mave Methad suite can be shared between objects ofsame type is 0 Fixed paints are key to understanding OO languages 0 Classes are extensible generators of xed points 0 Subtyping explains restrictions on subclasses Even though subtypng distinct concept 0 De ning this in Classi l m M this IRY X lR 39 M39 where M39 lt M IRY lt Iref 0 When return this hide instance variables this EIXX x x M ObjM39 but notice ObjM39 lt ObjM thus this ObjM where ObjM is type of objects of the class being de ned 19 Obj P 1 fWDPCH where obj ifm In objects methods fixed parameterized by suite of instance variables not this classiImM VM lt M VIR lt I efn i x AthisIR gtlt IR M m How do we type function returning this 0 But now we have lost information 0 If C has method m with body return this then C m0 0 If D extends Cthen inherited in still has type C m0 0 But dm0 really returns value of type D Binary Methods public class Node protected Tm ThiSCIass is type ofuthisu public Nodemuselass next thlsnext next 0 In previous example declare public void setNextmns Lisr newNeKt m v ThisClass this ext K 0 Also examples with parameters of type public Tm 2 ThisClass called binary methods return ext Subclasses There are type safety problems De ne publlc class DbleNode extends Node l l d l ass 7 0 EC 6 US 1 prev publlc vold breakItNode nl Node n2 n1 setNextn2 next Tlll ilssz prev pm V 1d 5mm lg mm l Let n be a Node and dn be a DbleNode super setuext newNext newNextsetPrevthls7 breakItdn 11 public In setprevmue r newPrev thmm newt Blows up when dn setNext n is execmad Need to rule out this code using type system Rewrite Node and DbIeNode to replace all occurrences ofThisClass by ThisClass can 39 IY send binary message to Obiea if public void breakltmNode nl Node n2 know Its exact type quot1 setNextn2 0 If obj has type T then value of obj has typeT but not a subtype More generally w type parameters could write public ltN extends Nodegt void breakItU N nl an n2 n1setNextn2 0 ThisClass is type of this 0 In semantics 39 Node JThisClassNdThisClass 39 DbleNode uThisClass39DbNdThisClass39 0 Thus ThisClass NdThIsCInss Node ThisClass39 DbNdThIsClnss DoubleNode 7 0 Veri cation can bene t from similar assumptions on this and ThisClass 0 Alternative Verify under closedworld assumption and copy inherited methods down Compositional approach is better SubjObsGrp ClassGroup class MySubect void addObserVerMyObserver myObs void notifyObservers procMyEvent myEvt class MyObserVer void notifyMySubec mySUb MyEvent myEvt class MyEvent 0 Wish to typecheck modularly no repeated typechecking of inherited methods 0 Typecheck methods of class C under assumptions that hold in all extensions this ThisClass ThisClass extends C Can prove soundness of type system a 0 Gets much more interesting when Allow type parameters eg GJ lntroduceThisType as interface of this LOO extension of G java 5 Allow mutually recursiveThisClasses in class Allows types and classes to be re ned simultaneously in typesafe fashion ChoiceSubObsGrp ClassGroup extends SubjObsGrp class extends MySubect String getltemo class extends MyEvenr String getltemo class extends MyObsel39ver void notifyMySubjen mySUb MyEvent myEvt myEvtgetltem