
Demystified Object-Oriented Programming with C++
While object-oriented software design helps you write more easily maintainable code, companies choose C++ as an OO language for its speed. Object-oriented programming (OOP) in C++ is not automatic - understanding OO concepts and how they map to C++ language features as well as OOP techniques is crucial. You must also know how to distinguish your code by utilizing well-tested, creative solutions, which can be found in popular design patterns. This book will help you to harness OOP in C++ for writing better code.
Starting with the essential C++ features that serve as building blocks for the main chapters, this book explains fundamental object-oriented concepts and shows you how to implement them in C++. With the help of practical code examples and diagrams, you'll find out how and why things work. The book's coverage furthers your C++ repertoire by including templates, exceptions, operator overloading, STL, and OO component testing. You'll also discover popular design patterns with in-depth examples and how to use them as effective programming solutions to recurring OOP problems.
By the end of this book, you'll be able to employ essential and advanced OOP concepts confidently to create enduring and robust software.
- Demystified Object-Oriented Programming with C++
- Contributors
- About the author
- About the reviewer
- Preface
- Who this book is for
- What this book covers
- To get the most out of this book
- Download the example code files
- Download the color images
- Code in Action
- Conventions used
- Get in touch
- Reviews
- Section 1: C++ Building Block Essentials
- Chapter 1: Understanding Basic C++ Assumptions
- Technical requirements
- Reviewing basic C++ language syntax
- Variable declarations and standard data types
- Variables and array basics
- Comment styles
- Recapping basic I/O
- The iostream library
- Basic iostream manipulators
- Revisiting control structures, statements, and looping
- Control structures: if, else if, and else
- Looping constructs: while, do while, and for loops
- Reviewing C++ operators
- Revisiting function basics
- Reviewing user-defined type basics
- struct
- typedef
- class
- enum
- Recapping namespace basics
- Summary
- Questions
- Chapter 2: Adding Language Necessities
- Technical requirements
- Using the const qualifier
- Const variables
- Const qualification with functions
- Working with function prototypes
- Defining function prototypes
- Naming arguments in function prototypes
- Adding default values to function prototypes
- Prototyping with different default values in different scopes
- Understanding function overloading
- Learning the basics of function overloading
- Eliminating excess overloading with standard type conversion
- Ambiguities arising from function overloading and type conversion
- Summary
- Questions
- Chapter 3: Indirect Addressing: Pointers
- Technical requirements
- Understanding pointer basics and memory allocation
- Revisiting pointer basics
- Using the address-of and dereference operators
- Using the operators new() and delete()
- Creating and using pointers to user defined types
- Allocating and deallocating arrays at run time
- Dynamically allocating single-dimension arrays
- Dynamically allocating 2-D arrays: arrays of pointers
- Dynamically allocating 2-D arrays: pointers to pointers
- Dynamically allocating N-D arrays: pointers to pointers to pointers
- Using pointers with functions
- Passing pointers as arguments to functions
- Using pointers as return values from functions
- Using the const qualifier with pointers
- Using pointers to constant objects
- Using constant pointers to objects
- Using constant pointers to constant objects
- Using pointers to constant objects as function arguments and as return types from functions
- Using pointers to objects of unspecified types
- Creating void pointers
- Summary
- Questions
- Chapter 4: Indirect Addressing: References
- Technical requirements
- Understanding reference basics
- Declaring, initializing, and accessing references
- Referencing existing objects of user defined types
- Using references with functions
- Passing references as arguments to functions
- Using references as return values from functions
- Using the const qualifier with references
- Using references to constant objects
- Using pointers to constant objects as function arguments and as return types from functions
- Realizing underlying implementation and restrictions
- Understanding when we must use pointers instead of references
- Summary
- Questions
- Section 2: Implementing Object-Oriented Concepts in C++
- Chapter 5: Exploring Classes in Detail
- Technical requirements
- Introducing object-oriented terminology and concepts
- Understanding object-oriented terminology
- Understanding object-oriented concepts
- Understanding class and member function basics
- Examining member function internals; the "this" pointer
- Using access labels and access regions
- Understanding constructors
- Applying constructor basics and overloading constructors
- Creating copy constructors
- Creating conversion constructors
- Understanding destructors
- Applying destructor basics and proper usage
- Applying qualifiers to data members and member functions
- Adding inline functions for potential efficiency
- Adding const data members and the member initialization list
- Using const member functions
- Utilizing static data members and static member functions
- Summary
- Questions
- Chapter 6: Implementing Hierarchies with Single Inheritance
- Technical requirements
- Expanding object-oriented concepts and terminology
- Deciphering generalization and specialization
- Understanding single inheritance basics
- Defining base and derived classes, and accessing inherited members
- Examining inherited access regions
- Understanding inherited constructors and destructors
- Implicit constructor and destructor invocations
- Usage of the member initialization list to select a base class constructor
- Putting all the pieces together
- Implementation inheritance changing the purpose of inheritance
- Modifying access labels in the base class list by using protected or private base classes
- Creating a base class to illustrate implementation inheritance
- Using a private base class to implement one class in terms of another
- Using a protected base class to implement one class in terms of another
- Summary
- Questions
- Chapter 7: Utilizing Dynamic Binding through Polymorphism
- Technical requirements
- Understanding the OO concept of polymorphism
- Implementing polymorphism with virtual functions
- Defining virtual functions and overriding base class methods
- Generalizing derived class objects
- Utilizing virtual destructors
- Putting all the pieces together
- Considering function hiding
- Understanding dynamic binding
- Comprehending runtime binding of methods to operations
- Interpreting the virtual function table (v-table) in detail
- Summary
- Questions
- Chapter 8: Mastering Abstract Classes
- Technical requirements
- Understanding the OO concept of an abstract class
- Implementing abstract classes with pure virtual functions
- Creating interfaces
- Generalizing derived class objects as abstract types
- Putting all the pieces together
- Summary
- Questions
- Chapter 9: Exploring Multiple Inheritance
- Technical requirements
- Understanding multiple inheritance mechanics
- Examining reasonable uses for MI
- Supporting Is-A and mix-in relationships
- Supporting Has-A relationships
- Creating a diamond-shaped hierarchy
- Utilizing virtual base classes to eliminate duplication
- Considering discriminators and alternate designs
- Summary
- Questions
- Chapter 10: Implementing Association, Aggregation, and Composition
- Technical requirements
- Understanding aggregation and composition
- Defining and implementing composition
- Defining and implementing a generalized aggregation
- Understanding associations
- Implementing association
- Utilizing back-link maintenance and reference counting
- Summary
- Questions
- Section 3: Expanding Your C++ Programming Repertoire
- Chapter 11: Handling Exceptions
- Technical requirements
- Understanding exception handling
- Utilizing exception handling with try, throw, and catch
- Exploring exception handling mechanics with typical variations
- Utilizing exception hierarchies
- Using standard exception objects
- Creating customized exception classes
- Creating hierarchies of user-defined exception types
- Summary
- Questions
- Chapter 12: Friends and Operator Overloading
- Technical requirements
- Understanding friend classes and friend functions
- Using friend functions and friend classes
- Making access safer when using friends
- Deciphering operator overloading essentials
- Implementing operator functions and knowing when friends might be necessary
- Summary
- Questions
- Chapter 13: Working with Templates
- Technical requirements
- Exploring template basics to genericize code
- Examining the motivation for templates
- Understanding template functions and classes
- Creating and using template functions
- Creating and using template classes
- Examining a full program example
- Making templates more flexible and extensible
- Adding operator overloading to further genericize template code
- Summary
- Questions
- Chapter 14: Understanding STL Basics
- Technical requirements
- Surveying the contents and purpose of the STL
- Understanding how to use essential STL containers
- Using STL list
- Using STL iterator
- Using STL vector
- Using STL deque
- Using STL stack
- Using STL queue
- Using STL priority queue
- Examining STL map
- Examining STL map using a functor
- Customizing STL containers
- Summary
- Questions
- Chapter 15: Testing Classes and Components
- Technical requirements
- Contemplating OO testing
- Understanding canonical class form
- Default constructor
- Copy constructor
- Overloaded assignment operator
- Virtual destructor
- Move copy constructor
- Move assignment operator
- Bringing the components of canonical class form together
- Ensuring a class is robust
- Creating drivers to test classes
- Testing related classes
- Testing classes related through inheritance, association, or aggregation
- Testing exception handling mechanisms
- Embedding exception handling in constructors to create robust classes
- Summary
- Questions
- Section 4: Design Patterns and Idioms in C++
- Chapter 16: Using the Observer Pattern
- Technical requirements
- Utilizing design patterns
- Understanding the Observer pattern
- Implementing the Observer pattern
- Creating Observer, Subject, and domain-specific derived classes
- Summary
- Questions
- Chapter 17: Applying the Factory Pattern
- Technical requirements
- Understanding the Factory Method pattern
- Implementing the Factory Method pattern
- Including the Factory Method in the Product class
- Creating an Object Factory class to encapsulate the Factory Method
- Summary
- Questions
- Chapter 18: Applying the Adapter Pattern
- Technical requirements
- Understanding the Adapter pattern
- Implementing the Adapter pattern
- Using an Adapter to provide a necessary interface to an existing class
- Using an Adapter as a wrapper
- Summary
- Questions
- Chapter 19: Using the Singleton Pattern
- Technical requirements
- Understanding the Singleton pattern
- Implementing the Singleton pattern
- Using the simple implementation
- Using the more robust paired-class implementation
- Using a registry to allow many classes to utilize Singleton
- Summary
- Questions
- Chapter 20: Removing Implementation Details Using the pImpl Pattern
- Technical requirements
- Understanding the pImpl pattern
- Implementing the pImpl pattern
- Organizing file and class contents to apply the pattern basics
- Improving the pattern with a unique pointer
- Understanding pImpl pattern trade-offs
- Summary
- Questions
- Assessments
- Chapter 1 Understanding Basic C++ Assumptions
- Chapter 2 Adding Language Necessities
- Chapter 3 Indirect Addressing: Pointers
- Chapter 4 Indirect Addressing: References
- Chapter 5 Exploring Classes in Detail
- Chapter 6 Implementing Hierarchies with Single Inheritance
- Chapter 7 Utilizing Dynamic Binding through Polymorphism
- Chapter 8 Mastering Abstract Classes
- Chapter 9 Exploring Multiple Inheritance
- Chapter 10 Implementing Association, Aggregation, and Composition
- Chapter 11 Handling Exceptions
- Chapter 12 Friends and Operator Overloading
- Chapter 13 Working with Templates
- Chapter 14 Understanding STL Basics
- Chapter 15 Testing Classes and Components
- Chapter 16 Using the Observer Pattern
- Chapter 17 Applying the Factory Pattern
- Chapter 18 Applying the Adapter Pattern
- Chapter 19 Using the Singleton Pattern
- Chapter 20 Removing Implementation Details Using the pImpl Pattern
- Why subscribe?
- Other Books You May Enjoy
- Packt is searching for authors like you
- Leave a review - let other readers know what you think
- Tytuły: Demystified Object-Oriented Programming with C++
- Autor: Dorothy R. Kirk
- Tytuł oryginału: Demystified Object-Oriented Programming with C++
- ISBN Ebooka: 9781839213540, 9781839213540
- Data wydania: 2021-03-26
- Identyfikator pozycji: e_2t6s
- Kategorie:
- Wydawca: Packt Publishing