User Tools

Site Tools


namespaces

This is an old revision of the document!


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 Customer.Item
local oSupplierItem as Supplier.Item

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

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

namespaces.1516598803.txt.gz · Last modified: 2018/01/22 05:26 by wolfgangriedmann