<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to OOP: Interface methods/properties with different return types</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/0da20406bf/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/0da20406bf/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/0da20406bf/</id><updated>2022-11-25T10:16:40.491000Z</updated><subtitle>Recent posts to OOP: Interface methods/properties with different return types</subtitle><entry><title>OOP: Interface methods/properties with different return types</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/0da20406bf/?limit=25#7d9c" rel="alternate"/><published>2022-11-25T10:16:40.491000Z</published><updated>2022-11-25T10:16:40.491000Z</updated><author><name>lefish</name><uri>https://forge.codesys.com/u/lefish/</uri></author><id>https://forge.codesys.comd4cd92e111b4ed82dfdbb6fd54ae14957a2319de</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Thanks for your replies.&lt;/p&gt;
&lt;p&gt;&lt;a class="user-mention" href="/u/fajean/"&gt;@fajean&lt;/a&gt;: Basically this is what I am trying to achieve. I need to pack FBs with commonly named properties (returning different kinds of structs) into one array to loop over all FBs. It would have been great for this purpose if a propertyX returned a structA when queried for an instance of typeA, but a propertyX returned a structB when queried for instance of typeB...&lt;/p&gt;
&lt;p&gt;I solved this now by dropping the Interface-approach at all. Instead I implemented "Interface"-Methods and Properties in a FB_Handler (which I needed anyways) to interact with the underlying instances of FB_A and FB_B.&lt;br/&gt;
Typechecking is also to be implemented in this "Interface". &lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>OOP: Interface methods/properties with different return types</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/0da20406bf/?limit=25#5cca" rel="alternate"/><published>2022-11-22T11:17:32.512000Z</published><updated>2022-11-22T11:17:32.512000Z</updated><author><name>fajean</name><uri>https://forge.codesys.com/u/fajean/</uri></author><id>https://forge.codesys.comc02ca18f9ab7f2d0b1cb38425b82bc9ca80d5752</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Are you trying to achieve the equivalent of generics (i.e. have a "container" function block that contains elements of an arbitrary type, but all elements of the same type for a given instance of the container) or mixed types (i.e. elements of different types within the same container)?&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>OOP: Interface methods/properties with different return types</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/0da20406bf/?limit=25#5e72" rel="alternate"/><published>2022-11-22T07:14:48.745000Z</published><updated>2022-11-22T07:14:48.745000Z</updated><author><name>sgronchi</name><uri>https://forge.codesys.com/u/sgronchi/</uri></author><id>https://forge.codesys.com7354f8ac37a7b236f7c55b8db67b83dd507b83ec</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;In general you cannot return a different data type except with a union.&lt;/p&gt;
&lt;p&gt;If you want stronger typechecking, you could return a pointer to the data (in pointer to byte) and a reference to a "decoding interface" that inherits from a base one with no .Decode method, and then you dispatch via __QUERYINTERFACE.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>OOP: Interface methods/properties with different return types</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/0da20406bf/?limit=25#8421" rel="alternate"/><published>2022-11-21T15:56:25.403000Z</published><updated>2022-11-21T15:56:25.403000Z</updated><author><name>lefish</name><uri>https://forge.codesys.com/u/lefish/</uri></author><id>https://forge.codesys.com151987ec2c542583de82f069e0e0da6ffa7d771f</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hi there,&lt;/p&gt;
&lt;p&gt;can I somehow achieve to let the function blocks which implement an interface decide which data type is actually returned?&lt;/p&gt;
&lt;p&gt;So let FB_A return Type_A and FB_B return Type_B when calling an interface I_AB method.&lt;/p&gt;
&lt;p&gt;Basically I need to change the return type of an overloaded method/property according to the method called.&lt;/p&gt;
&lt;p&gt;I can explain more detail of what I am trying to achieve, but I would like to keep it abstract for the opening of the thread (lenghtiness of thread where it might not be needed)&lt;/p&gt;
&lt;p&gt;I tried to form a Union of Type_A and Type_B, return always the union and decide on runtime which to use, but this is very error prone during development as it exposes Type_A to implementations of FB_B function block.&lt;/p&gt;
&lt;p&gt;Can you point me into the right direction please?&lt;/p&gt;
&lt;p&gt;Thanks in advance!&lt;/p&gt;
&lt;p&gt;Best regards&lt;br/&gt;
LeFish&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>