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.
Application and more information
5. Creating and using classes
6. Example of class (New!!)
7. Implementing OOP Features (Still
under construction)
Sources consulted
- Object Oriented Programming in Delphi - A Guide for Beginners
http://www.webtechcorp.co.uk/web-developer-training-delphi-article-oop.htm
- Object Oriented Programming in Delphi. Pieter Blignaut (Jan. 2008)
- Enjoy Delphi. Part 2. A. Bezuidenhout, K. Gibson, C. Noom?, U.
Wassermann, M. Zeeman (S. Jacobs, ed.) (2005) - p. 207-252
- Creative Programming in Delphi. Part 2. M. Havenga & C. Moraal. (2007) -
p. 135-156
- Introducing Delphi Programming: Theory through practice. J. Barrow, L.
Miller, K. Malan & H. Gelderblom. (2005) ? p. 486-520 |