Parameter Passing Actual vs formal parameters

Slides:



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

Programming Paradigms Introduction. 6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1:
Abstract Data Types Data abstraction, or abstract data types, is a programming methodology where one defines not only the data structure to be used, but.
CS 211 Inheritance AAA.
Inheritance Inheritance Reserved word protected Reserved word super
1 COMP 144 Programming Language Concepts Felix Hernandez-Campos Lecture 24: Dynamic Binding COMP 144 Programming Language Concepts Spring 2002 Felix Hernandez-Campos.
Basic Definitions Data Structures: Data Structures: A data structure is a systematic way of organizing and accessing data. Or, It’s the logical relationship.
Lecture 9 Concepts of Programming Languages
OOP Languages: Java vs C++
Comparison of OO Programming Languages © Jason Voegele, 2003.
Programming Languages and Paradigms Object-Oriented Programming.
LECTURE LECTURE 17 More on Templates 20 An abstract recipe for producing concrete code.
C++ Object Oriented 1. Class and Object The main purpose of C++ programming is to add object orientation to the C programming language and classes are.
1 Chapter 10: Data Abstraction and Object Orientation Aaron Bloomfield CS 415 Fall 2005.
Guided Notes Ch. 9 ADT and Modules Ch. 10 Object-Oriented Programming PHP support for OOP and Assignment 4 Term project proposal C++ and Java Designer.
OOP and Dynamic Method Binding Chapter 9. Object Oriented Programming Skipping most of this chapter Focus on 9.4, Dynamic method binding – Polymorphism.
Inheritance in the Java programming language J. W. Rider.
Introduction to Object Oriented Programming CMSC 331.
1 COMP313A Programming Languages Object Oriented Progamming Languages (3)
Data Structures Using C++ 2E1 Inheritance An “is-a” relationship –Example: “every employee is a person” Allows new class creation from existing classes.
Chapter 12 Support for Object oriented Programming.
Introduction to c++ programming - object oriented programming concepts - Structured Vs OOP. Classes and objects - class definition - Objects - class scope.
8. Inheritance “Is-a” Relationship. Topics Creating Subclasses Overriding Methods Class Hierarchies Abstract Class Inheritance and GUIs The Timer Class.
Object-Oriented Programming Chapter Chapter
(1) ICS 313: Programming Language Theory Chapter 12: Object Oriented Programming.
OOPs Object oriented programming. Abstract data types  Representationof type and operations in a single unit  Available for other units to create variables.
CS-1030 Dr. Mark L. Hornick 1 Basic C++ State the difference between a function/class declaration and a function/class definition. Explain the purpose.
ISBN Object-Oriented Programming Chapter Chapter
Copyright © 2005 Elsevier Object-Oriented Programming Control or PROCESS abstraction is a very old idea (subroutines!), though few languages provide it.
Classes, Interfaces and Packages
1 Lecture 23: Dynamic Binding (Section ) CSCI 431 Programming Languages Fall 2002 A compilation of material developed by Felix Hernandez-Campos.
ISBN Chapter 12 Support for Object-Oriented Programming.
Design issues for Object-Oriented Languages
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Object-Oriented Programming
Principles of programming languages 10: Object oriented languages
Polymorphism in Methods
Inheritance Chapter 7 Inheritance Basics Programming with Inheritance
Abstract Data Types and Encapsulation Concepts
Object-Oriented Programming (OOP) Lecture No. 45
Chapter 9 :: Data Abstraction and Object Orientation
Exceptions, Interfaces & Generics
Review: Two Programming Paradigms
Chapter 3: Using Methods, Classes, and Objects
11.1 The Concept of Abstraction
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Object-Orientated Programming
Types of Programming Languages
Copyright © 2009 Elsevier Chapter 9 :: Data Abstraction and Object Orientation Programming Language Pragmatics Michael L. Scott.
Object Oriented Programming
Lecture 9 Concepts of Programming Languages
Abstract Data Types and Encapsulation Concepts
Inheritance Basics Programming with Inheritance
Chapter 9 :: Data Abstraction and Object Orientation
OOP and ADTs Chapter 14 Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved.
Corresponds with Chapter 7
Abstract Data Types and Encapsulation Concepts
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin.
More Object-Oriented Programming
Chapter 9 :: Data Abstraction and Object Orientation
Computer Programming with JAVA
Support for Object-Oriented Programming
Introduction to Data Structure
Programming Languages and Paradigms
Lecture 10 Concepts of Programming Languages
Chapter 10 :: Object Orientated Programming
C++ Object Oriented 1.
SPL – PS3 C++ Classes.
Lecture 9 Concepts of Programming Languages
Chapter 11 Abstraction - The concept of abstraction is fundamental in
Presentation transcript:

Parameter Passing Actual vs formal parameters Actual: what is actually passed Formal: argument declared in subroutine header Call by value (always in C, Java) Pass address to change value Call by reference (sometimes in C++)

Issues In Parameter Passing Function names as parameters Conformant arrays – shape resolved at run time Optional parameters (e.g. C++) Named parameters (order unimportant) Variable arglist ( in C)

Templates You write one generic class, this code generates whatever classes are needed E.g. STL (standard template library), ATL (active template library)

Exceptions Problem: How to handle “unexpected” things happening in your program, e.g.: Arithmetic overflow/underflow Divide by zero File open-error, read-error, write-error, end of file error Null pointer exception Out of memory error Index out of range Segment fault, etc.

Exceptions Exceptions in C++ Exceptions in Java Exception hierarchy

Exceptions Implementation Simplest: Maintain stack of handlers, one frame for each try..catch section Push when enter “try”, pop when leave Expensive: cost incurred even if no exceptions encountered More efficient: Generate table of protected sections with handlers Lookup only when exception occurs

History of object-oriented languages Simula 67: Encapsulation in “class” definition Smalltalk-80: Xerox PARC: First true object oriented language (Alan Kay) C++: First widely accepted object-oriented language (initially was only a preprocessor) C++, Ada95, Modula-3, CLOS: added object-orientation to existing languages Java: Object model derived from C++, simplified, improved

Procedural versus object oriented programming Object orientation changes the focus of programming from algorithms to data structures: The logical organization of data determines the organization of software The software design process centers on the organization of data and the definition of the operations applied to the data “data type” is now embodied in “class”

Abstract data types The notion of an class replaces data type. An object is an instance of a class Classes contain both methods and data elements The representation of the type and the operations on it are contained in the class The actual implementation is hidden

Inheritance Is-a relationship between classes E.g. sophomore is-a student is-a person Derived classes, subclasses Single versus multiple inheritance Abstract base classes: Classes that have no actual instances, Subclasses must implement methods Java: interface (like an abstract base class with no implementation)

Encapsulation A class provides information-hiding: Private: Only class members can access Protected: class members and child class members can access Public: all classes can access

Dynamic method binding When you invoke a method on an object, it can use the method from any parent class in the class hierarchy This can be dynamic or static: Static: Uses class of pointer/reference This is C++ Default Dynamic: Uses class of actual object This is Java default

Static vs Dynamic binding class person; class student : public person { … } class professor : public person { … } student s; professor p; person *x = s, *y = p; x->print_mailing_label(); y->print_mailing_label(); Dynamic: invokes student/prof method Static: invokes person method

Inheritance Single Inheritance Multiple Inheritance Shared Inheritance Replicated Inheritance Mix-In Inheritance