<?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: Constants - To be declared in class or interface? in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/constants-to-be-declared-in-class-or-interface/m-p/6757599#M1461124</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I know it is done in the standard, but personally I do not like the practice of using interfaces for constants. Coming from a Java background, I consider this an anti-pattern. The main idea of an interface is to expose the behavior of a class and hiding the implementation detail. Inventing an interface and throwing in constants without regard to the previous consideration makes me squirm.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I absolutely have to have a place for global constants, I prefer an abstract class. An added advantage is that you can have table-type constants as read-only static variables that are initialized in the class constructor.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-- Sebastian&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 29 Mar 2010 14:48:21 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2010-03-29T14:48:21Z</dc:date>
    <item>
      <title>Constants - To be declared in class or interface?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/constants-to-be-declared-in-class-or-interface/m-p/6757595#M1461120</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello OO gurus,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The place where I work is upgrading SAP version and now all developments must be done using OO concepts. I am already familiar with this concept but i have one doubt regarding its application in ABAP programs.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I transformed a existing procedural report into a object oriented report. I declared all the constants used in this program in a separated &lt;STRONG&gt;class&lt;/STRONG&gt; as follows:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
CLASS: cl_constants_handler DEFINITION.
  PUBLIC SECTION.
    CONSTANTS:
            c_h1(10)          TYPE c    VALUE   'Purch.Doc.',
            c_h2(09)          TYPE c    VALUE   'Doc. date',
" (...)
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However i saw that constants are declared in &lt;STRONG&gt;interfaces&lt;/STRONG&gt; in standards programs. Then, classes need to implement these interfaces to used them. Examples: IF_BCB_ITEM_CONSTANTS, IF_CRM_CONSTANT1,  IF_UA_APPLICATION_CONSTANTS&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My question is: what is the advantage to declare constants in interfaces instead of classes?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 29 Mar 2010 13:59:33 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/constants-to-be-declared-in-class-or-interface/m-p/6757595#M1461120</guid>
      <dc:creator>FabioPagoti</dc:creator>
      <dc:date>2010-03-29T13:59:33Z</dc:date>
    </item>
    <item>
      <title>Re: Constants - To be declared in class or interface?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/constants-to-be-declared-in-class-or-interface/m-p/6757596#M1461121</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think there is no big advantage in defining constants in an interface. All constants are address as static components so you can use any public constant of any class you want.&lt;/P&gt;&lt;P&gt;Here the interface just introduce new logical grouping. You can store all the constants in one place and call the interface some more meaningfully like i.e. "if_physics" than just addressing them from different classes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Personally I prefer to use interfaces as a central point for &lt;EM&gt;types&lt;/EM&gt; which I use accross several classes. This way I don't need to define them separately in each class, I just implement right interface.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So, in my opinion this is all about logical data grouping, to make the program more meaningful to other developer.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Marcin&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 29 Mar 2010 14:10:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/constants-to-be-declared-in-class-or-interface/m-p/6757596#M1461121</guid>
      <dc:creator>MarcinPciak</dc:creator>
      <dc:date>2010-03-29T14:10:00Z</dc:date>
    </item>
    <item>
      <title>Re: Constants - To be declared in class or interface?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/constants-to-be-declared-in-class-or-interface/m-p/6757597#M1461122</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Marcin!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;First of all.. thanks a lot! We think in the same way &lt;SPAN __jive_emoticon_name="happy"&gt;&lt;/SPAN&gt; ... in this example report, i also created a separated class for &lt;EM&gt;types&lt;/EM&gt;. It is really helpful.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I don't know if i was clear enough, but i used a single class in this report too. I made a logical separation using a class instead of an interface, like 'lcl_physics'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It's really good to know that i am in the right way... it would be great if SDN had a source of information about OO best pratices like that one.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 29 Mar 2010 14:32:47 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/constants-to-be-declared-in-class-or-interface/m-p/6757597#M1461122</guid>
      <dc:creator>FabioPagoti</dc:creator>
      <dc:date>2010-03-29T14:32:47Z</dc:date>
    </item>
    <item>
      <title>Re: Constants - To be declared in class or interface?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/constants-to-be-declared-in-class-or-interface/m-p/6757598#M1461123</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hej Fabio,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Yes, I agree. If there was a such document, we could add this advise there &lt;SPAN __jive_emoticon_name="happy"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;&lt;P&gt;Marcin&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 29 Mar 2010 14:37:40 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/constants-to-be-declared-in-class-or-interface/m-p/6757598#M1461123</guid>
      <dc:creator>MarcinPciak</dc:creator>
      <dc:date>2010-03-29T14:37:40Z</dc:date>
    </item>
    <item>
      <title>Re: Constants - To be declared in class or interface?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/constants-to-be-declared-in-class-or-interface/m-p/6757599#M1461124</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I know it is done in the standard, but personally I do not like the practice of using interfaces for constants. Coming from a Java background, I consider this an anti-pattern. The main idea of an interface is to expose the behavior of a class and hiding the implementation detail. Inventing an interface and throwing in constants without regard to the previous consideration makes me squirm.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I absolutely have to have a place for global constants, I prefer an abstract class. An added advantage is that you can have table-type constants as read-only static variables that are initialized in the class constructor.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-- Sebastian&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 29 Mar 2010 14:48:21 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/constants-to-be-declared-in-class-or-interface/m-p/6757599#M1461124</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-03-29T14:48:21Z</dc:date>
    </item>
    <item>
      <title>Re: Constants - To be declared in class or interface?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/constants-to-be-declared-in-class-or-interface/m-p/6757600#M1461125</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;that's a very good point of view Sebastian.&lt;/P&gt;&lt;P&gt;Do someone splitt the constants in different classes for increase logical separation?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 31 Mar 2010 17:42:31 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/constants-to-be-declared-in-class-or-interface/m-p/6757600#M1461125</guid>
      <dc:creator>FabioPagoti</dc:creator>
      <dc:date>2010-03-31T17:42:31Z</dc:date>
    </item>
    <item>
      <title>Re: Constants - To be declared in class or interface?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/constants-to-be-declared-in-class-or-interface/m-p/6757601#M1461126</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Halo Fabio,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In ABAP the problem with the interface is it makes the code unreadable .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I suggest that you have a seperate hierarchies for Model and GUI . All the classes should inherit from a parent Model and parent GUI class. All the GUI relted constants should be added in parent GUI class so that it appears and can be used in GUI sub classes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Similarly all the Model related constants should be added in Model Parent class so that it gets inherited to the Model Sub classes&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 06 Apr 2010 09:03:46 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/constants-to-be-declared-in-class-or-interface/m-p/6757601#M1461126</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-04-06T09:03:46Z</dc:date>
    </item>
    <item>
      <title>Re: Constants - To be declared in class or interface?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/constants-to-be-declared-in-class-or-interface/m-p/6757602#M1461127</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;the problem is there is no multiple inheritance in ABAP OO : a class has only one parent class&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;that's why we use interfaces to store constants: this way we just have to "implement" each interface with needed constants (I mean it is possible to have several interfaces in the same class, and so to get constants from several at the same time)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Apr 2010 14:25:13 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/constants-to-be-declared-in-class-or-interface/m-p/6757602#M1461127</guid>
      <dc:creator>franois_henrotte</dc:creator>
      <dc:date>2010-04-07T14:25:13Z</dc:date>
    </item>
  </channel>
</rss>

