1. | List and describe the preferred characteristics of an object-oriented architecture. |
|
2. | State the definition of the Liskov substitution principle. |
|
3. | Define the term class invariant. |
|
4. | What is the purpose of a method precondition? |
|
5. | What is the purpose of a method postcondition? |
|
6. | List and describe the three rules of the substitution principle. |
|
7. | Write the definition and goals of the open-closed principle. |
|
8. | Explain how the open-closed principle uses the Liskov substitution principle and Meyer design by contract programming to achieve its goals. |
|
9. | Write the definition and goals of the dependency inversion principle. |
|
10. | Explain how the dependency inversion principle builds upon the open-closed principle and the Liskov substitution principle/Meyer design by contract programming. |
|
Answers
1. | - easy to understand, easy to reason about, easy to extend |
2. | - Subtype objects must be behaviorally substitutable for supertype objects. Programmers must be able to reason correctly about and rely upon the behavior of subtypes using only the supertype behavior specification. |
3. | - A class invariant is an assertion about an object property that must hold true for all valid states an object can assume. |
4. | - A precondition is an assertion about some condition that must be true before a method can be expected to perform its operation correctly. |
5. | - A postcondition is an assertion that must hold true when a method completes its operations and returns to the caller. |
6. | - Signature rule, methods rule, properties rule |
7. | - Software modules must be designed and implemented in a manner that opens them for extension but closes them for modification. |
8. | - The key to writing code that conforms to the open-closed principle is to depend upon abstractions, not upon implementations. The reason — abstractions tend to be more stable. (Correctly designed abstractions are very stable!) This is achieved in Java through the use of abstract base classes or interfaces and dynamic polymorphic behavior. Code should rely only upon the interface methods and behavior promised via abstract methods. A code module that relies only upon abstractions will exhibit the characteristic of being closed to the need for modification yet open to the possibility of extension. |
9. | - A. High-level modules should not depend upon low-level modules. Both should depend upon abstractions. - B. Abstractions should not depend upon details. Details should depend upon abstractions. |
10. | - The key to success with the DIP lies in choosing the right software abstractions. A software architecture based upon the right kinds of abstractions will exhibit the desirable characteristic of being easy to extend. It will be flexible because of its extensibility, it will be non-rigid in that the addition of new functionality via new derived classes will not affect the behavior of existing abstractions. Lastly, software modules that depend upon abstractions can generally be reused in a wider variety of contexts, thus achieving a greater degree of mobility. |