Presentation is loading. Please wait.

Presentation is loading. Please wait.

Section 2.1: Programming paradigms

Similar presentations


Presentation on theme: "Section 2.1: Programming paradigms"— Presentation transcript:

1 Section 2.1: Programming paradigms
A class in OOP The basics of declaring a new class in Delphi

2 Defining a class You may find it useful to follow these steps:
Step 1: Name the class. Step 2: Decide on the properties of the class. Step 3: Declare properties as private. Step 4: Declare the constructor of the class. Step 5: Declare the methods (procedures and functions). Step 6: Write the code for your methods.

3 A basic OOP class in Delphi
interface Step 1: Name the class. type Tractor = class private Step 2: Decide on the properties of the class. manufacturer: integer; horsePower: integer; engineHours: integer; public Step 3: Declare properties as private. constructor Create; function getmanufacturer; procedure setmanufacturer(man:String); function gethorsePower; procedure sethorsePower(hp: integer); function getEngineHours; procedure setEngineHours(eh:integer); Step 4: Define the constructor of the class as public. Step 5: Declare the methods (procedures and functions). end; implementation constructor Tractor.create; begin engineHours:=0; end; …. ETC Step 6: Write the code for your methods.

4 Summary Properties of a class are declared as private. This is so they cannot be accessed outside the class. Methods (procedures and functions) are public and are written to enable the properties of the class to be accessed from outside the class. A constructor is a special method that is used when a new object is created of that class. When an object is created it has all the methods and variables defined in the class. Encapsulation is a term used to describe the combination of the object and its methods. This promotes separation of the implementation and the interface. Because the properties of the class are private, you can control changes to the actual object. In addition, you have the flexibility to change the implementation without affecting anything outside the class. This principle is known as information hiding. Inheritance is where one class can inherit methods and properties from another class. This promotes efficiency because code from one class can be reused in its sub-class.


Download ppt "Section 2.1: Programming paradigms"

Similar presentations


Ads by Google