Presentation is loading. Please wait.

Presentation is loading. Please wait.

Parameter Passing Actual vs formal parameters

Similar presentations


Presentation on theme: "Parameter Passing Actual vs formal parameters"— Presentation transcript:

1 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++)

2 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)

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

4 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.

5 Exceptions Exceptions in C++ Exceptions in Java Exception hierarchy

6 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

7 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

8 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”

9 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

10 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)

11 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

12 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

13 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

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


Download ppt "Parameter Passing Actual vs formal parameters"

Similar presentations


Ads by Google