Docsity

OOP - Mod 3 - Inheritance, Lecture notes of Programming Paradigms

Toggle sidebar
bg1
OOP – Mod 3
Inheritance
Object Families/Hierarchy
➢ the idea of passing down characteristics from parent to child, and plays an
important part in Object-oriented design and programming.
Generalization/Specification
➢ Classification – hierarchic
o A person may be an employee, a customer or a supplier
o An employee may be paid monthly, weekly, or hourly
o An hourly-paid employee may be a driver, a cleaner, or a sales assistant
➢ As you go up, more general. As you go down, more specific.
➢ Keyword for inheritance
➢ Keyword for superclass
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download OOP - Mod 3 - Inheritance and more Lecture notes Programming Paradigms in PDF only on Docsity!

Inheritance

Object Families/Hierarchy ➢ the idea of passing down characteristics from parent to child, and plays an important part in Object-oriented design and programming. Generalization/Specification ➢ Classification – hierarchic o A person may be an employee, a customer or a supplier o An employee may be paid monthly, weekly, or hourly o An hourly-paid employee may be a driver, a cleaner, or a sales assistant ➢ As you go up, more general. As you go down, more specific. ➢ Keyword for inheritance ➢ Keyword for superclass

Enumeration

Polymorphism

Object Polymorphism

  • Polymorphism - one of the benefits of Inheritance; poly – meaning many, and morphe – meaning form.
  • Inheritance lets us inherit attributes and methods from another class. Polymorphism uses those methods to perform different tasks. This allows us to perform a single action in different ways. - the use of a single symbol to represent multiple different types.
  • Major classes of polymorphism o Ad Hoc Polymorphism 1. Static polymorphism (Overloading) 2. Dynamic polymorphism (Overriding) o Inclusion Polymorphism – subtyping; a subtype is a datatype that is related to another datatype (the supertype) by some notion of substitutability - program elements, typically subroutines or functions,written to operate on elements of the supertype can also operate on elements of the subtype. o Parametric polymorphism - enables the generic definition of functions and types, without a great deal of concern for type-based errors. - way to make a language more expressive, while still maintaining full static type-safety.

EXAMPLES 2:

Inclusion or Subtyping Limitations : Employee cannot access to PartimeEmployee Objects Advantage: Create multiple objects

Parametric Polymorphism