Subtying Kangwon National University 임현승 4473001-1 Programming Languages These slides were originally created by Prof. Sungwoo Park at POSTECH.

Slides:



Advertisements
Similar presentations
Overriding CMPS Overriding Recall, a method in a child class overrides a method in the parent class, if it has the same name and type signature.
Advertisements

Chapter 9 Pointers and Dynamic Arrays. Overview 9.1 Pointers 9.2 Dynamic Arrays.
METHOD OVERRIDING Sub class can override the methods defined by the super class. Overridden Methods in the sub classes should have same name, same signature.
METHOD OVERRIDING 1.Sub class can override the methods defined by the super class. 2.Overridden Methods in the sub classes should have same name, same.
Portability and Safety Mahdi Milani Fard Dec, 2006 Java.
CSE-321 Programming Languages Subtyping POSTECH May 14, 2007 박성우.
Catriel Beeri Pls/Winter 2004/5 last 55 Two comments on let polymorphism I. What is the (time, space) complexity of type reconstruction? In practice –
CSE341: Programming Languages Lecture 26 Subtyping for OOP Dan Grossman Fall 2011.
Overview of Java (continue). Announcements You should have access to your repositories and HW0 If you have problems getting HW0, let me know If you’ve.
Subtyping COS 441 Princeton University Fall 2004.
Polymorphism. Legal assignments Widening is legal Narrowing is illegal (unless you cast) class Test { public static void main(String args[]) { double.
1 COMP313A Programming Languages Object Oriented Progamming Languages (1)
Principles of Object-Oriented Software Development The language Java.
1 Java (vs. C++). 2 Object-oriented Programming Java and C++ are the most popular object-oriented programming languages Java Sun Microsystems in 1990.
Exam Objective : Legal return types PRESENTED BY : SRINIVAS VG.
Scott Grissom, copyright 2004Ch 3: Java Features Slide 1 Why Java? It is object-oriented provides many ready to use classes platform independent modern.
26-Jun-15 Polymorphism. 2 Legal assignments Widening is legal Narrowing is illegal (unless you cast) class Test { public static void main(String args[])
Course Map The Java Programming Language Basics Object-Oriented Programming Exception Handling Graphical User Interfaces and Applets Multithreading Communications.
1 Type Type system for a programming language = –set of types AND – rules that specify how a typed program is allowed to behave Why? –to generate better.
(c) University of Washington03-1 CSC 143 Java Inheritance Reading: Ch. 10.
Like our natural language. Designed to facilitate the expression and communication ideas between people and computer Like our natural language. Designed.
Engr 691 Special Topics in Engineering Science Software Architecture Spring Semester 2004 Lecture Notes.
“is a”  Define a new class DerivedClass which extends BaseClass class BaseClass { // class contents } class DerivedClass : BaseClass { // class.
OVERRIDING/OVERLOADING Srinivas. EXAM OBJECTIVES  Given a code example, determine if a method is correctly overriding or overloading another method,
Object Oriented Programming: Java Edition By: Samuel Robinson.
Subtyping Chapter 15 Benjamin Pierce Types and Programming Languages.
1 COSC3557: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University.
Class 14: Object-Oriented Programming Fall 2010 University of Virginia David Evans cs2220: Engineering Software.
Inheritance. Introduction Inheritance is one of the cornerstones of object-oriented programming because it allows the creation of hierarchical classifications.
Sun Certified Java Programmer, ©2004 Gary Lance, Chapter 5, page 1 Sun Certified Java 1.4 Programmer Chapter 5 Notes Gary Lance
Generics CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
OOP and Dynamic Method Binding Chapter 9. Object Oriented Programming Skipping most of this chapter Focus on 9.4, Dynamic method binding – Polymorphism.
1 COMP313A Programming Languages Object Oriented Progamming Languages (3)
28-Dec-04polymorhism.ppt1 Polymorphism. 28-Dec-04polymorhism.ppt2 signatures in any programming language, a signature is what distinguishes one function.
The Scala API. Scala has a reputation of being a difficult language Some people feel that Scala is beyond what the average programmer can master Others.
Lecture 10 Concepts of Programming Languages Arne Kutzner Hanyang University / Seoul Korea.
Csci 490 / Engr 596 Special Topics / Special Projects Software Design and Scala Programming Spring Semester 2010 Lecture Notes.
Principles of Object-Oriented Software Development The language C++
1 Chapter 9a Abstract Classes & Dynamic Binding. 2 Abstract Classes All classes so far have been concrete classes –Classes that can be used to create.
Conformance Object-Oriented Programming Spring
SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler
Interfaces and Polymorphism CS 162 (Summer 2009).
COM S 228 Introduction to Data Structures Instructor: Ying Cai Department of Computer Science Iowa State University Office: Atanasoff.
Inductive Proofs Kangwon National University 임현승 Programming Languages These slides were originally created by Prof. Sungwoo Park at POSTECH.
Access Specifier. Anything declared public can be accessed from anywhere. Anything declared private cannot be seen outside of its class. When a member.
AD Lecture #1 Object Oriented Programming Three Main Principles 1 Inheritance Encapsulation Polymorphism.
CSSE501 Object-Oriented Development. Chapter 10: Subclasses and Subtypes  In this chapter we will explore the relationships between the two concepts.
A comparison of C-Sharp and Java Zunaid Jogee Supervisor: T. Stakemire.
Inductive Definitions Kangwon National University 임현승 Programming Languages These slides were originally created by Prof. Sungwoo Park at POSTECH.
CMSC 202 Polymorphism. 10/20102 Topics Binding (early and late) Upcasting and downcasting Extensibility The final modifier with  methods  classes.
Class Inheritance SWE 344 Internet Protocols & Client Server Programming.
Java Inheritance in Java. Inheritance Inheritance is a mechanism in which one object acquires all the properties and behaviors of parent object. The idea.
COME 339 WEEK 1. Example: The Course Class 2 TestCourceRunCourse.
Types and Programming Languages Lecture 10 Simon Gay Department of Computing Science University of Glasgow 2006/07.
Methods.
Author: DoanNX Time: 45’.  OOP concepts  OOP in Java.
CH10 Supplementary Material Prepared by Fatimah Alakeel Oct 2010.
CSE 341 Section 10 Subtyping, Review, and The Future.
JAVA METHODS (FUNCTIONS). Why are they called methods? Java is a strictly object-oriented programming language Methods are functions inside of objects.
28-Dec-04polymorhism.ppt1 Polymorphism. 28-Dec-04polymorhism.ppt2 signatures in any programming language, a signature is what distinguishes one function.
Object Oriented Programming Lecture 2: BallWorld.
Modern Programming Tools And Techniques-I
Lecture 12 Inheritance.
CS230 Tutorial Week 3.
Subtyping Rules David Evans cs205: engineering software BlackBear
More inheritance, Abstract Classes and Interfaces
Method Overriding in Java
class PrintOnetoTen { public static void main(String args[]) {
Object Oriented Programming.
Subtype Substitution Principle
Presentation transcript:

Subtying Kangwon National University 임현승 Programming Languages These slides were originally created by Prof. Sungwoo Park at POSTECH.

2 Key Features of Object-Oriented Languages Multiple representation –different methods of the same name –dynamic dispatch Encapsulation –Only an object's own methods can see private data. Inheritance –classes, subclasses,... Subtyping –interface, interface extension

3 Outline Overview V Principle of subtyping Subtyping relations Coercion semantics

4 Principle of Subtyping

5 Examples

6 Basic Rules Reflexivity and transitivity Rule of subsumption

7 Subset Semantics for Subtyping Example –32-bit word for nat –32-bit word for int –64-bit word for float

8 Outline Overview V Principle of subtyping V Subtyping relations Coercion semantics

9 Setup

10 Subtyping for Product Types

11 Subtyping for Sum Types

12 Subtyping for Function Types

13 Subtyping for Reference Types

You are all so gullible!

15 Wrong Subtyping Rules!

16

17

18 Subtyping for Function Types Covariant in return types B and B' Contravariant in argument types A and A'

19 Dereferencing ref A

20 Assigning to ref A

21 Subtyping for Reference Types

22 Subtyping for Array Types Array types = extension of reference types Subtyping for array types in Java –runtime overhead of dynamic tag-checks.

Subtyping for Java Array Types class Animal {} class Dog extends Animal {} class Cat extends Animal {} class Main { public static void main(String[] args) { Dog[] dogs = new Dog[1]; dogs[0] = new Dog(); Animal[] animals = dogs; animals[0] = new Cat(); } 23 Exception in thread "main" java.lang.ArrayStoreException: Cat at Main.main

24 Outline Overview V Principle of subtyping V Subtyping relations V Coercion semantics

25 Coercion Semantics for Subtyping Example –32-bit word for int –64-bit word for float

26 Coercion Subtyping Judgment

27 Coherence