OOPs Object oriented programming. Based on ADT principles  Representation of type and operations in a single unit  Available for other units to create.

Slides:



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

INHERITANCE BASICS Reusability is achieved by INHERITANCE
METHOD OVERRIDING 1.Sub class can override the methods defined by the super class. 2.Overridden Methods in the sub classes should have same name, same.
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.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
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
1 Chapter 6 Inheritance, Interfaces, and Abstract Classes.
1 Chapter 12 © 2002 by Addison Wesley Longman, Inc Introduction - Categories of languages that support OOP: 1. OOP support is added to an existing.
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.
CPS 506 Comparative Programming Languages
Principles of Computer Programming (using Java) Review Haidong Xue Summer 2011, at GSU.
Programming Languages and Paradigms Object-Oriented Programming.
ISBN Chapter 12 Support for Object-Oriented Programming.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
CS 403 – Programming Languages Class 25 November 28, 2000.
Object Oriented Programming: Java Edition By: Samuel Robinson.
Java Implementation: Part 3 Software Construction Lecture 8.
Features of Object Oriented Programming Lec.4. ABSTRACTION AND ENCAPSULATION Computer programs can be very complex, perhaps the most complicated artifact.
Inheritance in the Java programming language J. W. Rider.
Introduction to Object Oriented Programming CMSC 331.
Chapter 12 Support for Object oriented Programming.
Chapter 3 Inheritance and Polymorphism Goals: 1.Superclasses and subclasses 2.Inheritance Hierarchy 3.Polymorphism 4.Type Compatibility 5.Abstract Classes.
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.
Lecture 10 Concepts of Programming Languages Arne Kutzner Hanyang University / Seoul Korea.
Chapter 12 Support for Object-Oriented Programming.
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.
Object Oriented Programming
3C-1 Purity Typing Language semantics Inheritance model  Single vs. Multiple inheritance  Common root Modular mechanisms Generics Object Oriented Languages.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 9 Java Fundamentals Objects/ClassesMethods Mon.
1 COSC2007 Data Structures II Chapter 9 Class Relationships.
ISBN Object-Oriented Programming Chapter Chapter
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Inheritance and Class Hierarchies Chapter 3. Chapter Objectives  To understand inheritance and how it facilitates code reuse  To understand how Java.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
 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.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 10 Java Fundamentals Objects/ClassesMethods.
Object Oriented Programming in Java Habib Rostami Lecture 2.
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.
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
Modern Programming Tools And Techniques-I
12.1 Introduction - Categories of languages that support OOP:
Support for Object-Oriented Programming
Support for Object-Oriented Programming
Inheritance and Polymorphism
Object Oriented Programming in Java
Types of Programming Languages
Names, Binding, and Scope
Java Programming Language
Object-Oriented Programming
The Procedure Abstraction Part V: Run-time Structures for OOLs
Advanced Programming Behnam Hatami Fall 2017.
Support for Object-Oriented Programming
Java Inheritance.
Support for Object-Oriented Programming
Lecture 10 Concepts of Programming Languages
Presentation transcript:

OOPs Object oriented programming

Based on ADT principles  Representation of type and operations in a single unit  Available for other units to create variables of the type  Possibility of hiding data structure of type and implementation of operations

Limitations of ADT --> OOP extensions  Software reuse: ADTs too rigid --> inheritance  No structure to collections of ADTs --> inheritance OOP provides class hierarchies

The three* hierarchies of OOP  Inheritance: 1 - n  Instantiation 1 - n  Composition 1 - n superclass subclass class instance object instance variable * Not including interfaces

Inheritance  Superclass – subclass Subclass inherits all methods, variables Subclass can add methods, variables Subclass can overwrite all methods, variables -> increased reusability -> structure collections of classes

Access to variables and methods  ADTs – public (global scope) or private (class scope)  Objects - public or private -plus protected (class plus subclasses)? Design decision: info hiding vs efficiency  Java adds package scope

Scope and objects - java looking for a variable while executing a method: block, local, instance, class extensions: inner class, package, inheritance public, protected, private

superclass w class z instance x Scope & objects in java block t class Nest extends Bird { int x=10; static int z=0; void doIt(int q) { int r = 100; { int t = r+x+z+q+w; } class Nest extends Bird { int x=10; static int z=0; void doIt(int q) { int r = 100; { int t = r+x+z+q+w; } looking for a variable while executing a method: 1.block, 2.local, 3.instance, 4.class, 5.superclass w in superclass, either protected or public, may be static method r,q

Scope and objects - java extensions: inner class - static scoping protected, private, public(looking inward) packages  access to classes, methods, public variables  importing

Inheritance rules  Single inheritance (Smalltalk) – subclass has only one superclass; classes form an inheritance tree  Multiple inheritance (C++) – subclass can have multiple superclasses  Single inheritance plus interfaces (Java)

Need for multiple inheritance  ‘orthogonal’ properties – the ‘diamond’ problem Vehicle GMVehicleKiaVehicle GMCarGMSUVKiaCarKiaSUV Vehicle CarSUV GMCarGMSUVKiaCarKiaSUV Car, SUV properties repeated Manufacturer properties repeated

Using multiple inheritance Vehicle KiaVehicleGMVehicleCarSUV GMCarGMSUVKiaCarKiaSUV

Problems of multiple inheritance  Identifier conflict: Class Super1 int x, y Class Super2 double x, z Class Sub extends Super1, Super2 Which x?

Interfaces solve the multiple inheritance problem  No variables in interfaces  No method implementations in interfaces – only protocols BUT  Weaker inheritance – no gain in code reuse

Type checking  none (Smalltalk typeless) message compatibility  subclasses are subtypes* type compatibility – object of subtype can be assigned to identifier declared of superclass type dynamic type checking provides polymorphism

Polymorphism in method calls class Super method x() class Sub1 method x() class Sub3 method x() class Sub2 Super a,b,c,d; a = new Super(); b = new Sub1(); c = new Sub2(); d = new Sub3(); a.x(); b.x(); c.x(); d.x(); Super a,b,c,d; a = new Super(); b = new Sub1(); c = new Sub2(); d = new Sub3(); a.x(); b.x(); c.x(); d.x();

Polymorphism means dynamic type checking  class of object must be determined at run time methods bound to messages dynamically parameters type checked dynamically BUT  protocol can be verified statically -> purpose of abstract methods

Forced static binding  if a method cannot be overridden, it can be statically bound C++ assumes methods cannot be overridden -> statically bound – virtual keyword causes dynamic binding Java (and Objective C) assumes methods can be overridden -> dynamic binding – final keyword allows static binding

Implementing dynamic method invocation Superclass method table (VMT) -methA -methB Superclass method table (VMT) -methA -methB Subclass method table (VMT) -methA -methC Ref to parent VMT Subclass method table (VMT) -methA -methC Ref to parent VMT Superclass var1; var1 = new Subclass(); var1.methA(); var1.methB(); var1.methC(); // compile error var1 Instance vars; Ref to class VMT Instance vars; Ref to class VMT

Allocation and de-allocation  What kinds of object memory allocation? Static Stack-dynamic Heap-dynamic  Heap reclamation Programmer control Garbage collection C++Smalltalk,Java X X

C++  Access: Classes private, public Members private, public, protected  Extending class can change access Override access to members in parent Valuable for ‘narrowing’ access polymorphism problem List StackQueue Remove some access

C++  Inheritance – partial – no single hierarchy  Efficient but complex

Java  Closer to pure object language than C++ No functions Dynamic by default One hierarchy of classes BUT  Imperative statements  Primitive data types are not objects

Smalltalk - pure OOP  every statement is a message with an object recipient and method invocation

Another ‘object’ model  Property lists / attribute-value pairs E.g., Lisp symbols: property list E.g., Javascript objects: hash table Properties are typeless – data and methods Set of properties is dynamically varying Ideally suited to tabulation – visual programming Are they objects? ADTs? Variant records?