- couldn t be instantiated dynamically! - no type or other method of organizing, despite similarity to

Similar documents
Object-Oriented Languages and Object-Oriented Design. Ghezzi&Jazayeri: OO Languages 1

Some instance messages and methods

Data Abstraction. Hwansoo Han

References: Chapters 10 and 11 Chapters 8, and 12( 2 and 3)

CSE Lecture 3: Objects 2 September Nate Nystrom University of Texas at Arlington

DATA TYPES. CS 403: Types and Classes DATA TYPES (CONT D)

Concepts of Programming Languages

Week 7. Statically-typed OO languages: C++ Closer look at subtyping

CS422 - Programming Language Design

Topics. Modularity and Object-Oriented Programming. Dijkstra s Example (1969) Stepwise Refinement. Modular program development

Object-oriented Programming. Object-oriented Programming

CS109B ML Notes for the Week of 5/8/95. Structures. ML's way of encapsulating concepts such as a data. structure and functions that operate on it.

Chapter 5 Object-Oriented Programming

CS558 Programming Languages

Lecture 13: Object orientation. Object oriented programming. Introduction. Object oriented programming. OO and ADT:s. Introduction

Java Object Oriented Design. CSC207 Fall 2014

CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 17: Types and Type-Checking 25 Feb 08

Design issues for objectoriented. languages. Objects-only "pure" language vs mixed. Are subclasses subtypes of the superclass?

Object-Oriented Concepts and Principles (Adapted from Dr. Osman Balci)

Objects. Deian Stefan (Adopted from my & Edward Yang s CS242 slides)

Lecture Notes on Programming Languages

Subtyping (Dynamic Polymorphism)

CSE341: Programming Languages Lecture 25 Subtyping for OOP; Comparing/Combining Generics and Subtyping. Dan Grossman Winter 2013

CS-XXX: Graduate Programming Languages. Lecture 22 Class-Based Object-Oriented Programming. Dan Grossman 2012

G Programming Languages - Fall 2012

Data Structures and Algorithms Design Goals Implementation Goals Design Principles Design Techniques. Version 03.s 2-1

Chapter 5: Procedural abstraction. Function procedures. Function procedures. Proper procedures and function procedures

CS558 Programming Languages

Outline. Central concepts in OO languages Objects as activation records (Simula) Dynamically-typed object-oriented languages

OBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe

Konzepte von Programmiersprachen

CSE 504. Expression evaluation. Expression Evaluation, Runtime Environments. One possible semantics: Problem:

Inheritance and Interfaces

Introduction to C++ Introduction to C++ Dr Alex Martin 2013 Slide 1

Lists. Michael P. Fourman. February 2, 2010

PROGRAMMING LANGUAGE 2

301AA - Advanced Programming [AP-2017]

Paytm Programming Sample paper: 1) A copy constructor is called. a. when an object is returned by value

Object Oriented Programming in Java. Jaanus Pöial, PhD Tallinn, Estonia

Chapter 13 Object Oriented Programming. Copyright 2006 The McGraw-Hill Companies, Inc.

Compiler Construction Lent Term 2015 Lectures 10, 11 (of 16)

Rushikesh K Joshi. Department of Computer Science and Engineering Indian Institute of Technology Bombay

ob-ject: to feel distaste for something Webster's Dictionary

Functional programming Primer I

CS558 Programming Languages Winter 2013 Lecture 8

Informatica 3 Syntax and Semantics

Chapter 11. Categories of languages that support OOP: 1. OOP support is added to an existing language

CS Computable Functions. Reading: Chapter 2

CMSC 132: Object-Oriented Programming II

Object-Oriented Programming. Lecture 16 CS 565 4/10/08

Type Hierarchy. Lecture 6: OOP, autumn 2003

Object typing and subtypes

CSc 520. Principles of Programming Languages 45: OO Languages Introduction

Objects. Prof. Clarkson Fall ob-ject: to feel distaste for something Webster's Dictionary. Today s music: Kung Fu Fighting by CeeLo Green

Programming Language Concepts Object-Oriented Programming. Janyl Jumadinova 28 February, 2017

C++ Important Questions with Answers

On to Objects. CIS 500 Software Foundations Fall November 20. A Change of Pace. Case study: object-oriented programming

Thanks! Review. Course Goals. General Themes in this Course. There are many programming languages. Teaching Assistants. John Mitchell.

Programming Languages and Techniques (CIS120)

CS558 Programming Languages

Compiler construction 2009

Advanced oo concepts Specialization of behaviour? Multiple inheritance - alternatives to. Inner classes Classes

Records. ADTs. Objects as Records. Objects as ADTs. Objects CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 15: Objects 25 Feb 05

ITI Introduction to Computing II

Lecture 16: Object Programming Languages

Object Oriented Programming. Java-Lecture 11 Polymorphism

An Introduction to Subtyping

Java Class Design. Eugeny Berkunsky, Computer Science dept., National University of Shipbuilding

CS-202 Introduction to Object Oriented Programming

Object Orientation. Chapter Sixteen Modern Programming Languages, 2nd ed. 1

Programming Languages 2nd edition Tucker and Noonan"

STUDENT LESSON A20 Inheritance, Polymorphism, and Abstract Classes

Simula 67. Simula and Smalltalk. Comparison to Algol 60. Brief history. Example: Circles and lines. Objects in Simula

Object Fundamentals Part Three. Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/6448 Lecture 4 09/06/2007

CS 11 Ocaml track: lecture 2

Design Issues. Subroutines and Control Abstraction. Subroutines and Control Abstraction. CSC 4101: Programming Languages 1. Textbook, Chapter 8

ITI Introduction to Computing II

Quiz. Programming Languages. CSE 130 : Fall Lecture 16: Static Types for Objects. Ranjit Jhala UC San Diego

State, Object-Oriented Programming Explicit State, Polymorphism (CTM ) Objects, Classes, and Inheritance (CTM )

Code Reuse: Inheritance

n n Try tutorial on front page to get started! n spring13/ n Stack Overflow!

Programming Language Concepts, CS2104 Lecture 7

Lecture 23: Object Lifetime and Garbage Collection

CSE 307: Principles of Programming Languages

CS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE

Design Pattern and Software Architecture: IV. Design Pattern

Abstract Classes. Abstract Classes a and Interfaces. Class Shape Hierarchy. Problem AND Requirements. Abstract Classes.

Argument Passing All primitive data types (int etc.) are passed by value and all reference types (arrays, strings, objects) are used through refs.

CSE 452: Programming Languages. Previous Lecture. From ADTs to OOP. Data Abstraction and Object-Orientation

Polymorphism. CMSC 330: Organization of Programming Languages. Two Kinds of Polymorphism. Polymorphism Overview. Polymorphism

COURSE 2 DESIGN PATTERNS

Lecture 7: Data Abstractions

Procedure and Object- Oriented Abstraction

Chapter 11 Object and Object- Relational Databases

Inheritance (Chapter 7)

Inheritance, Polymorphism, and Interfaces

Project Overview. 1 Introduction. 2 A quick introduction to SOOL

Subtyping. Lecture 13 CS 565 3/27/06

Outline. Inheritance. Abstract Classes Interfaces. Class Extension Overriding Methods Inheritance and Constructors Polymorphism.

Inheritance. Benefits of Java s Inheritance. 1. Reusability of code 2. Code Sharing 3. Consistency in using an interface. Classes

Transcription:

Roots in ADT Languages Lecture 20: OOLs CSC 131 Fall, 2014 Kim Bruce Ada and Modula-2 internal reps - couldn t be instantiated dynamically - no type or other method of organizing, despite similarity to records - provide better modules for building large systems Called object-based Qualities Desired in Software Responding to the SOFTWARE CRISIS Correctness Robustness Extensibility ----------------- Almost all supported by ADT s Reusability Compatibility

Object-Oriented Languages Objects that are data abstractions Objects have associated object type (classes) Classes may inherit attributes from superclass Computations proceed by sending messages Subtype polymorphism Support dynamic method invocation Programming Objects in ML exception Empty; fun newstack(x) = let val store = ref [x] in {push = fn y => store := y::(store); pop = fn z => case store of nil = raise Empty (y::ys) = (store := ys; y) } end; val mystack = newstack(0); #push(mystack)(1); #pop(mystack)(); Parameter z ignored, used # to delay evaluation# really parameterless function Weakness of ML OO Keywords Object No subtyping No this/self No inheritance Message Class Instance Method Subtype Subclass

Objects Object Types Internal data abstractions Hide representation Have associated state Methods have access to its state Self Allow objects to be first class Allow use in assignment, parameters, components of structures Allow objects to be classified via subtyping Classes Dynamic Method Invocation Templates for creation of objects - Initialization code - Contain definitions for all methods Can modify or extend by creating subclasses. Can be used as types Each object responsible for keeping track of implementation of its own operations When evaluated o.m(...) at run-time, code run depends on operations associated with o. Static overloading is different - resolved at compile time.

Multi-methods Subtyping Code executed depends on more than one argument. Example m(a,b) -- choice of code to be executed depends on run-time types of a and b. CLOS is example of such language Already discussed Relation between interfaces, independent of implementations Behavior and implementation quite different from single-dispatch languages. Subclasses Subclasses Support incremental modification of code. class Point var x = 0: Int; methods fun getx():int {return x} proc move(dx: int) {x := x + dx} subclass Colorpoint of Point modifying move var color = blue: ClrType methods fun getcolor():clrtype {return color} proc setcolor(nucolor: ClrType) {color := nucolor} proc move(dx: int) {super.move(dx); color := red}

Static Overloading vs Dynamic Dispatch Dynamic dispatch - object receiving message determines which code will be executed. - Determined at run-time. Static overloading occurs when an object supports two or more implementations of a message name -- generally w/different types. - Determined at compile-time.# - e.g., moveto(x,y) & moveto(locn)# Confusion when coexist in same language. Overloading vs Dynamic Dispatch class C { fun eq(other: Ctype):boolean { } (1) } class SC of C modifying eq { fun eq(other: Ctype):boolean { } (2) override fun eq(other: SCtype):boolean { } (3) overload } c,c : Ctype;sc: SCtype; c = new C; c = new SC; sc = new SC; What code is executed? c.eq(c); c.eq(c ); c.eq(sc); c.eq(c); c.eq(c ); c.eq(sc); sc.eq(c); sc.eq(c ); sc.eq(sc); Type Restrictions More flexible subclasses Type systems limit changes in method types in subclasses. class C... methods clone(): CType {...}; equals(other: CType) {...}; end class How can we change these types in subclasses? Why restrict changing types in subclasses? Methods can be mutually recursive

class Example : methods proc m(s:s,...) {... self.n(s)...} fun n(x: S): T {...} subclass SubExample of Example modifying n : methods fun n(x: S ): T {...} proc newmethod(...){...} What must be relationship of new type of n to old to preserve type safety? Changing Types in Subclasses Subtype will always be fine I.e., S <: S' and T' <: T equivalently, S T <: S T E.g., can change return type of clone in subclass to type of objects from subclass. Cannot specialize parameter types in equals Binary methods# If subclass updates method types so they are subtypes of original then type-safe. If restricted in this way, subclasses will always generate subtypes. What about instance variables? Instance variables can be values and receivers - No subtypes If Circle has instance variable center: Point, ColorCircle's center must have same type. Hard to redefine getcenter in ColorCircle, even if legal# Important problem in OO language design and type theory