Synopsis:
This lecture provides help with projects, then continues with discussion of sample code for C++ classes and their relationships.
Glossary of Terms
-
Class:
A language construct that binds together member functions and data:- Class syntax: class X { ... }
- Method syntax: R X::f(T t) { ... }
- Data syntax: Y y;
-
Class Relationships:
Object Oriented Designs use C++ classes and their relationships to structure an implementation. The relationships are:-
Inheritance:
Derived classes specialize base classes, using the syntax:class D : public B { ... };
-
Composition:
Composing classes hold instances of other types as data members, using the syntax:class C { ... private: A a; B b; };
-
Aggregation:
Aggregating classes hold pointers to instances of data on the native heap, using the syntax:class A { ... private: B* pB = nullptr; C* pC = nullptr; };
The pointers are initialized to point to heap allocations in some member function of the class, perhaps in it's constructors and the allocations are returned in its destructor. -
Using:
Using classes are passed class instances they will use through member function calls. They do not own these instances, simply use them temporarily, with the syntax:class U { void usingMF(R* pR) { pr->someUsefulFunction(); } };
-
Inheritance:
Lecture Content:
-
Help with Projects:
-
Project #1
Single-user Test Harness. -
Project #2
Local Test Harness -
Project #3
Server Process Pools -
Project #4
Remote Multi-User Test Harness
-
Project #1
-
Synchronous Discussion:
- Create a class diagram for your Project #2 implementation. Please indicate all of the class relationships.
- Be prepared to discuss your packages and dependencies.
-
Class Hierarchy
-
class relationships,
docx,
class relationships - layout view,
vsdx
ClassRelationships code folder
Illustrates static (class) and physical (memory) structure. -
Hierarchy Presentation,
pptx
Hierarchy is concerned with the relationships between classes - aggregation, composition, inheritance, and using. -
Principles - esp. Liskov Substitution
Discussion of principles that guide good Object Oriented Design
-
Virtual Function Pointer Tables,
vsdx
Virtual Function Pointer Tables -
Demonstrates Compound Object creation
You need to understand how constructor initialization is used to control creation of the objects you use. -
Three Tier Hierarchy
Interface defines a contract, abstract base class provides sharing, derived classes implement the contract in specialized ways. -
Demonstrate Composition
This project contains several demonstrations of basic composition relationships. -
Demonstrate Inheritance
Contains demonstration of things to be careful with when using inheritance. -
C++'s Dark Corners,
docx
A summary of the short list, with brief explainations, of C++'s dark corners, e.g., things that can cause subtle errors.
-
class relationships,
docx,
class relationships - layout view,
vsdx
-
Lecture Take-aways:
The most important things we discussed today: