Polymorphism in UiPath

Hi,

I am very interested in using polymorphism in UiPath and need to find out how to do this.

Real example:
As input to my process, I have the results of a query to a db. Each row received represents a product.

In Visual Studio, I have an interface class, IProduct, which is implemented by all types of products available.

I have also a factory class which takes as input the current row, and returns the corresponding product in a reference to the interface class:

public static IProduct Create(DataRowCollection row)

It works fine in UiPath Studio when I call on the factory, using a Assign Activity:

IProduct iProduct = Factory.Create(row)

Now I want to call the method GetValue() on the variable iProduct and through dynamic binding delegate the call the corresponding overridden methods in the derived product classes. This should work easily if I only have simple logic in this method, but what GetValue() should do is to go to the specific home pages of the product in question and do data scraping etc. So the functionality encapsulated by the GetValue() methods in the derived product classes is typical UiPath business.

How can I achieve this ?

For example, it would be really nice if I could create a library in UiPath Studio for a product and in there define GetValue() method which overrides the one in the interface and then call on this library/method in the main workflow.

Can I define classes/interfaces/abstract classes/inheritance hierarchies somewhere in UiPath Studio and reference them in my workflows, or do I have to do that in for example Visual Studio and publish a package which I then import in UiPath Studio to be able to reference the classes ?

Custom classes have to be created in visual studio and published as a package like you mentioned. You can look into the ‘libraries’ feature of studio, but that is much more limited than what you can create yourself in visual studio

Hi Dave, what you mention is fine and I made it work anyway.

How about the part with calling methods of concrete classes/implementations through a reference to the base class/interface? In essence, I would like to be able to follow good design practices such as S.O.L.I.D. My original question relates to the principle “open for extension, closed for modification”, in that I want to be able to iteratively add a new implementation for each new product, without having any effect on existing code.