PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

Home | Sign in | English US
New WINDEV, WEBDEV, WINDEV Mobile 23 feature!
  • Implementation
  • Variables
  • Passing parameters
  • External component
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile
Others
Stored procedures
An interface is used to divide the uses of features common to several elements from their implementations, which simplifies their re-usability.
An interface is a list of available features, a kind of contract ("I am committed to provide the following methods and properties").
Interface characteristics:
  • An interface contains a list of prototypes of methods and properties.
  • All methods and properties are accessible (no public/protected/private).
  • There is no implementation element (no member, no code, ...).
An interface is a type that can be declared in the initialization code of project or in the declaration code of an element, especially the sets of procedures.
Example
// Declare an interface
Basket is Interface
Procedure AddProduct(ProductCode)
Property NumberProducts <get>
END
Syntax

Declaring an interface Hide the details

<Interface Name> is Interface
   Procedure <Procedure 1> ([<Parameters]) [: <Type of Return>]
   Procedure <Procedure N> ([<Parameters]) [: <Type of Return>]
   Property <Property 1> [: <Type of Return>] [<Get/Set>]
   Property <Property N> [: <Type of Return>] [<Get/Set>]
END
<Interface Name>:
Name of interface to declare.
<Procedure X>:
Name of procedures listed by the interface. These procedures can have one or more parameters and they can return a value. You have the ability to specify the type of value returned by the procedure. This type can correspond to a simple type (integer, real, string, ...) or to a structured type (structure, object, ...).
<Property Y>:
Name of properties listed by the interface. These properties can:
  • return a value. You have the ability to specify the type of value returned by the property. This type can correspond to a simple type (integer, real, string, ...) or to a structured type (structure, object, ...).
  • have attributes used to specify whether the property is read-only or read/write, ...
<END>:
End of interface declaration.
Remarks

Implementation

An interface can be implemented by a class: the class implements all the methods and properties of interface.
The "implement" keyword is used to link the interface and the class.
Example :
InternetBasket is Class
implement Basket
m_ArrProducts is array of ints
END
// Procedure
PROCEDURE AddProduct(ProductCode)
m_ArrProducts.Add(ProductCode)
// Property
PROCEDURE PUBLIC NumberProducts()
RESULT m_ArrProducts..Occurrence
A compilation error occurs if a class does not implement all methods or properties of interface.

Variables

You have the ability to declare variables to store and handle the elements by their interfaces.
In this case, you must use the '<-' operator to specify the real element handled via the interface. The syntax is as follows:
<VariableName> is <Interface> <-...
Example:
// After a reconnection, retrieve the previous basket
CurrentBasket is Basket <- RestorePreviousBasket()
If the real element does not implement all the methods or properties, the variable is assigned with 'Null' and no error occurs. This allows you to check whether the element was converted into its interface by comparing it to Null. On the contrary, any later use of variable will trigger an error.

Passing parameters

An interface can be used to type a procedure parameter.
If a procedure expects an "Interface Xxx" parameter, any element that implements all the procedures and methods of interface can be passed in parameter.
A compilation error occurs if the element does not implement all the methods and all the properties.
The real class does not have to explicitly implement the interface. However, all methods and all properties must be found.

External component

  • The interfaces can be used from an external component.
  • Interfaces exported from a component: The interface should not be declared in the initialization code of project. Indeed, in this case, the projects that call the component will not see the interface.
Minimum required version
  • Version 23
This page is also available for…
Comments
Click [Add] to post a comment