Variations on Inheritance Flashcards

1
Q

What’s an abstract class?

A

A class that cannot be instantiated

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Can abstract classes have constructors?

A

yes. if a concrete class derives from the abstract, when constructing the concrete class we need to construct the abstract class first.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What’s an abstract method?

A

a method without implementation, postponed to inheriting class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What’s the difference between pure virtual function in c++ and an abstract method in java or c#?

A

PVF: may have implementation

abstract method: doesn’t have implementation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What’s the difference between interface and abstract class in Java?

A

Interface:
only abstract methods and const definitions.
pure protocol specification.

Abstract class:
methods may have default implementation.
every class with an abstract method is abstract.
not every abstract class has an abstract method.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What’s a final method?

A

cannot be overridden

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What’s a final class?

A

cannot be further derived

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What’s multiple dispatch?

A

the executed method is selected by the dynamic type of one (or more) argument(s)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What’s MultiMethod?

A

a method that takes part in multiple dispatch

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are the Drawbacks of MultiMethods?

A
  • Expensive dispatch process
    Must examine dynamic types of all arguments
  • Possible run time ambiguity
    Given A::f(A, A), B::f(B, A) and B::f(A, B)
    What happens if you pass two B’s to A::f?
  • Can get the same functionality in standard Java
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is a binary method?

A

a method that takes as an argument a parameter of the same type as the class the method is declared in.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How mixins are implemented in c++?

A
Using templates.
let's say we want to add an undo functionality to different classes.
let's use a mixin:
typedef UndoableMixin UndoableInt;
typedef UndoableMixin Undoable char;

the new functionality will be in UndoableMixin.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are the drawbacks of c++’s mixins?

A

mixin is not a class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the drawback of mixins in java?

A

Adding a method to a mixin may silently override an inherited method

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What’s a trait?

A
A composable unit of behavior.
Serves as a type
No fields
Provides some methods (with behavior)
Requires other methods (abstract)
When composing traits, if a method has more than one implementation it becomes abstract
How well did you know this?
1
Not at all
2
3
4
5
Perfectly