Conformance Flashcards

1
Q

What is the meaning of the “Same or better” principle?

A

An overriding method should have at least the same functionality as the overridden method.
Namely:
Overriding should not pose surprises to client

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

What is the liskov substitution principle?

A

functions that use pointers or references to base classes
must be able to use objects of derived classes -
without knowing it!

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

What’s the meaning of no-variance?

A

The argument’s type cannot be changed

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

What’s the meaning of Covariance?

A

Change argument’s type in the same direction as the inheritance direction

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

What’s the meaning of Contravariance?

A

Change argument’s type in the opposite direction of the inheritance direction

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

is function arguments covariance safe?

A

No.

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

is function arguments contravariance safe?

A

Yes

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

is return type covariance safe?

A

yes

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

How variance works in c++ and java?

A
return type - covariance
arguments - no-variance
If a method has a covariant argument, It does not override the “old” method
in java: overloading
in c++: hiding
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What’s the diffrence between java, smalltalk and c++ regarding access conformance?

A

smalltalk - all methods are public.
java - can only improve visibility in a subtype
c++ - not enforced.

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

What does design by contract means?

A
A method can declare pre-conditions
-   Expected arguments values
A method can declare post-conditions
-    Guaranteed return value
A class can declare invariants
-   Object’s state (when stable)
Contract is checked at run time
-   Like an assert – exception thrown upon failure
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the conformance in design by contract?

A

Pre-condition Conformance-
Overriding method must demand the same or less from its client (preconditions are or’ed).

Post-condition Conformance-
Overriding method must ensure the same or more to its client (post-conditions are and’ed).

Invariants Conformance-
Derived must keep Base invariants; can add invariants guarding any newly introduced fields.

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