1. Home
  2. Computing & Technology
  3. Delphi Programming

Introducing Type Inheritance - Delphi OOP Part 6 - Chapter 14
Difference between subclassing and subtyping; Part Download

By , About.com Guide

This chapter refers to the difference between subclassing and subtyping. Although this distinction is crucial to using polymorphism effectively, not all authors maintain it. These terms also sometimes mean different things to different people. We follow the Gang of Four (GoF) definitions (Gamma et al, 1995, p17):

‘Class inheritance defines an object's implementation in terms of another object's implementation.’ Thus class inheritance (or subclassing) allows for the re-use of data fields and methods, and is a mechanism for code and representation sharing. It is therefore largely a consideration that comes up during implementation and is the form of inheritance we used in the first few chapters of these notes.

‘In contrast, interface inheritance (or subtyping) describes when an object can be used in place of another.’ Subtyping is concerned about being able to substitute a child for a parent, and consequently about polymorphism. It is largely a design consideration though its implementation needs dynamic binding.

Subtyping allows a particular type or interface to be defined in a parent class. The various child classes then implement this interface in such a way that any child may take on the role nominally assigned to the parent. Client programs declare variables of the type of the parent only so that they can remain unaware of the specific child class which is dynamically bound at any particular moment to the parent type,

An important distinction here is the difference between static and dynamic binding. With static binding, the message initiator determines how the message will be carried out through addressing a specific class (the class declared) irrespective of the actual class of the receiver. With dynamic binding, the message initiator addresses a specific type at run time and the receiver performs its (own) implementation of the message.

What makes the difference between subclassing and subtyping a little difficult to grasp at first is that both depend on inheritance. So it’s difficult to see from just a quick glance at a set of class definitions whether subclassing, subtyping or both are being used. A useful clue is given by the virtual, abstract and override keywords, which usually indicate that subtyping is being used in some way or other. As we work further through these notes, the distinction will become clearer.

Part 6 Homework Problems

There are a dozen of homework problems included in the Part's PDF. Make sure you solve all of them.

This is the end of Part 6 of the Delphi OOP Course. Here's the full source code for the examples described in chapters 12, 13 and 14.

Stay tuned, Delphi OOP Course is not finished yet ... forward to Part 7 / Chapter 15.
Explore Delphi Programming
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Coding Delphi Applications
  5. OOP in Delphi
  6. Free Online OOP Course
  7. Introducing Type Inheritance - Delphi OOP Part 6 - Chapter 14

©2009 About.com, a part of The New York Times Company.

All rights reserved.