From the course: C++ Design Patterns: Creational

Unlock the full course today

Join today to access over 24,700 courses taught by industry experts.

Concrete vs. abstract

Concrete vs. abstract

- [Instructor] When developers initially start learning about creating classes and subclasses, they start with a parent or base class. Take, for example, an Animal class with methods for eat or makeNoise. Typically these methods are implemented in the Animal class, but then the Child class will override it. For example, a Dog class inherits from animal and overrides the makeNoise method, so the dog barks. The method makeNoise will always be overwritten by the classes that inherit from Animal. So it shouldn't be necessary to define something in this base class. C++ allows me to do that with the virtual keyword. This indicates to the compiler, and other programmers, that I expect all subclasses to override this method with their own implementation. The ability to define methods in this way is incredibly useful. I can use this class as a blueprint for all classes that will inherit from it. When defining a method with the…

Contents