Vai al contenuto

Interfaces Polimorphysm

GF_ProjectVX code can handle polimorphysm with interfaces, create a variable of type interface and valorize it usign the instance of a class that implements the method prototypes of that interface; now you can use the interface variable to call methods, GF_ProjectVX code will be able to recognize which is the correct method to call, even if there may be more classes that implement the same interface.Also, using the query interface operator IMOVE ( ?= ), you can use a variable to an in- terface to valorize a varaible to a second interface which is extended by the first one; GF_ProjectVX code will be able to analyze the object behind the source interface, and will use the correct method to valorize the destination interface variable. Interfaces Polimorphysm-image_0In the baove example: the interface intf_1 extends the interface intf_2; the interface intf_1 is implemented by both fb_class_1 and fb_class_2.i1, variable of type intf_1, is valorized using myClass_2, an instance of fb_class_2, which is a Function Block that implements intf_1; now calling i1.method_201 will correctly call method_201 of fb_class_2.i2, variable of type intf_2, which is an interface extended by intf_1, is valorized with i1 using the IMOVE operator; thanks to this operator there’s no error even if i1 and i2 are not of the same type (because GF_ProjectVX code understand that i1 extends i2) and i2 is valor- ized with a reference to the instance of myClass_2; so if around your project you call i2.method201, you will be calling method_201 of fb_class_2.