User Tools

Site Tools


namespaces

Namespaces

Namespaces are a possibility (that you should use, but not overuse!) to structure your classes.

A sample of working code:

Customer.Item.prg

begin namespace Customer
 
class Item
 
# Class code
 
end class
 
end namespace

Supplier.Item.prg

begin namespace Supplier
 
class Item
 
# Class code
 
end class
 
end namespace

and now how to use these classes:

local oCustomerItem as Customer.Item
local oSupplierItem as Supplier.Item
 
oCustomerItem := Customer.Item{}
oSupplierItem := Supplier.Item{}

Please note that with the “using” statement you don't need to fully specify the class like in this code:

using Customer
local oItem as Item
 
oItem := oItem{}

For the compiler, it must be clear which class to use, so if you have use classes that are defined multiple times in different namespaces, you need to fully qualify them. The following code will lead to a compiler warning:

using Customer
using Supplier
 
local oCustomerItem as Item
 
oCustomerItem := Item{}

because you need to specify which class to take. The compiler has no chance to do that correctly.

namespaces.txt · Last modified: 2018/08/20 04:07 by wolfgangriedmann