(1) ICS 313: Programming Language Theory Chapter 12: Object Oriented Programming.

Slides:



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

Lecture 10: Part 1: OO Issues CS 540 George Mason University.
ISBN Chapter 12 Support for Object-Oriented Programming.
Software Productivity
Chapter 12 Support for Object-Oriented Programming.
Chapter 12: Support for Object-Oriented Programming
Object-Oriented Programming CS 3360 Spring 2012 Sec , Adapted from Addison Wesley’s lecture notes (Copyright © 2004 Pearson Addison.
Advanced Programming in Java
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Inheritance and object compatibility Object type compatibility An instance of a subclass can be used instead of an instance of the superclass, but not.
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 8.1 – 8.5.
ISBN Chapter 12 Support for Object-Oriented Programming.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Object-Oriented Programming
Chapter 10 Classes Continued
1 Chapter 12 © 2002 by Addison Wesley Longman, Inc Introduction - Categories of languages that support OOP: 1. OOP support is added to an existing.
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
ISBN Chapter 12 Support for Object- Oriented Programming.
CS 355 – PROGRAMMING LANGUAGES Dr. X. Copyright © 2012 Addison-Wesley. All rights reserved.1-2 Chapter 12 Topics Introduction Object-Oriented Programming.
Support for Object-Oriented Programming
Chapter 12 Support for Object-Oriented Programming.
CPS 506 Comparative Programming Languages
Programming Languages and Paradigms Object-Oriented Programming.
1 Chapter 11 Abstract Data Types and Encapsulation Constructs.
ISBN Chapter 12 Support for Object-Oriented Programming.
OOPs Object oriented programming. Based on ADT principles  Representation of type and operations in a single unit  Available for other units to create.
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: Java Edition By: Samuel Robinson.
Object-Oriented Programming Session 9 Course : T Programming Language Concept Year : February 2011.
Object-oriented programming: C++ class A { private: …… // can be accessd by A protected: …… // can be accessed by A and // its derived classes public:
Introduction to Object Oriented Programming CMSC 331.
Chapter 12 Support for Object oriented Programming.
Chapter 12 Support for Object-Oriented Programming.
ISBN Chapter 12 Support for Object-Oriented Programming.
Chapter 12 Support for Object-Oriented Programming.
1 Abstract Data Types & Object Orientation Abstract Data Types (ADT) Concepts –Data Abstraction –ADT in PLs –Encapsulation Object Orientation –Principal.
ISBN Chapter 12 Support for Object-Oriented Programming.
Lecture 10 Concepts of Programming Languages Arne Kutzner Hanyang University / Seoul Korea.
Chapter 12 Support for Object-Oriented Programming.
Object-Oriented Programming Chapter Chapter
OOPs Object oriented programming. Abstract data types  Representationof type and operations in a single unit  Available for other units to create variables.
Object Oriented Programming
1 Copyright © 1998 by Addison Wesley Longman, Inc. Chapter 11 Categories of languages that support OOP: 1. OOP support is added to an existing language.
ISBN Object-Oriented Programming Chapter Chapter
Author: DoanNX Time: 45’.  OOP concepts  OOP in Java.
1 Lecture 23: Dynamic Binding (Section ) CSCI 431 Programming Languages Fall 2002 A compilation of material developed by Felix Hernandez-Campos.
 Description of Inheritance  Base Class Object  Subclass, Subtype, and Substitutability  Forms of Inheritance  Modifiers and Inheritance  The Benefits.
C++ General Characteristics: - Mixed typing system - Constructors and destructors - Elaborate access controls to class entities.
ISBN Chapter 12 Support for Object-Oriented Programming.
Object Oriented Programming CMSC 331. Concept of Abstraction “An abstraction is a view or representation of an entity that includes only the attributes.
Chapter 12: Support for Object- Oriented Programming Lecture # 18.
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
Support for Object-Oriented Programming
12.1 Introduction - Categories of languages that support OOP:
Support for Object-Oriented Programming
Support for Object-Oriented Programming
CMP 339/692 Programming Languages Day 24 Tuesday May 1, 2012
Types of Programming Languages
Support for Object-Oriented Programming
Object-Oriented Programming
Support for Object-Oriented Programming
Support for Object-Oriented Programming
Object-Oriented Programming
Support for Object-Oriented Programming
Support for Object-Oriented Programming
Lecture 10 Concepts of Programming Languages
Presentation transcript:

(1) ICS 313: Programming Language Theory Chapter 12: Object Oriented Programming

(2) Object Orientedness Three essential features: ADTs Inheritance Polymorphism by Dynamic Binding

(3) ADTs in OOP Classes are Abstract Data Types: Syntactic encapsulation of data and operations on the data Data accessible only through the defined operations Classes are a natural extension to the concept of Abstract Data Types: Apply principle of abstraction to a collection of related ADTs by factoring out commonalities into superclasses

(4) Inheritance Motivated by software reuse: Need to modify the original ADT Need to model interrelationships and hierarchy Inheritance addresses these issues: Inherit functionality of an ADT with selective modifications Inheritance hierarchy models the application domain

(5) Inheritance: Some Terms Classes Objects (class instances) Subclass or derived class Superclass or parent class Methods Messages Instance variables Instance methods Class variables Class methods Public Private Protected Abstract Class

(6) Polymorphism Dynamic Binding of Messages to Method Definitions Variables of type class can reference objects of any subclass of class Methods bound to definition dynamically depending on the referenced object Class method ClassA method ClassB method ClassC method public Class var = new …; var.method()

(7) Computing in OOP Create a hierarchical ontology of objects in the world Simulate their communications and processes Reuse the objects in other programs

(8) Design Issues

(9) Exclusivity of Objects Purely object oriented All types are classes Everything is an object Elegant but slow SMALLTALK Overlay an Object System C++: OOP added to imperative language CLOS: OOP added to functional language Large and complex languages Primitives types are not objects Java Need wrapper classes

(10) Wrapper Classes in Java From a postfix evaluation application: evalStack = new Stack(); Putting integers on the stack: evalStack.push(new Integer(value)); Retrieving integers: ((Integer)evalStack.pop()).intValue();

(11) What is inherited? (Caution: confusion possible) Interface Inheritance (ADT interface) Behaviors of methods (you can call them) Safer but less efficient Implementation Inheritance Structure (you can access the data structures directly) Protocol Inheritance Only parameter profile and return type Java Interfaces

(12) Single and Multiple Inheritance Single inheritance: Smalltalk Multiple inheritance: C++ Goldfish extends Fish, Pet Name collisions: which implementation should be used? More complex dependencies Class ClassAClassB ClassC

(13) Interfaces Java avoids collisions with Interfaces Only one implementation inherited public class Clock extends Applet implements Runnable Requires Clock to implement methods of Runnable Can lead to different complexities, e.g. using ‘has-a’ as substitute for ‘is-a’

(14) Allocation and Deallocation Where allocated? Static Stack-dynamic Heap: new C++: all of these Smalltalk: Heap only Implicit or Explicit Deallocation? C++: Explicit delete Smalltalk, Java: Implicit

(15) Type Checking and Polymorphism Binding of messages to methods must be dynamic when polymorphic variables are involved When does type checking of this binding happen? If you want strong typing, checking must be static - This restricts the language: overriding methods must have matching protocol Dynamic type checking is more costly

(16) Dynamic and Static Binding Can the programmer specify that some methods calls are statically bound? Java: - Default is Dynamic - For static, define method to be final C++: - Default is Static - Pointer of type base class may reference derived class - Declare function virtual for dynamic binding

(17) C++ Example: Static and Dynamic class shape { public: virtual void draw() = 0; … } // pure virtual class rectangle : public shape { public: virtual void draw() { … } …} class square : public rectangle { public: virtual void draw() { … } … } square s; rectangle r; shape &refsq = s; refsq.draw() // dynamically bound (ptr to base class) r.draw(); // statically bound

(18) Implementation Issues Instance Data Storage Static storage: class instance records - Instance variable addressing is constant offset - C++ Dynamic storage: association list or dictionary - Python Binding of Messages to Methods Static: more efficent Dynamic: requires pointers to methods - Need only store once in Virtual Method Table or class record (when classes are instances)

(19) End of Module

(20) Are Subclasses Subtypes Variables of type subclass can appear wherever variables of type parent are legal No-brainer? Not necessarily in C++!