header image
Home arrow Programming arrow Object Oriented Programming (OOP)
Object Oriented Programming (OOP)

1. Definition
Object Oriented Programming uses objects (self-contained modules) to solve problems.


2. Objects
- An object is a module created by the programmer.
- An object represents something that can actually exist.
- Objects reacts to actions (events).
- Objects are grouped into classes.
- Objects have members called: properties and methods.
- A property describes the object while a method is something that can be done to an object.

All Delphi components are objects (yet not all objects are components).

For example:
A Button has a property ‘caption’ – the text displayed on the button.
The method ‘clear’ erases the contents of an Edit box.

If you right click on a Button and choose ‘View as Text’. The following properties are shown:

It is also evident from this example that the Form is also an object.

3. Classes
- Objects can be grouped into classes.
- Classes are used to distinguish one type of object from another.
- A class is a set of objects that share common characteristics and behaviour.
- An object is called an INSTANCE of a class.
- It can also be described as a pattern or template that is used to create objects.

Every type of component (Form, Button, Edit, Memo, etc.) has a class type defined in Delphi. This describes what its properties and methods are.

A Delphi component can belong to a class. When something is placed on a Form the components are created according to the definition of the particular class. Delphi automatically inserts the declaration after a component is placed on a form.

A class contains:
- a set of attributes and behaviour
- that describe the operation and construction of a real world object.

A class consists of:
- fields (variable that is part of an object)
- properties (data describing an object)
- methods (what an object can do)

When an object is created according to a class, we say the object is instantiated. Because an object is an instance of a class.

When naming a class – the letter T is always placed in front. For example: TForm, TButton, TCars and TBooks.

4. Basic OOP Features
4.1 Data Abstraction
Creating your own types in Delphi. Existing data types are grouped together to create a new data type not found in Delphi.

4.2 Encapsulation
An object is a distinct entity that has its own data and behaviour. An object 'owns' this data and behaviour and other objects do not have access to them.

4.3 Inheritance
Objects lower down the hierarchy inherit data and behaviour from their ancestors higher up in the hierarchy.

4.4 Polymorphism
An object can operate interchangeably with an ancestor in relation to the attributes and methods it inherits from the ancestor.


Additional Resources
- OOP Notes by Pieter Blignaut (posted on this site with author's permission)

Statistics
Members: 2
News: 41
Web Links: 4
Visitors: 439757