Type == Class  reference type -- store only the object’s address  simple (primitive) type -- for storing small data values Other options Wrapper classes.

Slides:



Advertisements
Similar presentations
Copyright © 2012 Pearson Education, Inc. Chapter 15: Inheritance, Polymorphism, and Virtual Functions.
Advertisements

Chapter 12: Support for Object-Oriented Programming
ACM/JETT Workshop - August 4-5, :Inheritance and Interfaces.
Session 07: C# OOP 4 Review of: Inheritance and Polymorphism. Static and dynamic type of an object. Abstract Classes. Interfaces. FEN AK - IT:
1 Advanced Material The following slides contain advanced material and are optional.
Principles of Object-Oriented Software Development The language Eiffel.
Static and Dynamic Behavior Fall 2005 OOPD John Anthony.
1 COMP 144 Programming Language Concepts Felix Hernandez-Campos Lecture 24: Dynamic Binding COMP 144 Programming Language Concepts Spring 2002 Felix Hernandez-Campos.
Topic 6 Generic Data Structures "Get your data structures correct first, and the rest of the program will write itself." - David Jones.
Inheritance, Polymorphism, and Virtual Functions
1 L40 Generics (2). 2 OBJECTIVES  To understand raw types and how they help achieve backwards compatibility.  To use wildcards when precise type information.
Types in programming languages What are types, and why do we need them? Types in programming languages1.
Comparison of OO Programming Languages © Jason Voegele, 2003.
Inheritance using Java
1 Inheritance and Polymorphism Chapter 9. 2 Polymorphism, Dynamic Binding and Generic Programming public class Test { public static void main(String[]
Chapter 15 – Inheritance, Virtual Functions, and Polymorphism
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
“is a”  Define a new class DerivedClass which extends BaseClass class BaseClass { // class contents } class DerivedClass : BaseClass { // class.
OOPs Object oriented programming. Based on ADT principles  Representation of type and operations in a single unit  Available for other units to create.
1 Abstraction  Identify important aspects and ignore the details  Permeates software development programming languages are abstractions built on hardware.
1 COSC3557: Object-Oriented Programming Haibin Zhu, Ph. D. Associate Professor of CS, Nipissing University.
Method Overriding Remember inheritance: when a child class inherits methods, variables, etc from a parent class. Example: public class Dictionary extends.
Unit IV Unit IV: Virtual functions concepts, Abstracts classes & pure virtual functions. Virtual base classes, Friend functions, Static functions, Assignment.
OOP and Dynamic Method Binding Chapter 9. Object Oriented Programming Skipping most of this chapter Focus on 9.4, Dynamic method binding – Polymorphism.
CSSE501 Object-Oriented Development. Chapter 11: Static and Dynamic Behavior  In this chapter we will examine the differences between static and dynamic.
CS221 - Computer Science II Polymorphism 1. CS221 - Computer Science II Polymorphism 2 Outline  Explanation of polymorphism.  Using polymorphism to.
Chapter 12 Support for Object oriented Programming.
Types in programming languages1 What are types, and why do we need them?
Inheritance, Polymorphism, And Virtual Functions Chapter 15.
What Is Inheritance? Provides a way to create a new class from an existing class New class can replace or extend functionality of existing class Can be.
Chapter 14 Abstract Classes and Interfaces. Abstract Classes An abstract class extracts common features and functionality of a family of objects An abstract.
Lecture 10 Concepts of Programming Languages Arne Kutzner Hanyang University / Seoul Korea.
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
Sadegh Aliakbary Sharif University of Technology Spring 2011.
OOPs Object oriented programming. Abstract data types  Representationof type and operations in a single unit  Available for other units to create variables.
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.
Generic Data Structures "Get your data structures correct first, and the rest of the program will write itself." - David Jones EE 422CGenerics 1.
Chapter 8 Class Inheritance and Interfaces F Superclasses and Subclasses  Keywords: super F Overriding methods  The Object Class  Modifiers: protected,
Method Overriding Remember inheritance: when a child class inherits methods, variables, etc from a parent class. Example: public class Dictionary extends.
Interfaces F What is an Interface? F Creating an Interface F Implementing an Interface F What is Marker Interface?
Peyman Dodangeh Sharif University of Technology Fall 2014.
Abstract Classes & Object Slicing. Pure Virtual Functions Virtual Function : Child class may override, if working with pointer/reference, check to see.
Object Oriented Programming in C++ Chapter 7 Dynamic Binding.
Inheritance in C++ Bryce Boe 2012/08/28 CS32, Summer 2012 B.
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
1 Lecture 23: Dynamic Binding (Section ) CSCI 431 Programming Languages Fall 2002 A compilation of material developed by Felix Hernandez-Campos.
COP INTERMEDIATE JAVA Inheritance, Polymorphism, Interfaces.
C++ General Characteristics: - Mixed typing system - Constructors and destructors - Elaborate access controls to class entities.
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 20 – C++ Subclasses and Inheritance.
Abstract Classes & Object Slicing. Object Slicing.
ISBN Chapter 12 Support for Object-Oriented Programming.
A First Book of C++ Chapter 12 Extending Your Classes.
1 Topic 5 Polymorphism "“Inheritance is new code that reuses old code. Polymorphism is old code that reuses new code.”
Design issues for Object-Oriented Languages
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Modern Programming Tools And Techniques-I
Sixth Lecture ArrayList Abstract Class and Interface
Advanced Programming in Java
Types of Programming Languages
Topic 6 Generic Data Structures
Java Programming Language
Polymorphism.
Object-Oriented Programming
Inheritance, Polymorphism, and Virtual Functions
Topic 5 Polymorphism "“Inheritance is new code that reuses old code. Polymorphism is old code that reuses new code.”
Inheritance and Polymorphism
Lecture 10 Concepts of Programming Languages
Polymorphism.
Static Binding Static binding chooses the function in the class of the base class pointer, ignoring any versions in the class of the object actually.
Programming in C# CHAPTER 5 & 6
Presentation transcript:

Type == Class  reference type -- store only the object’s address  simple (primitive) type -- for storing small data values Other options Wrapper classes (Java, C# calls this boxing) Expanded objects (Eiffel) Two Categories of Type  related issues: deep/shallow equality, alias vs. cloning

What is a message? Static type checking - compile time Type Checking Techniques (This should sound familiar.) Dynamic type checking - run time

Eiffel Example class BASE_CLASS feature {ANY} foo is … poo is … doo is … end class DERIVED_CLASS inherit BASE_CLASS rename poo as too redefine doo export {NONE} foo end feature {ANY} doo is … end

class ANOTHER_BASE feature {ANY} foo is … moo is … end class MULTI_CLASS inherit BASE_CLASS rename foo as footoo export {NONE} footoo end ANOTHER_BASE feature {ANY} … end class BASE_CLASS feature {ANY} foo is … poo is … doo is … end

class ANOTHER_BASE feature {ANY} foo is … moo is … end class MULTI_CLASS inherit BASE_CLASS rename foo as footoo export {NONE} footoo end ANOTHER_BASE redefine moo end ANOTHER_BASE rename moo as parent_moo export {NONE} parent_moo end feature {ANY} moo is do parent_moo … end class BASE_CLASS feature {ANY} foo is … poo is … doo is … end

Note that a variable can be assigned (bound to) different kinds of objects. Subtype polymorphism means that a name can refer to differing types of objects so long as these objects are descendant (subtype) classes of the named class. ClosedFigure EllipsePolygon Square QuadrilateralPentagonTriangleCircle ClosedFigure fig; fig = somePolygon; … fig = someCircle; … fig = someSquare Dynamic dispatch means that the actual method to be executed (dispatched) is not determined until run-time. Suppose every class contains a parameterless method called calculatePerimeter

Example (Java syntax) public class Parent { public void foo( ParentParm parm) { … } When does the child’s version of foo override (redefine) the parent’s ? public class Child extends Parent { public void foo( ChildParm p) { … } 1) only if ParentParm and ChildParm are the same class 2) only if ChildParm is a descendant (subclass) of ParentParm 3) only if ParentParm is a descendant (subclass) of ChildParm 4) never (no overriding permitted) C++ permits both covariance & contravariance for concrete virtual methods, but invariance for pure virtual (deferred/abstract) methods.

A generic (parameterized) class ___________________________________ class BAG [ElementType] creation make feature {ANY} count : INTEGER -- number of elements in the bag make is … item : ElementType is … insert(e : ElementType) is … end myBag : BAG[STRING]; Example (Eiffel syntax). Declaration of a BAG object (perhaps in some other class) Typical method call myBag.insert( “xyz” );

public class Bag { int count ; //number of elements in the bag public Bag (...) {... } public ElementType item() {... } public void insert(ElementType e) {.... } } myBag : Bag ; Java (proposed) syntax. Declaration of a Bag object (perhaps in some other class) Typical method call myBag.insert( “xyz” ); myBag = new Bag (...); Instantiation of a BAG object. Other possibilities... public class Pair {