Chapter 3 – OOP Fundamentals

This chapter introduces the core Object-Oriented Programming concepts as implemented in Delphi XE2. It covers the foundational ideas that underpin Delphi's class-based architecture and prepares the reader for more advanced topics in later chapters.

Classes and Objects

Delphi's object model is built around the class type. A class defines a blueprint from which individual objects — instances — are created at runtime. Each object encapsulates both data (fields) and behaviour (methods), providing a clean separation of concerns and promoting code reuse.

Key topics covered include:

Inheritance and Polymorphism Basics

Inheritance allows one class to derive from another, inheriting its members while adding or overriding functionality. Delphi supports single inheritance, where each class has exactly one immediate ancestor — ultimately tracing back to TObject, the root of the class hierarchy.

Polymorphism enables code written against a base class to operate on any derived class instance. Through virtual and dynamic methods, Delphi resolves the correct method implementation at runtime based on the actual object type.