More Object-Oriented Programming

Slides:



Advertisements
Similar presentations
OBJECT ORIENTED PROGRAMMING M Taimoor Khan
Advertisements

1 Object-Oriented Programming (Section ) CSCI 431 Programming Languages Fall 2003 A compilation of material developed by Felix Hernandez-Campos.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Data Abstraction and Object- Oriented Programming CS351 – Programming Paradigms.
Comparison of OO Programming Languages © Jason Voegele, 2003.
Programming Languages and Paradigms Object-Oriented Programming.
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.
CSM-Java Programming-I Spring,2005 Objects and Classes Overview Lesson - 1.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
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.
CS212: Object Oriented Analysis and Design Lecture 5: Classes and Objects - II.
Introduction to c++ programming - object oriented programming concepts - Structured Vs OOP. Classes and objects - class definition - Objects - class scope.
Abstraction ADTs, Information Hiding and Encapsulation.
Lecture 10 Concepts of Programming Languages Arne Kutzner Hanyang University / Seoul Korea.
Chapter 12 Support for Object-Oriented Programming.
Object-Oriented Programming Chapter Chapter
Object Oriented Programming
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.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Lecture 2: Review of Object Orientation. © Lethbridge/La ganière 2005 Chapter 2: Review of Object Orientation What is Object Orientation? Procedural.
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.
C++ General Characteristics: - Mixed typing system - Constructors and destructors - Elaborate access controls to class entities.
Copyright © 2009 Elsevier Chapter 9 :: Data Abstraction and Object Orientation Programming Language Pragmatics Michael L. Scott.
1 C++ Classes & Object Oriented Programming Overview & Terminology.
ISBN Chapter 12 Support for Object-Oriented Programming.
Chapter 11: Abstract Data Types Lecture # 17. Chapter 11 Topics The Concept of Abstraction Advantages of Abstract Data Types Design Issues for Abstract.
Java Programming Fifth Edition Chapter 9 Introduction to Inheritance.
Introduction to Object-oriented Programming
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Object-Oriented Programming
Data Abstraction: The Walls
Object-Oriented Programming Concepts
Names and Attributes Names are a key programming language feature
CS 3304 Comparative Languages
Abstract Data Types and Encapsulation Concepts
Support for Object-Oriented Programming
Chapter 9 :: Data Abstraction and Object Orientation
Inheritance and Polymorphism
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING (OOP) & CONCEPTS
Nested class.
Inheritance "Question: What is the object oriented way of getting rich? Answer: Inheritance.“ “Inheritance is new code that reuses old code. Polymorphism.
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
Names, Binding, and Scope
Chapter 9 :: Data Abstraction and Object Orientation
Abstract Data Types and Encapsulation Concepts
Java Programming Language
Lecture 22 Inheritance Richard Gesick.
Object-Oriented Programming
The Procedure Abstraction Part V: Run-time Structures for OOLs
Advanced Java Programming
Chapter 9 :: Data Abstraction and Object Orientation
Polymorphism Polymorphism
Object Oriented Programming
Parameter Passing Actual vs formal parameters
Java Programming, Second Edition
Support for Object-Oriented Programming
Object-Oriented Programming
Object-Oriented PHP (1)
Lecture 10 Concepts of Programming Languages
Chapter 10 :: Object Orientated Programming
C++ Object Oriented 1.
Lecture 9 Concepts of Programming Languages
Chapter 11 Abstraction - The concept of abstraction is fundamental in
Presentation transcript:

More Object-Oriented Programming www.bookspar.com | Website for students | VTU NOTES C H A P T E R S E V E N More Object-Oriented Programming

www.bookspar.com | Website for students | VTU NOTES Modules First introduced scope rules for data hiding. Public part consists of variables and functions that are visible outside of the module. Private part consists of variables and functions visible only within the module. Modules may span multiple compilation units (files). Modules generally lack any inheritance mechanism.

www.bookspar.com | Website for students | VTU NOTES Why OO-Programming? Reduces conceptual load by reducing amount of detail Provides fault containment Can’t use components (e.g., a class) in inappropriate ways Provides independence between components Design/development can be done by more than one person

www.bookspar.com | Website for students | VTU NOTES The Evolution of OOPS Global Variables -lifetime spans program execution. Local Variables - lifetime limited to execution of a single routine. Nested Scopes - allow functions to be local. Static Variables - visible in single scope. Modules - allow several subroutines to share a set of static variables. Module Types - multiple instances of an abstraction. Classes - families of related abstractions.

www.bookspar.com | Website for students | VTU NOTES Keys to OO Programming An instance of a class is know as an Object. Languages that are based on classes are know as Object-Oriented. Eiffel C++ Modula-3 Ada 95 Java

www.bookspar.com | Website for students | VTU NOTES Keys to OO Programming Encapsulation (data hiding) Enable programmer to group data & subroutines (methods) together, hiding irrelevant details from users Inheritance Enable a new abstraction (i.e., derived class) to be defined as an extension of an existing abstraction, retaining key characteristics Dynamic method binding Enable use of new abstraction (i.e., derived class) to exhibit new behavior in context of old abstraction

www.bookspar.com | Website for students | VTU NOTES Initialization & Finalization of Objects Choosing a constructor How are constructors supported in the language? References and values Value model  object creation results from elaboration Execution order of initialization E.g., with derived classes Garbage Collection? Don’t need destructors!

www.bookspar.com | Website for students | VTU NOTES Initialization & Finalization of Objects C++ automatically calls constructors for base classes before current constructor Base class members can be explicitly initialized using foo::foo (foo args) : bar (bar args), member1 (m1 args), member2 (m2 args) { … } Use of this syntax results in call to copy constructor rather than 0-arg constructor followed by operator= Java, like C++, by default calls 0-argument versions of base class constructors Call to super (args) overrides 0-arg version Smalltalk, Eiffel, and CLOS only initialize base class data members to null.

www.bookspar.com | Website for students | VTU NOTES Classes www.bookspar.com | Website for students | VTU NOTES Extends the scope rules of modules to include inheritance. Should private members of a base class be visible in derived classes? Should public members of a base class always be public members of a derived class. How much control should a base class have over its members in derived classes?

www.bookspar.com | Website for students | VTU NOTES Yikes! Huge families of classes are used to implement language features. This is from Smalltalk-80.

www.bookspar.com | Website for students | VTU NOTES C++ Classes www.bookspar.com | Website for students | VTU NOTES Any class can limit the visibility of its members: Public members are visible anywhere the class is in scope. Private members are visible only within the class’s methods. Protected members are visible inside members of the class and derived classes. Friend classes are granted exceptions to (some) of the rules.

www.bookspar.com | Website for students | VTU NOTES C++ Classes www.bookspar.com | Website for students | VTU NOTES Derived classes can further restrict visibility of base class members, but not increase it: Private members of a base class are never visible in a derived class. Protected and public members of a public base class are protected or public, respectively, in a derived class. Protected and public members of a protected base class are protected members of a derived class. Protected and public members of a private base class are private members of a derived class.

www.bookspar.com | Website for students | VTU NOTES C++ Classes www.bookspar.com | Website for students | VTU NOTES Derived classes that limit visibility of base class members can restore visibility by inserting a using declaration in its protected or public sections. Rules in other languages can be significantly different.

Dynamic Method Binding www.bookspar.com | Website for students | VTU NOTES

www.bookspar.com | Website for students | VTU NOTES Member Lookup www.bookspar.com | Website for students | VTU NOTES

www.bookspar.com | Website for students | VTU NOTES Virtual Methods www.bookspar.com | Website for students | VTU NOTES

www.bookspar.com | Website for students | VTU NOTES Inheritance www.bookspar.com | Website for students | VTU NOTES

www.bookspar.com | Website for students | VTU NOTES Multiple Inheritance www.bookspar.com | Website for students | VTU NOTES

www.bookspar.com | Website for students | VTU NOTES Multiple Inheritance www.bookspar.com | Website for students | VTU NOTES

Replicated Inheritance www.bookspar.com | Website for students | VTU NOTES

Replicated Inheritance www.bookspar.com | Website for students | VTU NOTES

Shared Multiple Inheritance www.bookspar.com | Website for students | VTU NOTES “A new opportunity for ambiguity and additional implementation complexity”

Shared Multiple Inheritance www.bookspar.com | Website for students | VTU NOTES

www.bookspar.com | Website for students | VTU NOTES Mixed Inheritance www.bookspar.com | Website for students | VTU NOTES A base class composed entirely of abstract methods is called an interface (at least in Java). It has no data nor implements any methods. Inheritance from one real base class and any number of interfaces is called mixed inheritance. Virtual methods of the interface(s) are “mixed into” the methods of the derived class.

www.bookspar.com | Website for students | VTU NOTES Mixed Inheritance www.bookspar.com | Website for students | VTU NOTES

www.bookspar.com | Website for students | VTU NOTES Summary www.bookspar.com | Website for students | VTU NOTES Object Oriented Programming has become an important mainstay of software development. OOP language implementation trades off functionality and “purity” on one hand and simplicity and speed on the other. Treating variables as references rather than static values requires simpler semantics but imposes runtime performance costs due to extra indirection.

www.bookspar.com | Website for students | VTU NOTES Summary www.bookspar.com | Website for students | VTU NOTES Garbage collection makes programming easier but has high run-time costs. Dynamic method binding requires the use of vtables or other lookup mechanism. Multiple inheritance adds extra complexity to the vtable mechanism (even if unused). Shared multiple inheritance adds even more indirection and run-time cost. In-line subroutines can greatly improve performance at the cost of program size.

www.bookspar.com | Website for students | VTU NOTES Summary www.bookspar.com | Website for students | VTU NOTES Smalltalk is considered the “purest” OO language even though it lacks multiple inheritance. Because it is slow it is rarely used in a commercial setting. C++ is most widely used because it has default static binding, minimal dynamic checks, and some very good compilers. Java is more of a niche player, scoring strongly in the internet and portable interface realms. It also tends to be slow.

Functional Programming www.bookspar.com | Website for students | VTU NOTES Next time… Functional Programming