1 COMP313A Programming Languages Object Oriented Progamming Languages (2)

Slides:



Advertisements
Similar presentations
Object-Oriented Programming Session 9 Course : T Programming Language Concept Year : February 2011.
Advertisements

Object-Oriented Programming. 2 An object, similar to a real-world object, is an entity with certain properties, and with the ability to react in certain.
Lecture 10: Part 1: OO Issues CS 540 George Mason University.
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.
Module 8 “Polymorphism and Inheritance”. Outline Understanding Inheritance Inheritance Diagrams Constructors in Derived Classes Type Compatibility Polymorphism.
1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University.
Programming Language Concepts Lecture 19 Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Object-Oriented Programming (Part.
CSC 212 – Data Structures. Using Stack Stack Limitations  Great for Pez dispensers, JVMs,& methods  All of these use most recent item added only 
Object-Oriented Programming CS 3360 Spring 2012 Sec , Adapted from Addison Wesley’s lecture notes (Copyright © 2004 Pearson Addison.
Object Oriented Programming Chapter 7 Programming Languages by Ravi Sethi.
Stacks and Queues & Inheritance 2014 Spring CS32 Discussion Jungseock Joo.
Inheritance and object compatibility Object type compatibility An instance of a subclass can be used instead of an instance of the superclass, but not.
Inheritance1 Inheritance Software re-use with derived classes.
Inheritance. In this chapter, we will cover: The concept of inheritance Extending classes Overriding superclass methods Working with superclasses that.
1 COMP313A Programming Languages Object Oriented Progamming Languages (1)
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 13 Object-Oriented Programming I am surprised.
1 Introduction to CS Agenda Syllabus Schedule Lecture: the management of complexity.
Queues CS-240 & CS-341 Dick Steflik. Queues First In, First Out operation - FIFO As items are added they are chronologically ordered, items are removed.
Saturday May 02 PST 4 PM. Saturday May 02 PST 10:00 PM.
Data Abstraction and Object- Oriented Programming CS351 – Programming Paradigms.
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
CS 355 – PROGRAMMING LANGUAGES Dr. X. Copyright © 2012 Addison-Wesley. All rights reserved.1-2 Chapter 12 Topics Introduction Object-Oriented Programming.
CSSE501 Object-Oriented Development
Like our natural language. Designed to facilitate the expression and communication ideas between people and computer Like our natural language. Designed.
OOP Languages: Java vs C++
CSE 425: Object-Oriented Programming II Implementation of OO Languages Efficient use of instructions and program storage –E.g., a C++ object is stored.
CS 403 – Programming Languages Class 25 November 28, 2000.
1 Chapter 10: Data Abstraction and Object Orientation Aaron Bloomfield CS 415 Fall 2005.
Object-oriented programming: C++ class A { private: …… // can be accessd by A protected: …… // can be accessed by A and // its derived classes public:
Programming Languages and Paradigms Object-Oriented Programming (Part II)
CS 2430 Day 26. Announcements Exam #2: Wednesday, April 3 –Review in lab on Tuesday, April 2 –Sample problems sent via .
1 COSC3557: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University.
Programming Languages and Paradigms Object-Oriented Programming.
CS212: Object Oriented Analysis and Design Lecture 15: Inheritance in C++ -II.
OOP and Dynamic Method Binding Chapter 9. Object Oriented Programming Skipping most of this chapter Focus on 9.4, Dynamic method binding – Polymorphism.
Inheritance - Polymorphism ITI 1121 Nour El Kadri.
1 COMP313A Programming Languages Object Oriented Progamming Languages (3)
Chapter 12 Support for Object-Oriented Programming.
QUEUES What are Queues? Creating a Queue Enqueuing and Dequeuing Testing for an Empty Queue.
Lecture 10 Concepts of Programming Languages Arne Kutzner Hanyang University / Seoul Korea.
Object-Oriented Programming Chapter Chapter
(1) ICS 313: Programming Language Theory Chapter 12: Object Oriented Programming.
Question of the Day  How can you change the position of 1 toothpick and leave the giraffe in exactly the same form, but possibly mirror-imaged or oriented.
Principles of programming languages 10: Object oriented languages Isao Sasano Department of Information Science and Engineering.
Week 2 - Friday.  What did we talk about last time?  Computing Big Oh.
Lecture 20 Stacks and Queues. Stacks, Queues and Priority Queues Stacks – first-in-last-out structure – used for function evaluation (run-time stack)
Inheritance Type/Subtype Relationship. Inheritance Idea: An object B of one type, termed child class, inherits from another object A of another type,
Inheritance and Subclasses CS 21a. 6/28/2004 Copyright 2004, by the authors of these slides, and Ateneo de Manila University. All rights reserved L16:
CSCI-383 Object-Oriented Programming & Design Lecture 24.
Lecture 8: Advanced OOP Part 2. Overview Review of Subtypes Interfaces Packages Sorting.
Question of the Day  How can you change the position of 1 toothpick and leave the giraffe in exactly the same form, but possibly mirror-imaged or oriented.
Pointers A pointer type variable holds the address of a data object or a function. A pointer can refer to an object of any one data type; it cannot refer.
Object Oriented Programming in Java Habib Rostami Lecture 7.
SUBCLASSES - JAVA. The Purpose of Subclasses Class Farm String getOwner() void setOwner(String s) int getSize() void setSize(int s) Class DairyFarm String.
ISBN Chapter 12 Support for Object-Oriented Programming.
Chapter 12: Support for Object- Oriented Programming Lecture # 18.
Inheritance a subclass extends the functionality of a superclass a subclass inherits all the functionality of a superclass don't reinvent the wheel – "stand.
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Principles of programming languages 10: Object oriented languages
Lecture 12 Inheritance.
7.1 What Is An Object Object-oriented program - Description or simulation of application Object-oriented programming is done by adopting or extending an.
Inheritance and Polymorphism
Support for Object-Oriented Programming in Ada 95
Parameter Passing Actual vs formal parameters
Support for Object-Oriented Programming
Object-Oriented Programming
Lecture 16 Stacks and Queues CSE /26/2018.
Object-Oriented Programming (Part 2)
Lecture 10 Concepts of Programming Languages
Lecture 16 Stacks and Queues CSE /26/2018.
Presentation transcript:

1 COMP313A Programming Languages Object Oriented Progamming Languages (2)

2 Lecture Outline The Class Hierarchy and Data Abstraction Polymorphism Polymorphism and Strong Typing

3 furniture chairtable lounge chairsofa dining table desk

4 public class Queue { // constructors and instance variables go here public void enqueue (int x) {…} public void dequeue() {…} public int front () {…} public boolean empty() {…} } public class Deque extends Queue {// constructors and instance variables go here public void addFront ( int x {… } public void deleteRear() {… } } Is Queue more abstract than Deque or vice versa

5 class stack{ public: void push(int, item){elements[top++] = item;}; int pop () {return elements[--top];}; private: int elements[100]; int top =0; }; class counting_stack: public stack { public: int size(); // return number of elements on stack stack s1, s2; // automatic variables stack* sp = new stack; sp->pop()

6 stack* sp = new stack; counting_stack* csp = new counting_stack; sp = csp; // okay csp = sp; // statically can’t tell C++ strong type system Why shouldn’t csp be allowed to point to an sp object?

7 Polymorphism polymorphic variables could refer to objects of different classes –what is the problem for a type checker How do we allow dynamic binding and still ensure type safety strong type system limits polymorphism –restricted to objects of a class or its derived classes –e.g. variables of type stack may refer to a variable of type counting_stack Strict object-oriented languages (Smalltalk, Eiffel, Java –all objects accessed through references which may be polymorphic C++ - pointers, reference variables and by- reference parameters are polymorphic

8 If we do not use pointers we do not get inclusion polymorphism. But… stack s; counting_stack cs; s = cs; //okay coerce cs to a stack cs = s; //not okay

9 The Type System The subtype principle a week day is also a day –is-a relationship similarly class and sub-class –counting_stack is-a stack but…. type day = (Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday); weekday= (Monday..Friday);

10 The Type System need to state the conditions under which the isa relationship holds for subclasses of classes because… subclasses can hide the variables and functions or modify them in an incompatible way need to know when they are equivalent with the parent’s definition