Home | Articles | Tutorials | Delphi Links

| Sites

Home
Articles
Tutorials
Delphi Links

    


Top100Borland
Vote for me




Coders Corner


The Delphi FAQ


Best Delphi Sites

Powered by phpBB2


www.BlueChillies.com

 

Contact Information

+218-51-742718
+218-91-3748232

contact@elarigh.com

 

 

 

Inheritance

When we define a new class in terms of an existing (original) class in such a way that all data and methods of the original class will be automatically and implicitly available to the new class, then we say that the new class (or subclass) inherits or enhances the original (superclass) class.
The subclass can then redefine the inherited attribute and behaviour and can add to the class new ones.
We can say that a subclass is a specialization of its superclass, and that a superclass a is a generalization of its subclasses.
With class inheritance, we can build complex blocks of related classes.

Inheritance and code reuse
When writing a new application, you can reuse existing similar classes from another application
without the need to rewrite everything from scratch. This saves your time, especially when you are reusing a tested code.

Encapsulation
The combination of data and functionality in a single entity.
With encapsulation, implementation details are hidden and access to the class is only made via the class's interface. Object Pascal has access keywords (private, public, ..etc) to achieve encapsulation. Encapsulation is also called information hiding, but this is not always true.

Polymorphism
Polymorphism is the ability of an object to refer to other objects (derived from the same ancestor) at runtime. Sometimes a method has the same name in different classes and with polymorphism, methods of the same name in the other objects can be called by any of the ancestors.

Classes
A class is a data type that encapsulates attributes (or data) and code in a single structure, or in Delphi terms a class is a data type with any number of fields, properties and methods which are called the members of the class.

Objects
An object is an instance of a class.
All objects share the same operations but each object preserves its own copy of data values (state).
Every object is located dynamically, and you can create as many instances (objects) from a class and in this sense, we can define a class as a collection of similar objects.

Fields
A field is a variable that is defined within the class and each object holds a copy of the fields of the class.

Methods (or operations or behaviour)
The procedures and functions of the class are called methods. The method is the code that operates on the data of the object and unlike data (where each object can have its own data), all objects have the same methods.

Properties (or state or data )
They are the attributes of the object, and refer to the data of the object.
A property doesn't need to exist in memory, in fact a property can get its data from any external resource  but usually it uses fields from the class to store its data. Every property has a read and/or write specifier (also called a reader and a writer) to access the property's value. These access specifiers can be fields or methods of the class and are automatically executed when the property is invoked.

Constructors
The constructor is a special method that we invoke to create an object.

Destructors
The destructor is a special method used to cleanup previously allocated memory or free resources.

The visibility of class members
The visibility or access level of the members of a class determines how and who can use the members of the class. This is achieved by grouping the declarations of the members in sections that are preceded by any of the keywords, private, public, protected or published. For example, the members in the public part can be used by any code from outside of the class where the class can be referenced, and the members in the private can only be used by the class itself or anywhere in the unit where the class is declared.   

 

Links to Object Oriented articles

 

  elarigh.com © 2005 | All Rights Reserved |

Home | Articles | Tutorials | Delphi Links