OOP Final Flashcards
polymorphic
one name and many different meanings
Overloading
ad hoc polymorphism
one name that refers to two or more different implementations. Must share the same method name.
i.e. occurs within the context of the parent class/child class relationship
Overriding
inclusion polymorphism
A child class redefining a method inherited from a parent class. Must maintain the same method signature
i.e. single function name (or method name) has several alternative implementations
Overloaded method binding
distinguished at compile time based on their type signatures
Polymorphic variable
variable that can hold different types of values during the course of execution
Pure polymorphism
when a polymorphic variable is used as a parameter
Generics (Templates)
A way of creating general tools or classes by parameterizing on types
i.e. leaves types of methods & classes unspecified to be used in wider range of situations
Inheritance & composition
Types of software reuse
Goal of polymorphism
Facilitates reuse of standard software components that leads to:
rapid development
reliability
ease of use
inheritance
is-a relationship
composition
has-a relationship
Using Composition
Everything must be redefined while leveraging an existing software component in the creation of a new application
i.e. Set and List are unique data structures but Set can be reimplemented completed using List class
Composition class hierarchy
no explicit or implicit claims about substitution.
i.e. Set and List are distinct and neither can be substituted in situations where the other is required
Using Inheritance
Declare a new class as a child of an existing class. Thus, all data areas and functions associated with the original class are automatically associated with the new data abstraction.
Composition Advantages
- simpler, and clearly indicates what operations are provided
- Easier to change underlying details (change data representation)
Inheritance Advantages
- shorter code from code reuse
- possibly increased functionality
- slight advantage in execution time
Inheritance Disadvantages
- Can be difficult to understand what behavior is provided
- May introduce unintended usage of behavior
i.e. programmer must understand a class constructed using inheritance and the parent class (yo-yo problem - flipping back and forth between two or more classes)
Polymorphism Mechanisms
Overloading
Overriding
Polymorphic Variable
Generics