ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

This content has been translated automatically.  Click here  to view the French version.
Help / WLanguage / OOP (Object Oriented Programming)
  • Overview
  • Syntaxes
  • Class inheritance
  • Detailed syntax
  • Syntax kept for backward compatibility
  • Polymorphism manipulation
  • Redefining methods
  • Example
  • Syntaxes for calling a base class method
  • Syntax 1
  • Syntax 2
  • Syntax 3
  • Remark
WINDEV
WindowsLinuxJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac Catalyst
Others
Stored procedures
Overview
The hierarchical organization in class and sub-class has allowed to create the notion of inheritance.
In other words, an object of the sub-class A (derived class) that has the same characteristics as the class B (ancestor class) as well as its own characteristics inherits from all the characteristics of class B without having to duplicate the programs in the object of the sub-class A. The number of lines of code is reduced.
The inheritance is the mechanism by which the class currently described uses the methods and the members defined in the existing classes.
  • The existing class is called Ancestor class or Base class.
  • The new class is called Derived class. The derived class includes the ancestor class and adds new methods, new members and new properties to it.
The purpose of the inheritance is to retrieve, for a class, the methods developed for another class, by adding the specific features of the new class.
The objects found in a derived class can access all methods, all members and all properties of ancestor classes ; it is as if the methods, the members and the properties of ancestor classes were part of the derived class.
Characteristics of inheritance:
  • An inheritance can be multiple. In this case, the derived class can derive from several ancestor classes.
  • An inheritance can be private or public (by default).
    If the inheritance is public, you have the ability to access the methods, the properties and the members inherited from the outside of the class.
    If the inheritance is private, only the methods of the derived class can access the inherited methods, properties and members.
  • Like in all languages, the polymorphism operates with the dynamic objects only.
Syntaxes

Class inheritance

<NameDerivedClass> is class
[PRIVATE, PROTECTED, PUBLIC]
Inherits from <NameAncestorClass>
<Name Member Derived Class> is <Member Type>
...
END

Detailed syntax

<NameDerivedClass>
Name identifying the derived class that is currently declared.

PRIVATE, PROTECTED, PUBLIC
Optional keyword. Indicates whether the inheritance is private or not. If this keyword is not specified, the inheritance is public.

<NameAncestorClass>
Name of the ancestor class.

<Member Name Derived Class>
Name of the member of the derived class. This member can only be used in an object of the derived class.

<Member Type>
Type of the member, chosen among the available types.


Example:
FileName is Class 
	Name is string
	Extension is string
	Directory is string
END
 
FileInformation is Class 
	inherits from FileName
	FileSize is int
	FileDate is string 
	FileTime is string 
END

Syntax kept for backward compatibility

<NameDerivedClass> is class
[PRIVATE, PROTECTED, PUBLIC]
An object <NameAncestorClass>
<Name Member Derived Class> is <Member Type>
...
END
Polymorphism manipulation
Polymorphism is an object-oriented programming concept that allows objects of different types to be treated as objects of a common "superclass". It enables code reuse and flexibility by allowing several classes to implement the same method in different ways.
The polymorphism operates with the dynamic objects only.
In this example, a virtual animal class is created. Two classes (rabbit and cat) inherit from this class. We want to create a list of different objects (rabbits and cats).
Animal is Class 
END
 
Cat is Class 
	inherits from Animal
END
Rabbit is Class 
	inherits from Animal
END

ListA is array of 16 dynamic animals
ListA[1] = new cat
ListA[1] = new rabbit
New in version 2025
Instances of a class that inherits from a base class can be manipulated by a variable of the base type. It is possible to manipulate the elements of the instance's real class using the conversion operator. For more details, see Explicit conversion operator on classes.
Redefining methods
In a derived class, a method of the base class can be redefined by creating in the derived class a method with the same name as the one of the base class.
The redefinition of methods is used to modify the behavior of the method defined in the base class ; the derived class can eventually redefine the method according to its requirements.
The redefined method is a virtual method by default.
Note Overriding a method (using two methods with the same name in the same class) is handled in WLanguage. For more details, see Prototype overload/Overload.
Note: the Object keyword is used to access the current object within a method.

Example

The FileInfo class inherits from the FileName class. These two classes have a method named Display. The Display method of the FileName class class is used by the Display method of the InfoFile class.
FileName classFileInfo class
Declaration of the classDeclaration of the class
FileName is Class
	Name is string
 	Extension is string
 	Directory is string 
END
FileInformation is Class
	inherits from FileName
	FileSize is int
	FileDate is string  
	FileTime is string  
END
Display methodDisplay method
PROCEDURE Display()
Trace(:Name) 
Trace(:Extension) 
Trace(:Directory)
PROCEDURE DISPLAY() 
Ancestor:Display() 
Trace(:FileSize) 
Trace(:FileDate) 
Trace(:FileTime)
Syntaxes for calling a base class method

Syntax 1

Ancestor:<Method Name>()
Details of syntax
Ancestor
keyword used to indicate that the method to use is the method of the ancestor class immediately found before (can be used for a single inheritance). To call a method of a base class regardless of its level in the order of inheritance, syntax #2 must be used..

<Method name>
Name of method to use in the ancestor class.

Syntax 2

<Base Class>:<Method Name>()
Details of syntax
<Base class>
Name of ancestor class where the method to use was defined.

<Method name>
Name of method to use in the ancestor class.

Syntax 3

:<Classe de base>:<Nom de la Méthode>()
Details of syntax
<Base class>
Name of ancestor class where the method to use was defined.

<Method name>
Name of method to use in the ancestor class.

Remark

For the constructors and destructors, we recommend that you use specific syntaxes (see Syntax of constructors for the base classes and members).
Related Examples:
WD Simple OOP Training (WINDEV): WD Simple OOP
[ + ] The "WD Simple OOP" example is an educational example about the OOP with WINDEV. This example presents the operating mode of:
- classes,
- inheritances,
- virtual procedures,
- UML diagrams,
- ...
WD Controlling word processor Training (WINDEV): WD Controlling word processor
[ + ] The purpose of this example is to propose a universal interface, allowing to control these applications without having to worry about the application to control. This example is based on an object-oriented programming concept: the polymorphism. It consists in using different objects (OpenOffice object and Microsoft Word object) without really knowing which one is used.
Minimum version required
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 06/20/2025

Send a report | Local help