16.5 — Dependencies

So far, we’ve explored 3 types of relationships: composition, aggregation, and association. We’ve saved the simplest one for last: dependencies. In casual conversation, we use the term dependency to indicate that an object is reliant upon another object for a given task. For example, if you break your foot, you …

16.4 — Association

In the previous two lessons, we’ve looked at two types of object composition, composition and aggregation. Object composition is used to model relationships where a complex object is built from one or more simpler objects (parts). In this lesson, we’ll take a look at a weaker type of relationship between …

16.1 — Object relationships

Life is full of recurring patterns, relationships, and hierarchies between objects. By exploring and understanding these, we can gain insight into how real-life objects behave, enhancing our understanding of those objects. For example, let’s say one day you’re walking down the street, and you see a bright yellow object attached …

14.14 — Converting constructors, explicit, and delete

By default, C++ will treat any constructor as an implicit conversion operator. Consider the following case: #include <cassert> #include <iostream> class Fraction { private: int m_numerator; int m_denominator; public: // Default constructor Fraction(int numerator = 0, int denominator = 1) : m_numerator(numerator), m_denominator(denominator) { assert(denominator != 0); } // Copy …

14.13 — Copy initialization

Consider the following line of code: int x = 5; This statement uses copy initialization to initialize newly created integer variable x to the value of 5. However, classes are a little more complicated, since they use constructors for initialization. This lesson will examine topics related to copy initialization for …