Recap. What is a type? Types in OO languages. What is a type? Types as sets. Up next, some advanced OO topics
|
|
- Stuart Henry
- 5 years ago
- Views:
Transcription
1 Recap Recap from last time And continuation of decorators See code Up next, some advanced OO topics Today: Typing of object oriented languages Next time: Multi-methods What is a type? Types in OO languages What is a type? A description of an object: the fields it contains and the methods it contains that is to say: the attributes it contains (where for now we assume an attribute includes the type of the attribute) Types as sets One way to interpret types is as sets A type corresponds to the set of objects that are described by the type In other words, a description of the actions that one can successfully perform on an object 1
2 Example The following type: interface Point { void screensaver(point [] p) { Corresponds to: set of objects having attributes getx, gety, move, jump, draw The object may have many other attributes! Compiler checks that screensaver only uses attributes of Point that are known to be there. Clients of screensaver So what objects can be passed in to screensaver? Intuitively, any object that has the given attributes should be ok. If the object has more attributes, no problem This intuitive notion is captured by the concept of subtyping Subtyping Subtyping A type T 1 is a subtype of type T 2, written T 1 <: T 2 if wherever an object of type T 2 can be used, so can an object of type T 1 Consequence: if T 1 <: T 2, then wherever an object of type T 2 is required, you can safely pass in an object of type T 1 When can we say that T 1 <: T 2? When an object of type T 1 has all the attributes that an object of type T 2 has Subtyping with types-as-sets If: 1. T 1 <: T 2 2. objs(t 1 ) is the set of objects of type T 1 3. objs(t 2 ) is the set of objects of type T 2 then how are objs(t 1 ) and objs(t 2 ) related? Subtyping with types-as-sets If: 1. T 1 <: T 2 2. objs(t 1 ) is the set of objects of type T 1 3. objs(t 2 ) is the set of objects of type T 2 then how are objs(t 1 ) and objs(t 2 ) related? A: obs(t 1 ) objs(t 2 ) T 1 T 2 2
3 Example of subtyping Example of subtyping Recall: interface Point { interface ColorPoint { void setcolor(color c) Color getcolor() interface TextPoint { void settext(string s) string gettext() Example of subtyping Another example objects Point void foo(triangle t) ColorPoint TextPoint Do we have ColorTriangle <: Triangle? Is it the case that wherever a Triangle is expected, it is safe to pass in a ColorTriangle? It it safe to pass ColorTriangle to foo? Another example Another example void foo(triangle t) void foo(triangle t) Safe to pass ColorTriangle to foo? Say foo only reads fields of t Then it s safe Safe to pass ColorTriangle to foo? Say foo only reads fields of t Then it s safe What if foo writes fields of t? 3
4 Let s model this with methods Let s model this with methods void set_p1(point p1); void set_p1(colorpoint p1); void foo(triangle t) { t.set_p1(new Point(0,0)); Does anybody see the problem? void set_p1(point p1); void set_p1(colorpoint p1); void foo(triangle t) { t.set_p1(new Point(0,0)); Does anybody see the problem? If ColorTriangle is passed in to foo(), then ColorTriangle.set_p1() is called with a Point as an argument. Now what happens if ColorTriangle.set_p1() accesses p1.color? Runtime error! So what s the rule then? So what s the rule then? void m(b c); void m(d d); void m(b c); void m(d d); We ve seen the answer is not D <: B Answer: B <: D Method params are contravariant subtyping relation between method parameters opposite of relation between classes What about return values? What about return values? B m(); D m(); B m(); D m(); Answer: D <: B Method return values are covariant subtyping relation in the same order as subtypting relation between the classes 4
5 Let s go back to fields void foo(triangle t) { t.p1 := new Point() t := new ColorTriagle(); foo(t); t.p1.color // yikes! What about Java Why does this not happen in Java? Read only fields are covariant Write-only field are contravariant Read/write fields invariant same type in subtype and supertype What about Java Why does this not happen in Java? Because Java has overloading: the name of a method includes its types, so all these methods in Java would actually be distinct. Arrays in Java Actually, that s not true! The covariance, contravariance issues does affect Java too! Array subtyping: Point [] and ColoredPoint [] interface Point [] { void set(int idx, Point val); Point get(int idx); if ColoredPoint [] <: Point [] then: interface ColoredPoint[] { void set(int idx, ColoredPoint val); ColoredPoint get(int idx); ColoredPoint [] x = new ColoredPoint [10]; Point [] y = x; y.set(0, new Point(10,10)); // Yikes! Arrays in Java Actually, that s not true! The covariance, contravariance issues does affect Java too! Array subtyping: Point [] and ColoredPoint [] interface Point [] { void set(int idx, Point val); Point get(int idx); if ColoredPoint [] <: Point [] then: ColoredPoint [] x = new ColoredPoint [10]; Point [] y = x; y.set(0, new Point(10,10)); // Yikes! interface ColoredPoint[] { void set(int idx, ColoredPoint val); ColoredPoint get(int idx); Conclusion: it is not the case that ColoredPoint[] <: Point [] But Java does consider ColoredPoint [] to be a subtype of Point[]. What gives? Runtime checks are inserted to detect errors at runtime! ColoredPoint [] x = new ColoredPoint[10]; Point [] y = x; y[0] := new Point(0,0); ColoredPoint z = x[0]; z.color; // yikes! runtime exception! 5
6 Recap So we ve seen a definition of when one interface subtypes another. This definition depends on looking at the attributes of the interfaces, and figuring out if they match. But in Java So we ve seen a definition of when one interface subtypes another. This definition depends on looking at the attributes of the interfaces, and figuring out if they match. But how does one really figure out in Java if an interface subtypes another? But in Java So we ve seen a definition of when one interface subtypes another. This definition depends on looking at the attributes of the interfaces, and figuring out if they match. But how does one really figure out in Java if an interface subtypes another? Look at the subclass relationship! Structural vs. nominal subtyping What we ve seen until now: structural subtyping the subtyping relation is determined based on the structure of the types (ie: the attributes in the interfaces) similar to duck typing in Python (although Python is dynamic) Nominal subtyping (by name subtyping): the subtyping relation is given by the programmer Next time: multimethods! 6
What is a type? Types in OO languages. What is a type? Types as sets. Example. Clients of screensaver
What is a type? Types in OO languages What is a type? A description of an object: the fields it contains and the methods it contains that is to say: the attributes it contains (where for now we assume
More informationQuiz. Programming Languages. CSE 130 : Fall Lecture 16: Static Types for Objects. Ranjit Jhala UC San Diego
CSE 130 : Fall 2008 Programming Languages Quiz Lecture 16: Static ti Types for Objects Ranjit Jhala UC San Diego Last time Tricks with namespaces: decorators Today Inheritance Static Types for Objects
More informationWeek 7. Statically-typed OO languages: C++ Closer look at subtyping
C++ & Subtyping Week 7 Statically-typed OO languages: C++ Closer look at subtyping Why talk about C++? C++ is an OO extension of C Efficiency and flexibility from C OO program organization from Simula
More informationObject typing and subtypes
CS 242 2012 Object typing and subtypes Reading Chapter 10, section 10.2.3 Chapter 11, sections 11.3.2 and 11.7 Chapter 12, section 12.4 Chapter 13, section 13.3 Subtyping and Inheritance Interface The
More informationSubtyping. Lecture 13 CS 565 3/27/06
Subtyping Lecture 13 CS 565 3/27/06 Polymorphism Different varieties of polymorphism: Parametric (ML) type variables are abstract, and used to encode the fact that the same term can be used in many different
More informationLecture Outline. Parametric Polymorphism and Java Generics. Polymorphism. Polymorphism
Lecture Outline Parametric Polymorphism and Java Generics Parametric polymorphism Java generics Declaring and instantiating generics Bounded types: restricting instantiations Generics and subtyping. Wildcards
More informationExercise 3 Subtyping and Behavioral Subtyping October 13, 2017
Concepts of Object-Oriented Programming AS 2017 Exercise 3 Subtyping and Behavioral Subtyping October 13, 2017 Task 1 In this question, we are in a nominal subtyping setting. Some languages have a special
More informationConformance. Object-Oriented Programming Spring 2015
Conformance Object-Oriented Programming 236703 Spring 2015 1 What s Conformance? Overriding: replace method body in sub-class Polymorphism: subclass is usable wherever superclass is usable Dynamic Binding:
More informationCS-XXX: Graduate Programming Languages. Lecture 23 Types for OOP; Static Overloading and Multimethods. Dan Grossman 2012
CS-XXX: Graduate Programming Languages Lecture 23 Types for OOP; Static Overloading and Multimethods Dan Grossman 2012 So far... Last lecture (among other things): The difference between OOP and records
More informationAnnouncements. Lecture 14 Generics 1. Announcements. CSE 331 Software Design and Implementation. Leah Perlmutter / Summer 2018
CSE 331 Software Design and Implementation Lecture 14 Generics 1 Announcements Leah Perlmutter / Summer 2018 Announcements Quiz 5 is due Thursday Homework 6 due Thursday Midterm grades and feedback will
More informationCSE 331 Software Design and Implementation. Lecture 14 Generics 1
CSE 331 Software Design and Implementation Lecture 14 Generics 1 Leah Perlmutter / Summer 2018 Announcements Announcements Quiz 5 is due Thursday Homework 6 due Thursday Midterm grades and feedback will
More informationLecture 13: Subtyping
Lecture 13: Subtyping Polyvios Pratikakis Computer Science Department, University of Crete Type Systems and Programming Languages Pratikakis (CSD) Subtyping CS546, 2018-2019 1 / 15 Subtyping Usually found
More informationAdvanced oo concepts Specialization of behaviour? Multiple inheritance - alternatives to. Inner classes Classes
Types and Classes I II From predefined (simple) and user-defined (composite) types via Abstract data types Advanced oo concepts Specialization of behaviour? Multiple inheritance - alternatives to Inner
More informationProgramming Languages and Techniques (CIS120)
Programming Languages and Techniques (CIS120) Lecture 22 March 14, 2018 Static Methods, Java Arrays Chapters 20 & 21 Announcements HW6: Java Programming (Pennstagram) Due: Tuesday the 20 th at 11:59pm
More informationProgramming Languages and Techniques (CIS120)
Programming Languages and Techniques (CIS120) Lecture 24 March 24, 2014 Java ASM Interfaces and Subtyping Announcements HW 07 due tomorrow at midnight Exam 2, in class, a week from Friday (April 4th) The
More informationCSE 331 Software Design and Implementation. Lecture 14 Generics 2
CSE 331 Software Design and Implementation Lecture 14 Generics 2 Zach Tatlock / Spring 2018 Big picture Last time: Generics intro Subtyping and Generics Using bounds for more flexible subtyping Using wildcards
More informationCSE341, Fall 2011, Lecture 26 Summary
CSE341, Fall 2011, Lecture 26 Summary Standard Disclaimer: This lecture summary is not necessarily a complete substitute for attending class, reading the associated code, etc. It is designed to be a useful
More informationCSE 331 Software Design and Implementation. Lecture 14 Generics 2
CSE 331 Software Design and Implementation Lecture 14 Generics 2 James Wilcox / Winter 2016 Hi, I m James! Big picture Last time: Generics intro Subtyping and Generics Using bounds for more flexible subtyping
More informationCS153: Compilers Lecture 11: Compiling Objects
CS153: Compilers Lecture 11: Compiling Objects Stephen Chong https://www.seas.harvard.edu/courses/cs153 Announcements Project 3 due today Project 4 out Due Thursday Oct 25 (16 days) Project 5 released
More informationExercise 8 Parametric polymorphism November 17, 2017
Concepts of Object-Oriented Programming AS 2017 Exercise 8 Parametric polymorphism November 17, 2017 Task 1 Implement a list in Java or C# with two methods: public void add(int i, Object el) public Object
More informationProgramming Languages and Techniques (CIS120)
Programming Languages and Techniques (CIS120) Lecture 24 October 29, 2018 Arrays, Java ASM Chapter 21 and 22 Announcements HW6: Java Programming (Pennstagram) Due TOMORROW at 11:59pm Reminder: please complete
More informationDerived and abstract data types. TDT4205 Lecture 15
1 Derived and abstract data types TDT4205 Lecture 15 2 Where we were We ve looked at static semantics for primitive types and how it relates to type checking We ve hinted at derived types using a multidimensional
More informationCS 565: Programming Languages. Spring 2008 Tu, Th: 16:30-17:45 Room LWSN 1106
CS 565: Programming Languages Spring 2008 Tu, Th: 16:30-17:45 Room LWSN 1106 Administrivia Who am I? Course web page http://www.cs.purdue.edu/homes/peugster/cs565spring08/ Office hours By appointment Main
More informationTypes. Type checking. Why Do We Need Type Systems? Types and Operations. What is a type? Consensus
Types Type checking What is a type? The notion varies from language to language Consensus A set of values A set of operations on those values Classes are one instantiation of the modern notion of type
More informationObject Oriented Programming: Based on slides from Skrien Chapter 2
Object Oriented Programming: A Review Based on slides from Skrien Chapter 2 Object-Oriented Programming (OOP) Solution expressed as a set of communicating objects An object encapsulates the behavior and
More informationCS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 17: Types and Type-Checking 25 Feb 08
CS412/CS413 Introduction to Compilers Tim Teitelbaum Lecture 17: Types and Type-Checking 25 Feb 08 CS 412/413 Spring 2008 Introduction to Compilers 1 What Are Types? Types describe the values possibly
More informationCS 320 Introduction to Software Engineering Spring 2017
Recap: Are UML diagrams useful? CS 320 Introduction to Software Engineering Spring 2017 March 01, 2017 Communication Forward design (before coding) brainstorm ideas (on whiteboard or paper) draft and iterate
More informationRushikesh K Joshi. Department of Computer Science and Engineering Indian Institute of Technology Bombay
CS 617 Object Oriented Systems Lecture 9 Polymorphism: Mere Syntactic Vs. Dynamic Binding,, Subsumption Covariance, Contravariance 3:30-5:00 pm Thu, Jan 31 Rushikesh K Joshi Department of Computer Science
More informationCS558 Programming Languages Winter 2013 Lecture 8
OBJECT-ORIENTED PROGRAMMING CS558 Programming Languages Winter 2013 Lecture 8 Object-oriented programs are structured in terms of objects: collections of variables ( fields ) and functions ( methods ).
More informationCSE Lecture 3: Objects 2 September Nate Nystrom University of Texas at Arlington
CSE 3302 Lecture 3: Objects 2 September 2010 Nate Nystrom University of Texas at Arlington Administration Out of town this afternoon thru Monday HW1 due next Thursday 9/9 Types Last time: strongly typed
More informationProgramming Languages and Techniques (CIS120)
Programming Languages and Techniques (CIS120) Lecture 21 March 12, 2018 Java: Objects, Interfaces, Static Members Chapters 19 & 20 Announcements Java Bootcamp Tonight!! Towne 100, 6-8 pm HW06: Pennstagram
More informationImplementing objects as in Javascript, Lua, 164 is expensive because object attributes are implemented as hashtable accesses:
Lectures Page 1 L18 Monday, November 23, 2009 10:22 PM Implementing objects as in Javascript, Lua, 164 is expensive because object attributes are implemented as hashtable accesses: x = { f=1 } x.f -->
More informationOfficial Survey. Cunning Plan: Focus On Objects. The Need for a Calculus. Object Calculi Summary. Why Not Use λ-calculus for OO?
Modeling and Understanding Object-Oriented Oriented Programming Official Survey Please fill out the Toolkit course survey 40142 CS 655-1 Apr-21-2006 Midnight May-04-2006 9am Why not do it this evening?
More informationObjects, Subclassing, Subtyping, and Inheritance
Objects, Subclassing, Subtyping, and Inheritance Brigitte Pientka School of Computer Science McGill University Montreal, Canada In these notes we will examine four basic concepts which play an important
More informationHarvard School of Engineering and Applied Sciences CS 152: Programming Languages
Harvard School of Engineering and Applied Sciences CS 152: Programming Languages Lecture 14 Tuesday, March 24, 2015 1 Parametric polymorphism Polymorph means many forms. Polymorphism is the ability of
More informationParametric polymorphism and Generics
Parametric polymorphism and Generics Today s Lecture Outline Parametric polymorphism Java generics Declaring and instantiating generics Bounded types: restricting instantiations Generics and subtyping.
More informationWhat s Conformance? Conformance. Conformance and Class Invariants Question: Conformance and Overriding
Conformance Conformance and Class Invariants Same or Better Principle Access Conformance Contract Conformance Signature Conformance Co-, Contra- and No-Variance Overloading and Overriding Inheritance as
More informationA Type is a Set of Values. Here we declare n to be a variable of type int; what we mean, n can take on any value from the set of all integer values.
Types A Type is a Set of Values Consider the statement: Read Chapter 6 int n; Here we declare n to be a variable of type int; what we mean, n can take on any value from the set of all integer values. Also
More informationTypes and Classes. I II From predefined (simple) and user-defined (composite) types via Abstract data types
Types and Classes I II From predefined (simple) and user-defined (composite) types via Abstract data types to Classes Type compatibility Subtyping subclassing Polymorphism revisited Subtype polymorphism
More informationRecords. ADTs. Objects as Records. Objects as ADTs. Objects CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 15: Objects 25 Feb 05
Records CS412/CS413 Introduction to Compilers Tim Teitelbaum Lecture 15: Objects 25 Feb 05 Objects combine features of records and abstract data types Records = aggregate data structures Combine several
More informationName: CIS 341 Final Examination 10 December 2008
Name: CIS 341 Final Examination 10 December 2008 1 /8 2 /12 3 /18 4 /18 5 /14 Total /70 Do not begin the exam until you are told to do so. You have 120 minutes to complete the exam. There are 11 pages
More informationINF 212/CS 253 Type Systems. Instructors: Harry Xu Crista Lopes
INF 212/CS 253 Type Systems Instructors: Harry Xu Crista Lopes What is a Data Type? A type is a collection of computational entities that share some common property Programming languages are designed to
More informationPart III Chapter 15: Subtyping
Part III Chapter 15: Subtyping Subsumption Subtype relation Properties of subtyping and typing Subtyping and other features Intersection and union types Subtyping Motivation With the usual typing rule
More informationCS152: Programming Languages. Lecture 23 Advanced Concepts in Object-Oriented Programming. Dan Grossman Spring 2011
CS152: Programming Languages Lecture 23 Advanced Concepts in Object-Oriented Programming Dan Grossman Spring 2011 So far... The difference between OOP and records of functions with shared private state
More informationPart III. Chapter 15: Subtyping
Part III Chapter 15: Subtyping Subsumption Subtype relation Properties of subtyping and typing Subtyping and other features Intersection and union types Subtyping Motivation With the usual typing rule
More informationSubtyping (Dynamic Polymorphism)
Fall 2018 Subtyping (Dynamic Polymorphism) Yu Zhang Course web site: http://staff.ustc.edu.cn/~yuzhang/tpl References PFPL - Chapter 24 Structural Subtyping - Chapter 27 Inheritance TAPL (pdf) - Chapter
More informationC++ Part 2 <: <: C++ Run-Time Representation. Smalltalk vs. C++ Dynamic Dispatch. Smalltalk vs. C++ Dynamic Dispatch
C++ Run-Time Representation Point object Point vtable Code for move C++ Part x y CSCI 4 Stephen Freund ColorPoint object x 4 y 5 c red ColorPoint vtable Code for move Code for darken Data at same offset
More informationG Programming Languages - Fall 2012
G22.2110-003 Programming Languages - Fall 2012 Lecture 12 Thomas Wies New York University Review Last lecture Modules Outline Classes Encapsulation and Inheritance Initialization and Finalization Dynamic
More informationC++ Yanyan SHEN. slide 1
C++ Yanyan SHEN slide 1 History C++ is an object-oriented extension of C Designed by Bjarne Stroustrup at Bell Labs His original interest at Bell Labs was research on simulation Early extensions to C are
More informationJam: A Smooth Extension With Java Mixins
Jam: A Smooth Extension With Java Mixins Davide Ancona, Giovanni Lagorio, Ellena Zucca Presentation created by Left-out Jam abstract syntax Formal definitions of Jam static semantics Formal definitions
More informationSystem Analysis and Design. Introduction: Object Oriented Design
System Analysis and Design Introduction: Object Oriented Design Salahaddin University College of Engineering Software Engineering Department 2011-2012 Amanj Sherwany http://www.amanj.me/wiki/doku.php?id=teaching:su:system_analysis_and_design
More informationSome instance messages and methods
Some instance messages and methods x ^x y ^y movedx: dx Dy: dy x
More information21 Subtyping and Parameterized Types
Object-Oriented Design Lecture 21 CS 3500 Spring 2011 (Pucella) Friday, Apr 1, 2011 21 Subtyping and Parameterized Types Given a parameterized type Foo[T], suppose we know that A B (A is a subtype of B),
More informationCSE 331 Software Design and Implementation. Lecture 13 Generics 1
CSE 331 Software Design and Implementation Lecture 13 Generics 1 Zach Tatlock / Spring 2018 Varieties of abstraction Abstraction over computation: procedures (methods) int x1, y1, x2, y2; Math.sqrt(x1*x1
More informationINF 212 ANALYSIS OF PROG. LANGS Type Systems. Instructors: Crista Lopes Copyright Instructors.
INF 212 ANALYSIS OF PROG. LANGS Type Systems Instructors: Crista Lopes Copyright Instructors. What is a Data Type? A type is a collection of computational entities that share some common property Programming
More informationThe Java Programming Language
The Java Programming Language Slide by John Mitchell (http://www.stanford.edu/class/cs242/slides/) Outline Language Overview History and design goals Classes and Inheritance Object features Encapsulation
More informationAnnouncements. Lecture 15 Generics 2. Announcements. Big picture. CSE 331 Software Design and Implementation
CSE 331 Software Design and Implementation Lecture 15 Generics 2 Announcements Leah Perlmutter / Summer 2018 Announcements Quiz 5 is due tomorrow Homework 6 due tomorrow Section tomorrow! Subtyping now
More informationCSE 331 Software Design and Implementation. Lecture 15 Generics 2
CSE 331 Software Design and Implementation Lecture 15 Generics 2 Leah Perlmutter / Summer 2018 Announcements Announcements Quiz 5 is due tomorrow Homework 6 due tomorrow Section tomorrow! Subtyping now
More informationCSE 331 Summer 2017 Final Exam. The exam is closed book and closed electronics. One page of notes is allowed.
Name Solution The exam is closed book and closed electronics. One page of notes is allowed. The exam has 6 regular problems and 1 bonus problem. Only the regular problems will count toward your final exam
More informationSubtyping and Objects
Subtyping and Objects Massimo Merro 20 November 2017 Massimo Merro Data and Mutable Store 1 / 22 Polymorphism So far, our type systems are very rigid: there is little support to code reuse. Polymorphism
More informationKonzepte von Programmiersprachen
Konzepte von Programmiersprachen Chapter 9: Objects and Classes Peter Thiemann Universität Freiburg 9. Juli 2009 Konzepte von Programmiersprachen 1 / 22 Objects state encapsulation (instance vars, fields)
More informationExercise 8 Parametric polymorphism November 18, 2016
Concepts of Object-Oriented Programming AS 2016 Exercise 8 Parametric polymorphism November 18, 2016 Task 1 Consider the following Scala classes: class A class B extends A class P1[+T] class P2[T
More informationDesign issues for objectoriented. languages. Objects-only "pure" language vs mixed. Are subclasses subtypes of the superclass?
Encapsulation Encapsulation grouping of subprograms and the data they manipulate Information hiding abstract data types type definition is hidden from the user variables of the type can be declared variables
More informationObject-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018
Object-oriented programming 1 and data-structures CS/ENGRD 2110 SUMMER 2018 Lecture 4: OO Principles - Polymorphism http://courses.cs.cornell.edu/cs2110/2018su Lecture 3 Recap 2 Good design principles.
More informationSubtyping (cont) Formalization of Subtyping. Lecture 15 CS 565. Inversion of the subtype relation:
Subtyping (cont) Lecture 15 CS 565 Formalization of Subtyping Inversion of the subtype relation:! If "
More informationObject-Oriented Design Lecture 14 CSU 370 Fall 2007 (Pucella) Friday, Nov 2, 2007
Object-Oriented Design Lecture 14 CSU 370 Fall 2007 (Pucella) Friday, Nov 2, 2007 (These notes are very rough, and differ somewhat from what I presented in class; I am posting them here to supplemental
More informationabstract binary class composition diamond Error Exception executable extends friend generic hash implementation implements
CS365 Midterm 1) This exam is open-note, open book. 2) You must answer all of the questions. 3) Answer all the questions on a separate sheet of paper. 4) You must use Java to implement the coding questions.
More informationCSE 331. Generics (Parametric Polymorphism)
CSE 331 Generics (Parametric Polymorphism) slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia http://www.cs.washington.edu/331/ 1 Parametric polymorphism
More informationSDV4001 Object Oriented Programming with C++ and UI Midterm 2013
Name : ID: Group: SDV4001 Object Oriented Programming with C++ and UI Midterm 2013 Marks : 30 Answer all questions. Time: 60 mins Section 1: MCQs (Circle the correct choice clearly) -12 marks (12 x 1)
More informationCSE341: Programming Languages Lecture 25 Subtyping for OOP; Comparing/Combining Generics and Subtyping. Dan Grossman Winter 2013
CSE341: Programming Languages Lecture 25 Subtyping for OOP; Comparing/Combining Generics and Subtyping Dan Grossman Winter 2013 Now Use what we learned about subtyping for records and functions to understand
More informationProgramming Languages and Techniques (CIS120)
Programming Languages and Techniques (CIS120) Lecture 28 March 30, 2016 Collections and Equality Chapter 26 Announcements Dr. Steve Zdancewic is guest lecturing today He teaches CIS 120 in the Fall Midterm
More informationCSE Lecture 7: Polymorphism and generics 16 September Nate Nystrom UTA
CSE 3302 Lecture 7: Polymorphism and generics 16 September 2010 Nate Nystrom UTA 2 Polymorphism poly = many morph = shape Allow a variable to contain values with different types 3 Subtype polymorphism
More informationOutline. Central concepts in OO languages Objects as activation records (Simula) Dynamically-typed object-oriented languages
Objects Outline Central concepts in OO languages Objects as activation records (Simula) Dynamically-typed object-oriented languages Class-based languages (Smalltalk) Prototype-based languages (JavaScript)
More informationObjects. Deian Stefan (Adopted from my & Edward Yang s CS242 slides)
Objects Deian Stefan (Adopted from my & Edward Yang s CS242 slides) Outline Central concepts in OO languages Objects as activation records (Simula) Dynamically-typed object-oriented languages Class-based
More informationCS263: Runtime Systems Lecture: High-level language virtual machines
CS263: Runtime Systems Lecture: High-level language virtual machines Today: A Review of Object-oriented features Chandra Krintz UCSB Computer Science Department Virtual machines (VMs) Terminology Aka managed
More informationThanks! Review. Course Goals. General Themes in this Course. There are many programming languages. Teaching Assistants. John Mitchell.
1 CS 242 Thanks! Review John Mitchell Final Exam Wednesday Dec 8 8:30 11:30 AM Gates B01, B03 Teaching Assistants Mike Cammarano TJ Giuli Hendra Tjahayadi Graders Andrew Adams Kenny Lau Vishal Patel and
More informationCS152: Programming Languages. Lecture 24 Bounded Polymorphism; Classless OOP. Dan Grossman Spring 2011
CS152: Programming Languages Lecture 24 Bounded Polymorphism; Classless OOP Dan Grossman Spring 2011 Revenge of Type Variables Sorted lists in ML (partial): type a slist make : ( a -> a -> int) -> a slist
More informationProgramming Languages and Techniques (CIS120)
Programming Languages and Techniques (CIS120) Lecture 22 March 14 th, 2016 Object Oriented Programming in Java Java Bootcamp tonight Announcements Monday, March 14 from 6-8pm in Levine 101 (Wu & Chen)
More informationSubtypes and Subclasses
Subtypes and Subclasses 6.170 Lecture 14 Fall - ocw.mit.edu Reading: Chapter 7 of Program Development in Java by Barbara Liskov 1 Subtypes We have used closed arrows in module dependence diagrams and object
More informationCS422 - Programming Language Design
1 CS422 - Programming Language Design Elements of Object-Oriented Programming Grigore Roşu Department of Computer Science University of Illinois at Urbana-Champaign 2 During this and the next lecture we
More informationSubtyping: broad definitions. Not Subtyping: type variable instantiation. Mutable Records (half like ML, half like Java/Scala)
Subtyping: broad definitions Not Subtyping: type variable instantiation Job of type system: If a program type-checks, then the program never applies an operation to an incompatible value. New type relation:
More informationCSCI Test 1.Spring 2004 Student Id: Grading: Undergrads, you are responsible for 110 points. Grads: you are responsible for 120 points
1a.Define Programming Language. (3 b. From the point of view of development of software packages, list the kinds of activities that a programming language ought to support. (4 b. List the 3 factors in
More informationOutline. More optimizations for our interpreter. Types for objects
Outline More optimizations for our interpreter Types for objects Optimization Eliminate tree walks: object creation, method calls fish initialize get_ grow eat colorfish color set_color get_color pickyfish
More informationCSE wi Final Exam 3/12/18. Name UW ID#
Name UW ID# There are 13 questions worth a total of 100 points. Please budget your time so you get to all of the questions. Keep your answers brief and to the point. The exam is closed book, closed notes,
More informationFortgeschrittene objektorientierte Programmierung (Advanced Object-Oriented Programming)
2014-03-07 Preface Fortgeschrittene objektorientierte Programmierung (Advanced Object-Oriented Programming) Coordinates: Lecturer: Web: Studies: Requirements: No. 185.211, VU, 3 ECTS Franz Puntigam http://www.complang.tuwien.ac.at/franz/foop.html
More informationSubtyping (cont) Lecture 15 CS 565 4/3/08
Subtyping (cont) Lecture 15 CS 565 4/3/08 Formalization of Subtyping Inversion of the subtype relation: If σ
More informationPowerPoint Slides. Object-Oriented Design Using JAVA. Chapter 2. by Dale Skrien
PowerPoint Slides Object-Oriented Design Using JAVA by Dale Skrien Chapter 2 Object-oriented Programming Divides the program into a set of communicating objects Encapsulates in an object all the behavior
More informationOverview. Elements of Programming Languages. Records. Named variants. Last time: Simple data structures: pairing (product types), choice (sum types)
Overview Elements of Programming Languages Lecture 7: Records, variants, and subtyping James Cheney University of Edinburgh October 12, 2017 Last time: Simple data structures: pairing (product types),
More informationGrade Weights. Language Design and Overview of COOL. CS143 Lecture 2. Programming Language Economics 101. Lecture Outline
Grade Weights Language Design and Overview of COOL CS143 Lecture 2 Project 0% I, II 10% each III, IV 1% each Midterm 1% Final 2% Written Assignments 10% 2.% each Prof. Aiken CS 143 Lecture 2 1 Prof. Aiken
More informationVariance. Svetlana Isakova
Variance Svetlana Isakova Variance Describes how types with the same base type and different type arguments relate to each other Animal Producer Consumer Cat Producer Consumer
More informationSOOL, a Simple Object-Oriented Language
10 SOOL, a Simple Object-Oriented Language SOOL In the last two chapters we introduced the formal notation necessary in order to specify programming languages. Now we are ready to present the formal specification
More informationJava Design Goals. Lecture 32: Java. Java Original implementations slow! Exceptions & Subtyping. - void method readfiles() throws IOException {...}!
Java Design Goals Lecture 32: Java CSC 131 Fall, 2014 Kim Bruce Portability across platforms Reliability Safety (no viruses) Dynamic Linking Multithreaded execution Simplicity and Familiarity Efficiency
More informationChapter 11 Inheritance and Polymorphism. Motivations. Suppose you will define classes to model circles,
Chapter 11 Inheritance and Polymorphism 1 Motivations Suppose you will define classes to model circles, rectangles, and triangles. These classes have many common features. What is the best way to design
More informationHistory C++ Design Goals. How successful? Significant constraints. Overview of C++
1 CS 242 History C++ John Mitchell C++ is an object-oriented extension of C C was designed by Dennis Ritchie at Bell Labs used to write Unix based on BCPL C++ designed by Bjarne Stroustrup at Bell Labs
More informationTopics Covered Thus Far. CMSC 330: Organization of Programming Languages. Language Features Covered Thus Far. Programming Languages Revisited
CMSC 330: Organization of Programming Languages Type Systems, Names & Binding Topics Covered Thus Far Programming languages Syntax specification Regular expressions Context free grammars Implementation
More informationType Hierarchy. Lecture 6: OOP, autumn 2003
Type Hierarchy Lecture 6: OOP, autumn 2003 The idea Many types have common behavior => type families share common behavior organized into a hierarchy Most common on the top - supertypes Most specific at
More informationCSE 143. "Class Relationships" Class Relationships and Inheritance. A Different Relationship. Has-a vs. Is-a. Hierarchies of Organization
Class Relationships and Inheritance [Chapter 8, pp.343-354] "Class Relationships" is the title of Chapter 8 One class may include another as a member variable Date" used inside "Performance" Called a "has-a"
More informationCS/ENGRD 2110 SPRING Lecture 2: Objects and classes in Java
1 CS/ENGRD 2110 SPRING 2014 Lecture 2: Objects and classes in Java http://courses.cs.cornell.edu/cs2110 Java OO (Object Orientation) 2 Python and Matlab have objects and classes. Strong-typing nature of
More informationCSE wi Final Exam 3/12/18 Sample Solution
Question 1. (8 points, 2 each) Equality. Recall that there are several different notions of object equality that we ve encountered this quarter. In particular, we have the following three: Reference equality:
More information301AA - Advanced Programming [AP-2017]
301AA - Advanced Programming [AP-2017] Lecturer: Andrea Corradini andrea@di.unipi.it Tutor: Lillo GalleBa galleba@di.unipi.it Department of Computer Science, Pisa Academic Year 2017/18 AP-2017-12: Polymorphisms
More information