<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: calling a method inside a subclass - factory pattern in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/calling-a-method-inside-a-subclass-factory-pattern/m-p/11838386#M1957142</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Christian.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can you give some example working with the interface ?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 02 Sep 2016 10:01:12 GMT</pubDate>
    <dc:creator>former_member182337</dc:creator>
    <dc:date>2016-09-02T10:01:12Z</dc:date>
    <item>
      <title>calling a method inside a subclass - factory pattern</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/calling-a-method-inside-a-subclass-factory-pattern/m-p/11838382#M1957138</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am working on creation of a factory pattern. The "factory" method inside the class will instantiate the sub classes based on the importing parameter. The subclasses redefine an abstract method in the super class and the same is being called in my program. It is fine till this stage. The problem that I am facing is that am not able to implement a separate method for the subclass. When I try to call the method ( Exclusive for the sub class not inherited from the super class) , I get the error message - "The method is unknown, protected or private" . There is no syntax error while I try to access a message inherited from the super class. Can you please share some thoughts?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Prem&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 29 Aug 2016 10:52:16 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/calling-a-method-inside-a-subclass-factory-pattern/m-p/11838382#M1957138</guid>
      <dc:creator>former_member182337</dc:creator>
      <dc:date>2016-08-29T10:52:16Z</dc:date>
    </item>
    <item>
      <title>Re: calling a method inside a subclass - factory pattern</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/calling-a-method-inside-a-subclass-factory-pattern/m-p/11838383#M1957139</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Post your code snippet so that others can have a better understanding of your problem.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If i understand correctly you're trying to call the method of the subclass using the reference variable whose static type is that of the superclass &lt;SPAN __jive_emoticon_name="confused" __jive_macro_name="emoticon" class="jive_macro_emoticon jive_macro jive_emote" src="https://community.sap.com/108/images/emoticons/confused.gif"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
&lt;P&gt;cl_factory=&amp;gt;get_instance(...)-&amp;gt;sub_class_method(...)&lt;/P&gt;
&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 29 Aug 2016 20:00:04 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/calling-a-method-inside-a-subclass-factory-pattern/m-p/11838383#M1957139</guid>
      <dc:creator>SuhaSaha</dc:creator>
      <dc:date>2016-08-29T20:00:04Z</dc:date>
    </item>
    <item>
      <title>Re: calling a method inside a subclass - factory pattern</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/calling-a-method-inside-a-subclass-factory-pattern/m-p/11838384#M1957140</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Suhas,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for your reply. Please find the code snippet below.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;go_val = ycl_factory=&amp;gt;factory( exporting iv_type = 'SO').&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;if go_val is bound.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;go_val-&amp;gt;calculate( exporting iv_customers = ip_sales &lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; receiving ep_customers = gt_sales ) .&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;go_val-&amp;gt;calculate_sub ().&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;endif.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;endif.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;BR /&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;The above code is fine till the calculate method which is inherited from the super class . The calculate_sub is a method that is available only in the child class which is instantiated by go_val.&lt;BR /&gt; and that is giving a syntax error.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Aug 2016 02:49:06 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/calling-a-method-inside-a-subclass-factory-pattern/m-p/11838384#M1957140</guid>
      <dc:creator>former_member182337</dc:creator>
      <dc:date>2016-08-30T02:49:06Z</dc:date>
    </item>
    <item>
      <title>Re: calling a method inside a subclass - factory pattern</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/calling-a-method-inside-a-subclass-factory-pattern/m-p/11838385#M1957141</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Prem,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;you first need to cast your go_val to the type of the subclass. Something like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;data: sub_class&amp;nbsp;&amp;nbsp;&amp;nbsp; type ref to cl_sub_class.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;sub_class ?= ycl_factory=&amp;gt;factory( ...).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;sub_class-&amp;gt;calculate_sub( ).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif;"&gt;However, this code looks like you are having a design issue. Usually it should not be necessary to call a specific method of the subclass. Instead you should stick with the interface provided by your factory.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif;"&gt;Christian &lt;/SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Aug 2016 06:09:52 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/calling-a-method-inside-a-subclass-factory-pattern/m-p/11838385#M1957141</guid>
      <dc:creator>ceedee666</dc:creator>
      <dc:date>2016-08-30T06:09:52Z</dc:date>
    </item>
    <item>
      <title>Re: calling a method inside a subclass - factory pattern</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/calling-a-method-inside-a-subclass-factory-pattern/m-p/11838386#M1957142</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Christian.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can you give some example working with the interface ?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Sep 2016 10:01:12 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/calling-a-method-inside-a-subclass-factory-pattern/m-p/11838386#M1957142</guid>
      <dc:creator>former_member182337</dc:creator>
      <dc:date>2016-09-02T10:01:12Z</dc:date>
    </item>
    <item>
      <title>Re: calling a method inside a subclass - factory pattern</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/calling-a-method-inside-a-subclass-factory-pattern/m-p/11838387#M1957143</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Christian,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any examples please?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 05 Sep 2016 09:20:10 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/calling-a-method-inside-a-subclass-factory-pattern/m-p/11838387#M1957143</guid>
      <dc:creator>former_member182337</dc:creator>
      <dc:date>2016-09-05T09:20:10Z</dc:date>
    </item>
    <item>
      <title>Re: calling a method inside a subclass - factory pattern</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/calling-a-method-inside-a-subclass-factory-pattern/m-p/11838388#M1957144</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Prem,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;it's hard to give an example as you question is quite abstract. However, I'd try to implement you framework in such a way that you don't need to know the specific subclass to invoke the required method. This can easily be achieved using an interface:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;data: my_example type ref to zif_example_interface.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;my_example = zcl_factory=&amp;gt;get_implementation( ...).&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;my_example-&amp;gt;execute_if_method( ).&lt;/SPAN&gt;&lt;/P&gt;
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;You define a interface (zif_example_interface) that has the necessary methods (execute_if_method). Your subclasses implement this interface and the specific functionality in the concrete interface implementation.&lt;/P&gt;&lt;P&gt;The factory now return a reference to the interface (the concrete implementation depends on the parameters). You now simply invoke the interface methods and don't need care about the concrete implementation returned by the factory.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Christian &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 05 Sep 2016 10:08:53 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/calling-a-method-inside-a-subclass-factory-pattern/m-p/11838388#M1957144</guid>
      <dc:creator>ceedee666</dc:creator>
      <dc:date>2016-09-05T10:08:53Z</dc:date>
    </item>
  </channel>
</rss>

