
- 328 pages
- English
- ePUB (mobile friendly)
- Available on iOS & Android
Object-Oriented Design Choices
About this book
Do modern programming languages, IDEs, and libraries make coding easy? Maybe, but coding is not design. Large-scale or expensive apps clearly require evaluation of design choices. Still, software design directly impacts code reuse and longevity even for small-scale apps with limited overhead. This text evaluates and contrasts common object-oriented designs.
A given problem may have many solutions. A developer may employ different design techniques – composition, inheritance, dependency injection, delegation, etc. – to solve a particular problem. A skilled developer can determine the costs and benefits of different design responses, even amid competing concerns. A responsible developer documents design choices as a contract with the client, delineating external and internal responsibilities. To promote effective software design, this book examines contractual, object-oriented designs for immediate and sustained use as well as code reuse. The intent of identifying design variants is to recognize and manage conflicting goals such as short versus long-term utility, stability versus flexibility, and storage versus computation. Many examples are given to evaluate and contrast different solutions and to compare C# and C++ effects. No one has a crystal ball; however, deliberate design promotes software longevity. With the prominence of legacy OO code, a clear understanding of different object-oriented designs is essential.
Design questions abound. Is code reuse better with inheritance or composition? Should composition rely on complete encapsulation? Design choices impact flexibility, efficiency, stability, longevity, and reuse, yet compilers do not enforce design and syntax does not necessarily illustrate design. Through deliberate design, or redesign when refactoring, developers construct sustainable, efficient code.
Frequently asked questions
- Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
- Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.4M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app.
Information
II
Strategic Type Coupling
CHAPTER 4
Composition
CHAPTER OBJECTIVES
- Define OOD relationships
- Illustrate composition and containment
- Examine association, ownership and cardinality
- Introduce Dependency Injection
4.1OBJECT-ORIENTED RELATIONSHIPS
4.2CONTAINMENT (HOLDS-A)
push(), pop(), clear(), etc. function in the same manner regardless of the type of data processed. The type of data stored provides no functionality and has little or no effect on containers. The holds-a relationship reflects little or no type dependency.replace().// transient ownership of subobject(s) // implies memory management // => must provide destructor // => support or suppress copying class Customer // replaceable gift card
// handle only, no object yet
{ GiftCard* c = 0;
public:
// assumption constructor: ownership // of transfer assumed Customer(GiftCard*& transfer)
{ c = transfer;
transfer = 0;
}
// no argument constructor:
// no gift card allocated
Customer() { c = 0; }
// again ownership transferred in
void replace(GiftCard*& backup)
// dispose existing card
{ if (c) delete c;
c = backup;
backup = 0;
}
˜ Customer() { if (c) delete c; }
};
4.3COMPOSITION (HAS-A)
Table of contents
- Cover
- Half Title
- Title Page
- Copyright Page
- Table of Contents
- Preface
- Acknowledgements
- Detailed Book Outline
- Section I: Stable Type Design
- Section II: Strategic Type Coupling
- Section III: Effective Type Reuse
- Appendix A: The Pointer Construct
- Appendix B: Design Exercises
- Appendix C: Comparative Design Exercises
- Glossary
- Bibliography
- Index