Object Oriented Programming (OOP)
Written by JAK Olivier
Sep 13, 2009 at 02:08 PM
Object Oriented Programming uses objects (self-contained modules) to solve problems.
- 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).
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.
- 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.
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.
Objects lower down the hierarchy inherit data and behaviour from their ancestors higher up in the hierarchy.
An object can operate interchangeably with an ancestor in relation to the attributes and methods it inherits from the ancestor.
- OOP Notes by Pieter Blignaut (posted on this site with author's permission)
Last Updated ( Sep 13, 2009 at 12:14 PM )