final Flashcards
(126 cards)
what are the 9 forms of inheritance?
- specialization
- specification
- construction
- generalization
- extension
- limitation
- containment
- variance
- combination
Forms of Inheritance
what is specialization?
- subclass is a specialized form
- subclass may add more or override parent methods
eg. Honda is a Car
In JavaScript how are constants made? How are they accessed?
Constants are made by making a method with “get”
Class constants use the static keyword and are accessed using the name of the constructor.
eg. static get COST_FACTOR() { return 1.5; }
ClassName.COST_FACTOR();
this.constructor.COST_FACTOR; //can also do this
Forms of Inheritance
what is specification?
used to guarantee common methods of interaction
- parent is used to describe required behaviour, using abstract methods
- focus is filling the holes left incomplete by the parent
what is the principle of substitution?
(aka the Liskov Substitution Principle)
If we have 2 classes A and B such that B is a subclass of A: it should be possible to substitute instances of class B for instances of class A in any situation with no observable effect
Interfaces can be seen as a form of inheritance. Which one?
specification
Forms of Inheritance
what is construction?
Child inherits most or all of its functionality from parent, making changes to the behaviour to build/construct something different
- Principle of substitution does NOT hold
- Subclass is not a subtype, can’t be substituted
The whole idea of an object is to provide ___________ of the representation of the state and behaviours of something
It’s very important to be able to hide implementation details
- if an object defines a field, it should …
- don’t assume subclasses will…
- these things lead to increased…
encapsulation
- define how it can be used/accessed/modified
- use it properly
- independence and reliability
Forms of Inheritance
what is generalization?
A subclass modifies the behaviour of the parent to make a more GENERAL kind of object (opposite of specialization)
- generally want to avoid this
C++
class X: {}
- public: visible to…
- private: visible only to…
- protected: visible in…
- public: visible to any user of a class X object
- private: visible only to X’s own member functions
- protected: visible in X’s member functions and member functions of subclasses of X
Forms of Inheritance
what is extension?
Extension only adds new methods to those of the parent, rather than overriding anything (inherited behaviour does not change)
Why use private at all when protected seems to give us what we want?
Private gives us better security and reliability, and better control of data locally
protected gives away too much power
nothing stopping subclasses from managing the data/methods in unintended ways
Forms of Inheritance
what is limitation?
- Behaviour of subclass is smaller or more restrictive than parent (excludes some operations)
which one of these is done by default if no access modifier is used?
class B: public A
class B: private A
class B: protected A
private
In C++, The status of the base class defines…
what the status of its members are in the inherited class*
*status only changes if it’s getting more strict
Forms of Inheritance
what is containment?
has-a relationship
private inheritance is essentially a ______ relationship
has-a
private and protected inheritance do not allow…
substitution / polymorphism
Forms of Inheritance
what is variance?
2 or more classes have similar implementations but don’t seem to have a hierarchical relationship between the abstract concepts they represent.
We arbitrarily pick one to be the subclass of the other
solution is to create a new class that they both relate to
C++ Friendship
friends have access to…
the class’ private members and makes it part of the object’s scope (allowing it to use the object’s members)
class Node {
friend class GenericList;
}
* all of GenericList’s members are now friends of Node and can access…
Node’s private members
If class B is a friend of class A, who decides that?
Class A.
the class giving up control of its members is the class that defines who its friends are
Friendship is NOT:
* __________
* __________ (the friend of my friend is not my friend!)
* __________
- inherited
- transitive
- reciprocal
Forms of Inheritance
what is combination?
A class requires a combination of features from >=2 parent classes
- This requires multiple inheritance