Step 3

Inheritance and frameworks – Virtual methods and polymorphism

After Step 3 you should have an understanding of the important OO concepts Inheritance and Polymorphism, and how they should be applied to support maintenance and reuse of software. You will have knowledge of mechanisms to achieve a polymorphic behavior and how to use virtual methods to create an interface for a customizable framework. We place great importance on that you now will master dynamic management of objects and variables, and also understand the creation and destruction processes for objects and variables.

Step 3 deals with two (of three) cornerstones in object oriented programming – the key concepts of Inheritance and Polymorphism. We start by looking at basic principles of inheritance mechanism, with its generalized base class and specialized behavior in the subclass. Dynamic management and creation process of objects will then gain a deeper study as well as class object and the static concept. In particular, the initialization order of objects in different contexts and the MIL – Member initialization list – will be in focus.

Furthermore, will be studied C++ constructs supporting polymorphism. We will address how polymorphic inheritance is implemented and how virtual methods are used to control a flexible class behavior. Above all is treated the characteristics of an abstract base class and how to create good conditions for a flexible framework and its adaptation classes, by use of an Interface.

The theory is to be found in the course book’s Ch. 14 (Inheritance),   Ch. 15: (Virtual Functions and Polymorphism) and  Ch. 20: 484-486 (static class members).

Concepts that are covered:

  • Inheritance as a means to support maintenance and reuse of class code
  • The base classgeneralizes properties and services
  • The subclassspecializes an object’s functionality
  • Access to class members with declarations public, protected and private
  • 5 ways to reserve memory for objects with different duration and scope
  • Initialization order of subclass, base class and internal data members – how to use Member Initialization List
  • What to do in the destructor?
  • For each class is exactly one class object – how to use its static members
  • The concept of polymorphism – with base class pointer we point out arbitrary subclass
  • Overloaded methods – only subclass-pointer giving access
  • By use of virtual-declaration in base class, will subclass method be called regardless pointer type
  • A pure virtual method enforces overloading, we have an abstract base class
  • A framework allows for adaptation classes, whose methods replaces the virtual ones
  • An interface specifies the “plugin” methods required

Welcome to CoursePress

en utav Linnéuniversitets lärplattformar. Som inloggad student kan du kommunicera, hålla koll på dina kurser och mycket mer. Du som är gäst kan nå de flesta kurser och dess innehåll utan att logga in.

Läs mer lärplattformar vid Linnéuniversitetet

Student account

To log in you need a student account at Linnaeus University.

Read more about collecting your account

Log in LNU