SlideShare una empresa de Scribd logo
1 de 5
ICS 313 - Fundamentals of Programming Languages 1
12. Object-Oriented Programming
12.1 Introduction
Categories of languages that support OOP:
1. OOP support is added to an existing language
C++ (also supports procedural and data-oriented programming)
Ada 95 (also supports procedural and data-oriented programming)
CLOS (also supports functional programming)
Scheme (also supports functional programming)
2. Support OOP, but have the same appearance and use the basic
structure of earlier imperative languages
Eiffel (not based directly on any previous language)
Java (based on C++)
3. Pure OOP languages
Smalltalk
ICS 313 - Fundamentals of Programming Languages 2
12.2 Object-Oriented Programming
Paradigm Evolution
1. Procedural - 1950s-1970s (procedural abstraction)
2. Data-Oriented - early 1980s (data abstraction)
3. OOP - late 1980s (Inheritance and dynamic binding)
Origins of Inheritance
Observations of the mid-late 1980s :
Productivity increases can come from reuse
Unfortunately, ADTs are difficult to reuse - never quite right
All ADTs are independent and at the same level
Inheritance solves both - reuse ADTs after minor
changes and define classes in a hierarchy
12.2 Object-Oriented Programming (continued)
OOP Definitions:
ADTs are called classes
Class instances are called objects
A class that inherits is a derived class or a subclass
The class from which another class inherits is a parent class or
superclass
Subprograms that define operations on objects are called
methods
The entire collection of methods of an object is called its
message protocol or message interface
Messages have two parts - a method name and the destination
object
In the simplest case, a class inherits all of the entities of its
parent
ICS 313 - Fundamentals of Programming Languages 3
12.2 Object-Oriented Programming (continued)
Inheritance can be complicated by access controls to encapsulated entities
A class can hide entities from its subclasses
A class can hide entities from its clients
A class can also hide entities for its clients while allowing its subclasses to see them
Besides inheriting methods as is, a class can modify an inherited method
The new one overrides the inherited one
The method in the parent is overriden
There are two kinds of variables in a class:
1. Class variables - one/class
2. Instance variables - one/object
There are two kinds of methods in a class:
1. Class methods – accept messages to the class
2. Instance methods – accept messages to objects
Single vs. Multiple Inheritance
One disadvantage of inheritance for reuse:
Creates interdependencies among classes that complicate maintenance
12.2 Object-Oriented Programming (continued)
Polymorphism in OOPLs
A polymorphic variable can be defined in a class that is able to
reference (or point to) objects of the class and objects of any of
its descendants
When a class hierarchy includes classes that override methods
and such methods are called through a polymorphic variable,
the binding to the correct method MUST be dynamic
This polymorphism simplifies the addition of new methods
A virtual method is one that does not include a definition (it only
defines a protocol)
A virtual class is one that includes at least one virtual method
A virtual class cannot be instantiated
ICS 313 - Fundamentals of Programming Languages 4
12.2 Object-Oriented Programming (continued)
Design Issues for OOPLs
1. The Exclusivity of Objects
a. Everything is an object
Advantage - elegance and purity
Disadvantage - slow operations on simple objects (e.g., float)
b. Add objects to a complete typing system
Advantage - fast operations on simple objects
Disadvantage - results in a confusing type system (two kinds of entities)
c. Include an imperative-style typing system for primitives but
make everything else objects
Advantage - fast operations on simple objects and a relatively small typing system
Disadvantage - still some confusion because of the two type systems
2. Are Subclasses Subtypes?
Does an is-a relationship hold between a parent class object
and an object of the subclass?
12.2 Object-Oriented Programming (continued)
3. Implementation and Interface Inheritance
If only the interface of the parent class is visible to the subclass,
it is interface inheritance
Disadvantage - can result in inefficiencies
If both the interface and the implementation of the parent class
is visible to the subclass, it is implementation inheritance
Disadvantage - changes to the parent class require recompilation of subclasses, and
sometimes even modification of subclasses
4. Type Checking and Polymorphism
Polymorphism may require dynamic type checking of
parameters and the return value
Dynamic type checking is costly and delays error detection
If overriding methods are restricted to having the same
parameter types and return type, the checking can be static
ICS 313 - Fundamentals of Programming Languages 5
12.2 Object-Oriented Programming (continued)
5. Single and Multiple Inheritance
Disadvantages of multiple inheritance:
Language and implementation complexity (in part due to name collisions)
Potential inefficiency - dynamic binding costs more with multiple inheritance (but not much)
Advantage:
Sometimes it is extremely convenient and valuable
6. Allocation and Deallocation of Objects
From where are objects allocated?
If they all live in the heap, references to them are uniform
Simplifies assignment - dereferencing can be implicit
Is deallocation explicit or implicit?
7. Dynamic and Static Binding
Should ALL binding of messages to methods be dynamic?
If none are, you lose the advantages of dynamic binding
If all are, it is inefficient

Más contenido relacionado

La actualidad más candente

Oo abap-sap-1206973306636228-5
Oo abap-sap-1206973306636228-5Oo abap-sap-1206973306636228-5
Oo abap-sap-1206973306636228-5
prakash185645
 

La actualidad más candente (20)

Oops abap fundamental
Oops abap fundamentalOops abap fundamental
Oops abap fundamental
 
Java interface
Java interface Java interface
Java interface
 
C#, OOP introduction and examples
C#, OOP introduction and examplesC#, OOP introduction and examples
C#, OOP introduction and examples
 
Object Orinted Programing(OOP) concepts \
Object Orinted Programing(OOP) concepts \Object Orinted Programing(OOP) concepts \
Object Orinted Programing(OOP) concepts \
 
Csci360 20
Csci360 20Csci360 20
Csci360 20
 
Csci360 20 (1)
Csci360 20 (1)Csci360 20 (1)
Csci360 20 (1)
 
Interface in java By Dheeraj Kumar Singh
Interface in java By Dheeraj Kumar SinghInterface in java By Dheeraj Kumar Singh
Interface in java By Dheeraj Kumar Singh
 
EEE oops Vth semester viva questions with answer
EEE oops Vth semester viva questions with answerEEE oops Vth semester viva questions with answer
EEE oops Vth semester viva questions with answer
 
Core java questions
Core java questionsCore java questions
Core java questions
 
Abstract class in java
Abstract class in javaAbstract class in java
Abstract class in java
 
Unit 4 Java
Unit 4 JavaUnit 4 Java
Unit 4 Java
 
Ppt chapter06
Ppt chapter06Ppt chapter06
Ppt chapter06
 
Suga java training_with_footer
Suga java training_with_footerSuga java training_with_footer
Suga java training_with_footer
 
Object Oriented Programming - Basic Concepts
Object Oriented Programming - Basic ConceptsObject Oriented Programming - Basic Concepts
Object Oriented Programming - Basic Concepts
 
Lecture 18
Lecture 18Lecture 18
Lecture 18
 
Oo abap-sap-1206973306636228-5
Oo abap-sap-1206973306636228-5Oo abap-sap-1206973306636228-5
Oo abap-sap-1206973306636228-5
 
Mi0041 java and web design
Mi0041  java and web designMi0041  java and web design
Mi0041 java and web design
 
Polymorphism in java
Polymorphism in javaPolymorphism in java
Polymorphism in java
 
Inheritance
InheritanceInheritance
Inheritance
 
Automated Refactoring of Legacy Java Software to Default Methods Talk at GMU
Automated Refactoring of Legacy Java Software to Default Methods Talk at GMUAutomated Refactoring of Legacy Java Software to Default Methods Talk at GMU
Automated Refactoring of Legacy Java Software to Default Methods Talk at GMU
 

Destacado

Proporción nn Procesos Productivos
Proporción nn Procesos ProductivosProporción nn Procesos Productivos
Proporción nn Procesos Productivos
guestf83d576
 
01 c ce-–-andaime-fachadeiro-–-manual-de-montagem
01 c ce-–-andaime-fachadeiro-–-manual-de-montagem01 c ce-–-andaime-fachadeiro-–-manual-de-montagem
01 c ce-–-andaime-fachadeiro-–-manual-de-montagem
Janaina Xavier
 
Raji_new_July_2015
Raji_new_July_2015Raji_new_July_2015
Raji_new_July_2015
Raja Kumari
 

Destacado (14)

Presentación normas cacería
Presentación normas caceríaPresentación normas cacería
Presentación normas cacería
 
February wk 2
February wk 2February wk 2
February wk 2
 
Castravete ciupirea plantei
Castravete ciupirea planteiCastravete ciupirea plantei
Castravete ciupirea plantei
 
Proporción nn Procesos Productivos
Proporción nn Procesos ProductivosProporción nn Procesos Productivos
Proporción nn Procesos Productivos
 
1804.13
1804.131804.13
1804.13
 
sexe
sexesexe
sexe
 
Server Networking
Server NetworkingServer Networking
Server Networking
 
sexe
sexesexe
sexe
 
01 c ce-–-andaime-fachadeiro-–-manual-de-montagem
01 c ce-–-andaime-fachadeiro-–-manual-de-montagem01 c ce-–-andaime-fachadeiro-–-manual-de-montagem
01 c ce-–-andaime-fachadeiro-–-manual-de-montagem
 
Jf 17
Jf 17Jf 17
Jf 17
 
Masail Fiqhiyyah - Makalah Pandangan Hukum Islam Terhadap Aborsi
Masail Fiqhiyyah - Makalah Pandangan Hukum Islam Terhadap AborsiMasail Fiqhiyyah - Makalah Pandangan Hukum Islam Terhadap Aborsi
Masail Fiqhiyyah - Makalah Pandangan Hukum Islam Terhadap Aborsi
 
Raji_new_July_2015
Raji_new_July_2015Raji_new_July_2015
Raji_new_July_2015
 
Objetos que forman diferentes tipos de ángulos
Objetos que forman diferentes tipos de ángulosObjetos que forman diferentes tipos de ángulos
Objetos que forman diferentes tipos de ángulos
 
తెలుగు అచ్చులు (Telugu Achulu)
తెలుగు అచ్చులు (Telugu Achulu)తెలుగు అచ్చులు (Telugu Achulu)
తెలుగు అచ్చులు (Telugu Achulu)
 

Similar a 12 object oriented programming

Oop by edgar lagman jr
Oop by edgar lagman jr Oop by edgar lagman jr
Oop by edgar lagman jr
Jun-jun Lagman
 
Object oriented basics
Object oriented basicsObject oriented basics
Object oriented basics
vamshimahi
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Concepts
thinkphp
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
Kumar
 

Similar a 12 object oriented programming (20)

Oop
OopOop
Oop
 
Unit 3
Unit 3Unit 3
Unit 3
 
Oop by edgar lagman jr
Oop by edgar lagman jr Oop by edgar lagman jr
Oop by edgar lagman jr
 
Object oriented basics
Object oriented basicsObject oriented basics
Object oriented basics
 
Data Structure Interview Questions & Answers
Data Structure Interview Questions & AnswersData Structure Interview Questions & Answers
Data Structure Interview Questions & Answers
 
C#
C#C#
C#
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Concepts
 
OOPs in Java
OOPs in JavaOOPs in Java
OOPs in Java
 
core_java.ppt
core_java.pptcore_java.ppt
core_java.ppt
 
Abap object-oriented-programming-tutorials
Abap object-oriented-programming-tutorialsAbap object-oriented-programming-tutorials
Abap object-oriented-programming-tutorials
 
12th ip CBSE chapter 4 oop in java notes complete
12th ip CBSE  chapter 4 oop in java notes complete12th ip CBSE  chapter 4 oop in java notes complete
12th ip CBSE chapter 4 oop in java notes complete
 
Java interview questions and answers
Java interview questions and answersJava interview questions and answers
Java interview questions and answers
 
Java interview questions
Java interview questionsJava interview questions
Java interview questions
 
C# interview quesions
C# interview quesionsC# interview quesions
C# interview quesions
 
SAP ABAP Latest Interview Questions with Answers by Garuda Trainings
SAP ABAP Latest Interview Questions with Answers by Garuda TrainingsSAP ABAP Latest Interview Questions with Answers by Garuda Trainings
SAP ABAP Latest Interview Questions with Answers by Garuda Trainings
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Java Notes
Java NotesJava Notes
Java Notes
 
Unit 1 Java
Unit 1 JavaUnit 1 Java
Unit 1 Java
 
OOP Introduction with java programming language
OOP Introduction with java programming languageOOP Introduction with java programming language
OOP Introduction with java programming language
 
JavaHTP6e_10.ppt
JavaHTP6e_10.pptJavaHTP6e_10.ppt
JavaHTP6e_10.ppt
 

Más de jigeno

Basic introduction to ms access
Basic introduction to ms accessBasic introduction to ms access
Basic introduction to ms access
jigeno
 
16 logical programming
16 logical programming16 logical programming
16 logical programming
jigeno
 
15 functional programming
15 functional programming15 functional programming
15 functional programming
jigeno
 
15 functional programming
15 functional programming15 functional programming
15 functional programming
jigeno
 
14 exception handling
14 exception handling14 exception handling
14 exception handling
jigeno
 
13 concurrency
13 concurrency13 concurrency
13 concurrency
jigeno
 
11 abstract data types
11 abstract data types11 abstract data types
11 abstract data types
jigeno
 
9 subprograms
9 subprograms9 subprograms
9 subprograms
jigeno
 
8 statement-level control structure
8 statement-level control structure8 statement-level control structure
8 statement-level control structure
jigeno
 
7 expressions and assignment statements
7 expressions and assignment statements7 expressions and assignment statements
7 expressions and assignment statements
jigeno
 
6 data types
6 data types6 data types
6 data types
jigeno
 
5 names
5 names5 names
5 names
jigeno
 
4 lexical and syntax analysis
4 lexical and syntax analysis4 lexical and syntax analysis
4 lexical and syntax analysis
jigeno
 
3 describing syntax and semantics
3 describing syntax and semantics3 describing syntax and semantics
3 describing syntax and semantics
jigeno
 
2 evolution of the major programming languages
2 evolution of the major programming languages2 evolution of the major programming languages
2 evolution of the major programming languages
jigeno
 
1 preliminaries
1 preliminaries1 preliminaries
1 preliminaries
jigeno
 
Access2007 m2
Access2007 m2Access2007 m2
Access2007 m2
jigeno
 
Access2007 m1
Access2007 m1Access2007 m1
Access2007 m1
jigeno
 

Más de jigeno (20)

Access2007 part1
Access2007 part1Access2007 part1
Access2007 part1
 
Basic introduction to ms access
Basic introduction to ms accessBasic introduction to ms access
Basic introduction to ms access
 
Bsit1
Bsit1Bsit1
Bsit1
 
16 logical programming
16 logical programming16 logical programming
16 logical programming
 
15 functional programming
15 functional programming15 functional programming
15 functional programming
 
15 functional programming
15 functional programming15 functional programming
15 functional programming
 
14 exception handling
14 exception handling14 exception handling
14 exception handling
 
13 concurrency
13 concurrency13 concurrency
13 concurrency
 
11 abstract data types
11 abstract data types11 abstract data types
11 abstract data types
 
9 subprograms
9 subprograms9 subprograms
9 subprograms
 
8 statement-level control structure
8 statement-level control structure8 statement-level control structure
8 statement-level control structure
 
7 expressions and assignment statements
7 expressions and assignment statements7 expressions and assignment statements
7 expressions and assignment statements
 
6 data types
6 data types6 data types
6 data types
 
5 names
5 names5 names
5 names
 
4 lexical and syntax analysis
4 lexical and syntax analysis4 lexical and syntax analysis
4 lexical and syntax analysis
 
3 describing syntax and semantics
3 describing syntax and semantics3 describing syntax and semantics
3 describing syntax and semantics
 
2 evolution of the major programming languages
2 evolution of the major programming languages2 evolution of the major programming languages
2 evolution of the major programming languages
 
1 preliminaries
1 preliminaries1 preliminaries
1 preliminaries
 
Access2007 m2
Access2007 m2Access2007 m2
Access2007 m2
 
Access2007 m1
Access2007 m1Access2007 m1
Access2007 m1
 

Último

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 

Último (20)

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 

12 object oriented programming

  • 1. ICS 313 - Fundamentals of Programming Languages 1 12. Object-Oriented Programming 12.1 Introduction Categories of languages that support OOP: 1. OOP support is added to an existing language C++ (also supports procedural and data-oriented programming) Ada 95 (also supports procedural and data-oriented programming) CLOS (also supports functional programming) Scheme (also supports functional programming) 2. Support OOP, but have the same appearance and use the basic structure of earlier imperative languages Eiffel (not based directly on any previous language) Java (based on C++) 3. Pure OOP languages Smalltalk
  • 2. ICS 313 - Fundamentals of Programming Languages 2 12.2 Object-Oriented Programming Paradigm Evolution 1. Procedural - 1950s-1970s (procedural abstraction) 2. Data-Oriented - early 1980s (data abstraction) 3. OOP - late 1980s (Inheritance and dynamic binding) Origins of Inheritance Observations of the mid-late 1980s : Productivity increases can come from reuse Unfortunately, ADTs are difficult to reuse - never quite right All ADTs are independent and at the same level Inheritance solves both - reuse ADTs after minor changes and define classes in a hierarchy 12.2 Object-Oriented Programming (continued) OOP Definitions: ADTs are called classes Class instances are called objects A class that inherits is a derived class or a subclass The class from which another class inherits is a parent class or superclass Subprograms that define operations on objects are called methods The entire collection of methods of an object is called its message protocol or message interface Messages have two parts - a method name and the destination object In the simplest case, a class inherits all of the entities of its parent
  • 3. ICS 313 - Fundamentals of Programming Languages 3 12.2 Object-Oriented Programming (continued) Inheritance can be complicated by access controls to encapsulated entities A class can hide entities from its subclasses A class can hide entities from its clients A class can also hide entities for its clients while allowing its subclasses to see them Besides inheriting methods as is, a class can modify an inherited method The new one overrides the inherited one The method in the parent is overriden There are two kinds of variables in a class: 1. Class variables - one/class 2. Instance variables - one/object There are two kinds of methods in a class: 1. Class methods – accept messages to the class 2. Instance methods – accept messages to objects Single vs. Multiple Inheritance One disadvantage of inheritance for reuse: Creates interdependencies among classes that complicate maintenance 12.2 Object-Oriented Programming (continued) Polymorphism in OOPLs A polymorphic variable can be defined in a class that is able to reference (or point to) objects of the class and objects of any of its descendants When a class hierarchy includes classes that override methods and such methods are called through a polymorphic variable, the binding to the correct method MUST be dynamic This polymorphism simplifies the addition of new methods A virtual method is one that does not include a definition (it only defines a protocol) A virtual class is one that includes at least one virtual method A virtual class cannot be instantiated
  • 4. ICS 313 - Fundamentals of Programming Languages 4 12.2 Object-Oriented Programming (continued) Design Issues for OOPLs 1. The Exclusivity of Objects a. Everything is an object Advantage - elegance and purity Disadvantage - slow operations on simple objects (e.g., float) b. Add objects to a complete typing system Advantage - fast operations on simple objects Disadvantage - results in a confusing type system (two kinds of entities) c. Include an imperative-style typing system for primitives but make everything else objects Advantage - fast operations on simple objects and a relatively small typing system Disadvantage - still some confusion because of the two type systems 2. Are Subclasses Subtypes? Does an is-a relationship hold between a parent class object and an object of the subclass? 12.2 Object-Oriented Programming (continued) 3. Implementation and Interface Inheritance If only the interface of the parent class is visible to the subclass, it is interface inheritance Disadvantage - can result in inefficiencies If both the interface and the implementation of the parent class is visible to the subclass, it is implementation inheritance Disadvantage - changes to the parent class require recompilation of subclasses, and sometimes even modification of subclasses 4. Type Checking and Polymorphism Polymorphism may require dynamic type checking of parameters and the return value Dynamic type checking is costly and delays error detection If overriding methods are restricted to having the same parameter types and return type, the checking can be static
  • 5. ICS 313 - Fundamentals of Programming Languages 5 12.2 Object-Oriented Programming (continued) 5. Single and Multiple Inheritance Disadvantages of multiple inheritance: Language and implementation complexity (in part due to name collisions) Potential inefficiency - dynamic binding costs more with multiple inheritance (but not much) Advantage: Sometimes it is extremely convenient and valuable 6. Allocation and Deallocation of Objects From where are objects allocated? If they all live in the heap, references to them are uniform Simplifies assignment - dereferencing can be implicit Is deallocation explicit or implicit? 7. Dynamic and Static Binding Should ALL binding of messages to methods be dynamic? If none are, you lose the advantages of dynamic binding If all are, it is inefficient