Right way of defining constants - Interfaces or Classes?

Two widely used ways to define constants in java projects are:
1. Interfaces - Define constants in interfaces, they automatically become static, final and then implement the interface in concrete classes that need those constants.
2. Classes - Use normal classes and define explicitly as static, final. Use CLASS_NAME.CONSTANT_NAME to access the constant in concrete classes.
I have gone through the web on Best-practices for defining constants and its strongly recommended for not using Interfaces for defining constants.
"The constant interface pattern is a poor use of interfaces. That a class uses some constants internally is an implementation detail. Implementing a constant interface causes this implementation detail to leak into the class's exported API. It is of no consequence to the users of a class that the class implements a constant interface. In fact, it may even confuse them. Worse, it represents a commitment: if in a future release the class is modified so that it no longer needs to use the constants, it still must implement the interface to ensure binary compatibility. If a nonfinal class implements a constant interface, all of its subclasses will have their namespaces polluted by the constants in the interface. " from     Effective Java, Joshua Bloch
What is your take on this?
Rgds

I have gone through the web on Best-practices for defining constants and its strongly recommended for not using Interfaces for defining constants.
"The constant interface pattern is a poor use of interfaces. That a class uses some constants internally is an implementation detail. Implementing a constant interface causes this implementation detail to leak into the class's exported API. It is of no consequence to the users of a class that the class implements a constant interface. In fact, it may even confuse them. Worse, it represents a commitment: if in a future release the class is modified so that it no longer needs to use the constants, it still must implement the interface to ensure binary compatibility. If a nonfinal class implements a constant interface, all of its subclasses will have their namespaces polluted by the constants in the interface. " from     Effective Java, Joshua Bloch
I don't like grouping constants into an interface. I prefer keeping them closer to the classes that use them.
%

Similar Messages

  • What is the best way to define constants in SOA ?

    Hi,
    What is the best way to define constants in SOA/BPEL ?

    I want to define at composite level. I have several BPELs in my composite. I have lot of Status and some other codes I need to check/compare/assign in assign activity and xslt transformations
    Ii can use BPEL preferences , but they only applies to that particular BPEL. I want to define all my codes in one place at composite level.
    Thanks
    --Sreeny
    Edited by: sreeny on May 29, 2012 8:59 AM

  • Residence of Constants: Interface vs Class

    Hi Gurus
    I have a very basic question, while defining constants should we put them
    in an interface (say MyConstant) or in a class (say XYZConstant). I am sure, as per java guidelines, they should be in a Constant class and should be used as-
    XYZConstant.Constant1because that's for interfaces are not designed.
    But...putting them in an interface offers a great ease of use. If any class
    wants to use couple of constants just implement that interface and use simply as-
    Constant1 and not like XYZConstants.Constant1This saves space, as well as keeps the code readable AND by proper naming
    of such interface (say UBSConstant) holding only constants, we can pass the message that this interface is not actually an 'interface' but just a constant holder.
    Please comment.
    Thanks
    Anu

    ... > we can pass the message that this
    interface is not actually an 'interface' but
    just
    a
    constant holder.Which is why you shouldn't use an interface forthis
    - 'cause that's not what they're for.
    http://www.javaworld.com/javaworld/javaqa/2001-06/01-q
    a-0608-constants.htmlBelieve me, I have seen constants in interfaces at
    numerous places.Believe me, I have seen all manner of things done in numerous places as well, but I don't see that as an argument that such things are correct.
    Also even when we know that it's improper to have
    interface just for
    constants(because the interfaces are not designed for
    that), I never
    found any disadvantage(If you are talking about the
    cohesion, no maintanance
    in future would suggest to remove these constants,
    moreover I will always
    keep my interface in same package and would always
    bundle it with any release).
    Ok then, with those assumptions I suppose you wouldn't see any disadvantage. I prefer not to assume those things though.
    Using Constants in Class, is sometime really
    troubling...just imagine long
    class name and long constant names (which we would
    often have for good
    readability..reference Java Naming Standards and put
    on top of them that
    80 characters / line rule ...again a java coding
    standard) turning a line
    into two lines...and that code is damn !!!!I tend not to let the amount of typing dictate how I arrange my class hierarchies, but then that might just be me.
    setDimensionParameter(
    ( PropertyControllerConstants.DIMENSION_OF_PROPERTY,
    houseSize); This doesn't look bad to me. But again, that might just be me.
    >
    So is it just! this moral....we should not have
    Constants in interface or
    should enjoy the freedom of putting qualifier by
    implementing constant interface
    and using as-
    setDimensionParameter( DIMENSION_OF_PROPERTY,
    houseSize); Thanks
    AnuSo, the maintainer gets to see that all caps unqualified name and check to see if it's a constant in this class, or any super class of this class, or an interface implemented by this class, or an interface implemented by any superclass.
    no thanks, I'll just qualify my constants.
    But again, that's just me.
    Good Luck
    Lee

  • How to define event hander interface in Class Builder (se24)?

    Hello,
    I've got the following local interface defined.
    INTERFACE lif_alv_grid_event_handler.
      METHODS:
        handle_button_click FOR EVENT button_click OF cl_gui_alv_grid
          IMPORTING es_col_id es_row_no,
        handle_double_click FOR EVENT double_click OF cl_gui_alv_grid
          IMPORTING e_row e_column es_row_no,
        handle_hotspot_click FOR EVENT hotspot_click OF cl_gui_alv_grid
          IMPORTING e_row_id e_column_id es_row_no,
        handle_toolbar FOR EVENT toolbar OF cl_gui_alv_grid
          IMPORTING e_object e_interactive,
        handle_user_command FOR EVENT user_command OF cl_gui_alv_grid
          IMPORTING e_ucomm.
    ENDINTERFACE.
    Now I want to define it as a dictionary object using se24.
    My problem is I could not find the quivalent of "FOR EVENT"
    word in it.
    Is there any chance to do that in Class Builder?
    Best regards
    Pawel

    Hello Pawel
    Display your class with the event handler methods in SE24 / SE80 and choose the DETAIL button (above the table control with the methods).
    Here you can define a method as "event handler for" an event of another class.
    On SAP release >= 6.20 you can right-click on a method in the tree view and choose context menu function Display -> Definition (tabstrip Attributes ).
    Regards
      Uwe

  • Right way to get interface counters in TCL/EEM

    Hello Experts,
    I am looking for your advise about the best way to deal with interface counters inside TCL/EEM on XR. The ultimate goal is to compare rate (bps/pps) over two 10G interfaces and alert user in case they are differ more than 15-20% .
    I can get counters by parsing output of "show interface TenGigX/X/X/X" but , may be more streightforward way is exists, like getting them directly from MIB or from elsewhere ?
    Thank you !

    Using the CLI on XR is probably best since you can get bidrectional utilization in one call.  The SNMP ED would work, but you can only poll for one OID at a time.  So short answer is, you're doing the best thing right now.

  • Defining constants

    I am still completely baffled by my misbehaving tables, so I
    thought I would try
    Murray's suggestion and get rid of the colspans and rowspans.
    While I was about
    it, I thought would be nice to centralise all my magic
    numbers (such as the
    colour of the body of the table, the tables containing the
    images, and so on) in
    the CSS file.
    For example I might wish to define body_colour as #f8f8ff.
    This ought to be
    (and undoubtedly is) dead easy, but, despite all the books on
    CSS I have lying
    around, none list "defining constants", or any equivalent I
    can think of, in the
    index. Nor can I find any examples which demonstrate how to
    do this.
    So the question is
    a. How do I define a constants in the CSS file, and
    b. How do I use it in the HTML?
    [email protected]

    First, please get rid of the spaces in your filenames!
    <img src="Images/Mr Vet.jpg"
    Also, note that any given ID can only be used ONCE on any
    page -
    <table id="pictureframe">
    <table id="pictureframe" align="right">
    If you want to do this kind of thing, make it a custom class
    selector (e.g.,
    <table class="pictureframe">
    , or figure out how to use descendent selectors
    to cascade into each desired element. You double instances of
    #pictureframe
    is most likely the cause of your results.
    Your CSS is way unnecessarily verbose, redundant, and
    cluttered, but I
    suspect that's not what you are looking for right now.
    > The image frames clearly have 2px or 3px of padding, but
    I cannot
    > find out where this value comes from, or how to change
    it.
    Most likely from the text box within which all inline tags
    are rendered.
    Try adding "display:block" to your image CSS to see if that
    would fix this.
    > However the pictures are in the editable region of the
    template, so if I
    > specified the values in the template I would be unable
    to modify the
    > appearance
    > of the images once the pages had been created.
    Sure you can. Just add a little stylesheet to the editable
    region in the
    head of the child page to override the base CSS.
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.dreamweavermx-templates.com
    - Template Triage!
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    http://www.macromedia.com/support/search/
    - Macromedia (MM) Technotes
    ==================
    "Clancy" <[email protected]> wrote in message
    news:[email protected]...
    > Bonnie <"kroko[Occam]"@pixelplum.com> wrote:
    >
    >>It would be better to post a link to the page;
    otherwise it's still a
    >>bit hard to see what you are trying to do. I assume
    from the above you
    >>are placing all your photos inside single-cell
    tables?
    >
    > Yes; I have put an example of what I am trying to do at
    >
    http://www.cybec.com.au/Test_nstdpage.htm
    >
    > I have got a little further with my experiments. The
    specification for
    > the
    > picture frame is now
    >
    > #pictureframe {width: 5%; background-color: #d8d8f0;
    border: 5px solid
    > #88d8e0;
    > }
    >
    > I have finally got the border to work properly, though I
    had no idea why
    > it
    > wasn't working half an hour ago -- I could have sworn
    that I had exactly
    > the
    > same code that have now. I don't want a border at all; I
    just want to
    > specify
    > some padding. The image frames clearly have 2px or 3px
    of padding, but I
    > cannot
    > find out where this value comes from, or how to change
    it.
    >
    > However, with what I have got working, I can fake the
    result I wants by
    > setting
    > the border colour to be the same as the background
    colour. I guess this
    > will
    > do, unless someone can tell me how to make the padding
    work.
    >
    > And, in case you are wondering why I want to specify
    these values in the
    > CSS
    > file, rather than the template, if they are in the CSS
    file I can change
    > the
    > appearance of every image on the web site by changing
    the specification of
    > the
    > picture frame.
    >
    > However the pictures are in the editable region of the
    template, so if I
    > specified the values in the template I would be unable
    to modify the
    > appearance
    > of the images once the pages had been created.
    >
    > [email protected]

  • Interfaces vs classes (performance question)

    I have three classes A, B and X.
    Both A and B use X but they use different methods so I defined two interfaces for X: XA and XB.
    This works fine but is not really necessary - so my question is does this affect performance in any way or is it just a compile time thing?
    Thank you

    TomsterG wrote:
    dcminter wrote:
    That's rarely a good design criterion - although if a class is difficult to work with, it indicates that there's probably something wrong with it.yes yes i know, all good points.
    I really only wanted to know about the performance issues though :)I think you might want to find another site. I can tell that so far you are really not going to like it here.
    You have a design that is broken. I suspected it in reply 1. Other said the same thing and when you said more about your problem it was confirmed. And now your response is "I really only wanted to know about the performance issues"?
    Seriously. You are not going to like the replies you get on this site. We don't give a flying whatsit about performance issues when it comes at the cost of having a horrible design with classes with 100 methods. Because nobody here wants to maintain applications built on that abortion of a design so we all do our best to discourage that sort of thinking.
    But your replies really suggest that you don't get it, you don't care and you think you are superior in your needs and ideas to anyone who might be interested in responding to your posts.
    It's a waste of your time.

  • Right way of configuring higher MTU over a Port Channel

    Hi guys,
    I have a running critical Port-Channel between two locations.
    Here's the config
    SW1:
    interface Port-channel2
     switchport
     switchport trunk encapsulation dot1q
     switchport mode trunk
    end
    interface GigabitEthernet1/45
     switchport trunk encapsulation dot1q
     switchport mode trunk
     channel-protocol lacp
     channel-group 2 mode active
    end
    interface GigabitEthernet1/46
     switchport trunk encapsulation dot1q
     switchport mode trunk
     channel-protocol lacp
     channel-group 2 mode active
    end
    SW2
    interface GigabitEthernet1/1
     switchport trunk encapsulation dot1q
     switchport mode trunk
     channel-protocol lacp
     channel-group 2 mode passive
    end
    interface GigabitEthernet1/2
     switchport trunk encapsulation dot1q
     switchport mode trunk
     channel-protocol lacp
     channel-group 2 mode passive
    end
    interface Port-channel2
     switchport
     switchport trunk encapsulation dot1q
     switchport mode trunk
    end
    Now I need to increase the MTU from default value to 9198. What the right way to do it and avoid any connectivity loss, PortChannel restart.
    Does it matter what switch I start first?
    Thanks!
    L.E. both SW are WS-C4948

    Hi,
    Because you are using layer 2 interfaces - there is no fragmentation support at layer 2, and interfaces receiving frames which have an unsupported size will be dropped.
    I think the best way for you to proceed is to lab this up; and verify what happens - it may be that you need to make changes on switches at either end of the channel within a very short time frame to prevent too large an outage.
     When you are ready to maike your change - think the best way to do this is to use the interface range command, and apply the 'mtu' command to all the interfaces in this range. I don't think it matters which switch you apply this change to first, and I don't believe if you are hinting at the 802.3ad (controlled by system-priority) decision maker, that it makes any difference.
    HTH
    Mike

  • Right way to dispose frame/components/containers?

    Hi,
    My application creates a lot of frames with lots of containers and components (heavyweights as well as light weights) inside them. I have obeserved that none of the frames/containers/components get finalized unless I do a remove/removeAll() over the respective container. Currently I just make a call to frame.dispose() to dispose it off and assume that all components would be reclaimed by the garbage collector at some point of time. Is that the right way to dispose off the frames and mark all its child components for garbage collection? Or is an explicit call to removeAll() required to release the memory. I am aware that garbage collection doesn't happen immediately and may take a while before the GC collects objects. I have run the application continuously for couple of hours and created/disposed a lot of frames during that period. GC recollected none of them (none of the components either) except for those that were removed by an explicit call to remove or removeAll during the lifetime of the session. I even hit OOM errors but none of the components were recollected.
    What could be the problem?
    Some additional information:
    I overridden removeNotify() and finalize() methods to see what's going on. For all components removeNotify() was called (even if I don't do explicit remove/removeAll and just dispose off the frame) but finalize never gets called. My methods:
         public void removeNotify()
              super.removeNotify();
              System.out.println("Remove notify called "+compId);
         protected void finalize() throws Throwable
              super.finalize();
              System.out.println("Finalized component "+compId);
         }Thanks in advance.
    Edited by: crack_it on Jul 31, 2009 8:52 AM

    Sorry to bother guys. The problem was not with AWT but with one evil component that was displayed inside most of my Frame classes and was also registered as an Observer with an Observable class. The event at which the component was supposed to unregister itself with Observable never got fired and this one reference prevented garbage collection of entire gui brigade. Damn! Tiny monster.
    Anyway the issue stands resolved. Thanks for your time.

  • Right way to declare field symbols

    i am new to field symbols, pls  help
    i want to know which  is the right way of declaration ?
    types: begin of typ_tab,
               vbeln  type vbap-vbeln,
               posnr type vbap-posnr,
               matnr  type vbap-matnr,
              end of typ_tab.
    data:  itab type standard table of typ_tab,
              wa  type typ_tab.
    field-symbols: <f_t> type standard table, 
                           <f_w> type any,                or      <f_w>  like  line of typ_tab,  ??
                            <f_s> type any.
    select  vbeln posnr  ....... into itab......
    assign  itab to <f_t>.
    assign wa  to <f_w>.
    loop at <f_t> assigning <f_w>.
    assign component 'vbeln' of structure <f_w>  to <f_s>.
    write : / <f_s>.
    endloop.
    OR
    loop at itab assigning <f_w>. 
    write: / <f_w>-vbeln.
    endloop. 
    r these 2 statements correctt ? if so then which one  to use,  pls show with an example. wats the diff btwn above 2  types of  looping statements ?   how to use read statement on this ?

    Hello Saurajit,
    Both the way are correct. And it depends on the requirement, which one to use.
    <f_w> TYPE ty_tab - is TYPED field symbol - if you know TYPE before runtime you can use this. It will just work like a static work area.
    <f_w> TYPE any - is not TYPED and structure of this field symbol is defined during runtime using ASSIGN statement. And fields of the structure is read by ASSIGN COMPONENT <<field name>> statement.

  • Can you define constants in Report Painter?

    Hi, I'm new to Report Painter and SAP in general. I was just wondering if it's possible to define constants that are visible across reports. e.g. In the header text for all our reports, we want our company name to be displayed. But instead of hardcoding it, we want to retrieve it from a constant or variable.
    Does anyone know if this is possible?

    Hi Andrew,
    Thanks for the response but this isn't exactly what I was looking for. From my understanding, the "Sel. Parameters" button allows you to access and display values that were entered by the user in the selection screen of the report (correct me if I'm wrong). What I'm aiming for is something like a global variable defined on the backend that all reports can access.
    I've looked at the other buttons that you pointed out, but it seems like I'm only able to use some pre-defined tables and fields. Does this mean that there isn't any way for me to define and use my own customized variables for reports?
    Thanks,
    Carlo
    Edited by: CarloInting on Jul 21, 2009 5:45 AM

  • Best way to define mapping

    Hi
    I am evaluating Kodo in the prospect to migrate an existing application
    which uses a different JDO implementation and I am currently wondering
    what is the best way to define the mapping.
    So far, we have only used __.jdo__ metadata file with default values and
    some jdo extension. Then we delegate to the JDO implementation the task to
    define the schema and create it in the relationnal database.
    I am trying to reproduce the same process with KODO. But :
    - I am encountering some problem with the kodo extension.(but they are
    certainly some mistake from my part, I will introduce some at the end of
    this email)
    - I understand that kodo can use a mapping file.
    Here are my very first questions
    - Which method should I use. Only JDO extension, or mapping file.
    - if I use the mapping file, is it possible to only specify info for
    fields which are different than default behavior of kodo
    - If I use the jdo extension only how can I :
    specify the name of a table for a particular class?
    specify the name of a join table?
    Specify the name of a column for a particular java field?
    Is there a way to configure the mapping tool to use a custom naming
    convention for the whole project (for a particular package)?
    I already made a small evaluation of kodo 7 month ago with version 3.1.0,
    but with this version, there was a bug discussed in this forum which
    forced me to use the mapping file. But I had to define the complete
    mapping, which was a huge task especially when you have to repeat field
    mapping for sub classes. My first tests with kodo 3.2.2 works with jdo
    extension, but I still have some issues as you can see from my questions.
    Thank you for your answer.
    Nicolas GANDRIAU
    Environment description
    Kodo 3.2.2 evaluation
    MySQL 4.1.4-gamma'-Max'
    MySQL Connector/J 3.0.15-ga
    JDK 1.4.2_05 de Sun
    Linux Kernel 2.6.8 (Mandrake 10.1)
    IDEA 4.5.2

    Nicolas,
    You need to define which mapping file using the kodo.jdbc.MappingFactory
    extension. Note that with either format that the mapping information
    must be complete (or you can have Kodo create them for you):
    http://solarmetric.com/Software/Documentation/3.2.2/docs/ref_guide_conf_kodo.html#kodo.jdbc.MappingFactory
    The metadata mapping factory is more verbose though all of your
    information is in a single file. .mapping files are more consise but
    need to be deployed in addition to your .jdo metadata.
    Nicolas GANDRIAU wrote:
    Hi
    I am evaluating Kodo in the prospect to migrate an existing application
    which uses a different JDO implementation and I am currently wondering
    what is the best way to define the mapping.
    So far, we have only used __.jdo__ metadata file with default values and
    some jdo extension. Then we delegate to the JDO implementation the task to
    define the schema and create it in the relationnal database.
    I am trying to reproduce the same process with KODO. But :
    - I am encountering some problem with the kodo extension.(but they are
    certainly some mistake from my part, I will introduce some at the end of
    this email)
    - I understand that kodo can use a mapping file.
    Here are my very first questions
    - Which method should I use. Only JDO extension, or mapping file.
    - if I use the mapping file, is it possible to only specify info for
    fields which are different than default behavior of kodo
    - If I use the jdo extension only how can I :
    specify the name of a table for a particular class?
    specify the name of a join table?
    Specify the name of a column for a particular java field?
    Is there a way to configure the mapping tool to use a custom naming
    convention for the whole project (for a particular package)?
    I already made a small evaluation of kodo 7 month ago with version 3.1.0,
    but with this version, there was a bug discussed in this forum which
    forced me to use the mapping file. But I had to define the complete
    mapping, which was a huge task especially when you have to repeat field
    mapping for sub classes. My first tests with kodo 3.2.2 works with jdo
    extension, but I still have some issues as you can see from my questions.
    Thank you for your answer.
    Nicolas GANDRIAU
    Environment description
    Kodo 3.2.2 evaluation
    MySQL 4.1.4-gamma'-Max'
    MySQL Connector/J 3.0.15-ga
    JDK 1.4.2_05 de Sun
    Linux Kernel 2.6.8 (Mandrake 10.1)
    IDEA 4.5.2
    Steve Kim
    [email protected]
    SolarMetric Inc.
    http://www.solarmetric.com

  • How to approach ABAP OO programming the right way...

    Hello experts,
    I am an old school procedural ABAP programmer and I recently I have been experementing with ABAP Objects since I've read a few columns the advantages of ABAP OO and also currently learning its syntax. Now, does ABAP Objects conform to the old way of say, doing reports like at selection-screen output, at selection-screen, on value-request for..., start-of-selection, end-of-selection, top-of-page, etc. I have been doing some practice programs and I am not sure if my approach is correct. Example, I created a class named cl1 and I have a method named upload. Now, the UPLOAD method contains the function 'GUI_UPLOAD'. Is this the right way of doing it? Also, How come I cannot create structures inside a class?
    Again, thanks guys and have a nice day!

    Hi,
    I have these three progs from one of the previous posts.
    Good approach on using constructors. I am not finding the original link.
    *& Report ZABAP_OBJ_01 *
    REPORT zabap_obj_01 .
    PARAMETERS : p_vbeln LIKE vbap-vbeln OBLIGATORY,
                 p_matnr LIKE mara-matnr.
    TYPES : BEGIN OF ty_vbap,
    vbeln TYPE vbap-vbeln,
    matnr TYPE vbap-matnr,
    arktx TYPE vbap-arktx,
    END OF ty_vbap.
    * CLASS sales_order DEFINITION
    CLASS sales_order DEFINITION.
      PUBLIC SECTION.
        DATA : v_matnr TYPE mara-matnr,
        v_vbeln TYPE vbap-vbeln.
        METHODS : constructor IMPORTING vbeln TYPE vbap-vbeln
        matnr TYPE mara-matnr OPTIONAL.
        DATA : it_vbap TYPE STANDARD TABLE OF ty_vbap.
        METHODS : get_vbap_details,
        disp_vbap_details.
    ENDCLASS. "sales_order DEFINITION
    * CLASS sales_order IMPLEMENTATION
    CLASS sales_order IMPLEMENTATION.
      METHOD get_vbap_details.
        CLEAR : it_vbap.
        REFRESH : it_vbap.
        SELECT vbeln
        matnr
        arktx
        FROM vbap
        INTO TABLE it_vbap
        WHERE vbeln = p_vbeln.
      ENDMETHOD. "get_vbap_details
      METHOD constructor.
        CLEAR : v_vbeln,
        v_matnr.
        v_vbeln = vbeln.
        v_matnr = matnr.
      ENDMETHOD. "constructor
      METHOD disp_vbap_details.
        DATA : wx_vbap LIKE LINE OF it_vbap.
        LOOP AT it_vbap INTO wx_vbap.
          WRITE :/ wx_vbap-vbeln,
          wx_vbap-matnr,
          wx_vbap-arktx.
        ENDLOOP.
        CLEAR : it_vbap.
      ENDMETHOD. "disp_vbap_details
    ENDCLASS. "sales_order IMPLEMENTATION
    DATA : obj TYPE REF TO sales_order.
    START-OF-SELECTION.
      IF NOT p_matnr IS INITIAL.
        CREATE OBJECT obj EXPORTING vbeln = p_vbeln
        matnr = p_matnr.
      ELSE.
        CREATE OBJECT obj EXPORTING vbeln = p_vbeln.
      ENDIF.
      CALL METHOD obj->get_vbap_details.
      CALL METHOD obj->disp_vbap_details.
    *& report ziga_abapobjects_asgn01 *
      REPORT ziga_abapobjects_asgn01 .
      PARAMETER : p_matnr LIKE mara-matnr.
    * CLASS lcl_material DEFINITION
    CLASS lcl_material DEFINITION.
      PUBLIC SECTION.
        DATA: v_matnr TYPE mara-matnr.
        METHODS : constructor IMPORTING matnr TYPE mara-matnr,
        get_material_description.
      PRIVATE SECTION.
        DATA : v_maktx TYPE makt-maktx.
    ENDCLASS. "lcl_material DEFINITION
    * CLASS lcl_material IMPLEMENTATION
    CLASS lcl_material IMPLEMENTATION.
      METHOD get_material_description.
        CLEAR v_maktx.
        SELECT SINGLE maktx INTO v_maktx
        FROM makt
        WHERE matnr = v_matnr AND
        spras = 'E'.
      ENDMETHOD. "get_material_description
      METHOD constructor.
        CLEAR v_matnr.
        v_matnr = matnr.
      ENDMETHOD. "constructor
    ENDCLASS. "lcl_material IMPLEMENTATION
    DATA : obj TYPE REF TO lcl_material.
    START-OF-SELECTION.
      CREATE OBJECT obj EXPORTING matnr = p_matnr.
      CALL METHOD obj->get_material_description.
      prg3)
      report ziga_abapobjects_asgn01 .
      PARAMETER : p_matnr LIKE mara-matnr.
    * CLASS lcl_material DEFINITION
    CLASS lcl_material DEFINITION.
      PUBLIC SECTION.
        METHODS : constructor IMPORTING matnr TYPE mara-matnr,
        write_material_desc.
        CLASS-METHODS : class_constructor.
      PRIVATE SECTION.
        CLASS-DATA: v_matnr TYPE mara-matnr.
        DATA : v_maktx TYPE makt-maktx.
        METHODS : get_material_description.
    ENDCLASS. "lcl_material DEFINITION
    * CLASS lcl_material IMPLEMENTATION
    CLASS lcl_material IMPLEMENTATION.
      METHOD get_material_description.
        CLEAR v_maktx.
        SELECT SINGLE maktx INTO v_maktx
        FROM makt
        WHERE matnr = v_matnr AND
        spras = 'E'.
      ENDMETHOD. "get_material_description
      METHOD constructor.
        WRITE :/ 'Inside Instance Constructor'.
        CLEAR v_matnr.
        v_matnr = matnr.
        CALL METHOD get_material_description.
      ENDMETHOD. "constructor
      METHOD write_material_desc.
        WRITE :/ 'Material Description :', v_maktx.
      ENDMETHOD.                    "write_material_desc
      METHOD class_constructor.
        WRITE :/ 'Inside Static Constructor'.
      ENDMETHOD.                    "class_constructor
    ENDCLASS. "lcl_material IMPLEMENTATION
    DATA : obj TYPE REF TO lcl_material,
    obj1 TYPE REF TO lcl_material.
    START-OF-SELECTION.
      CREATE OBJECT obj EXPORTING matnr = p_matnr.
      CALL METHOD obj->write_material_desc.
      CREATE OBJECT obj1 EXPORTING matnr = '000000000000000110'.
      CALL METHOD obj1->write_material_desc.
      CALL METHOD obj->write_material_desc.
      prg4)
      report ziga_abapobjects_asgn01 .
      PARAMETER : p_matnr LIKE mara-matnr.
    * CLASS lcl_material DEFINITION
    CLASS lcl_material DEFINITION.
      PUBLIC SECTION.
        METHODS : constructor IMPORTING matnr TYPE mara-matnr,
        write_material_desc,
        get_material_description.
        CLASS-METHODS : class_constructor.
      PRIVATE SECTION.
        CLASS-DATA: v_matnr TYPE mara-matnr.
        DATA : v_maktx TYPE makt-maktx.
    ENDCLASS. "lcl_material DEFINITION
    * CLASS lcl_material IMPLEMENTATION
    CLASS lcl_material IMPLEMENTATION.
      METHOD get_material_description.
        CLEAR v_maktx.
        SELECT SINGLE maktx INTO v_maktx
        FROM makt
        WHERE matnr = v_matnr AND
        spras = 'E'.
      ENDMETHOD. "get_material_description
      METHOD constructor.
        WRITE :/ 'Inside Instance Constructor'.
        CLEAR v_matnr.
        v_matnr = matnr.
      ENDMETHOD. "constructor
      METHOD write_material_desc.
        WRITE :/ 'Material Description :', v_maktx.
      ENDMETHOD.                    "write_material_desc
      METHOD class_constructor.
        WRITE :/ 'Inside Static Constructor'.
      ENDMETHOD.                    "class_constructor
    ENDCLASS. "lcl_material IMPLEMENTATION
    DATA : obj TYPE REF TO lcl_material,
    obj1 TYPE REF TO lcl_material.
    START-OF-SELECTION.
      CREATE OBJECT obj EXPORTING matnr = p_matnr.
      CALL METHOD obj->get_material_description.
      CALL METHOD obj->write_material_desc.
      CREATE OBJECT obj1 EXPORTING matnr = '000000000000000110'.
      CALL METHOD obj1->get_material_description.
      CALL METHOD obj1->write_material_desc.
      CALL METHOD obj->get_material_description.
      CALL METHOD obj->write_material_desc.
      REPORT ziga_abapobjects_asgn01 .
      PARAMETER : p_matnr LIKE mara-matnr.
    * CLASS lcl_material DEFINITION
    CLASS lcl_material DEFINITION.
      PUBLIC SECTION.
        CLASS-METHODS : write_material_desc,
        get_material_description,
        class_constructor.
      PRIVATE SECTION.
        CLASS-DATA: v_matnr TYPE mara-matnr.
        CLASS-DATA: v_maktx TYPE makt-maktx.
    ENDCLASS. "lcl_material DEFINITION
    * CLASS lcl_material IMPLEMENTATION
    CLASS lcl_material IMPLEMENTATION.
      METHOD get_material_description.
        CLEAR v_maktx.
        SELECT SINGLE maktx INTO v_maktx
        FROM makt
        WHERE matnr = v_matnr AND
        spras = 'E'.
      ENDMETHOD. "get_material_description
      METHOD write_material_desc.
        WRITE :/ 'Material Description :', v_maktx.
      ENDMETHOD.                    "write_material_desc
      METHOD class_constructor.
        WRITE :/ 'Inside Static Constructor'.
        v_matnr = '000000000000000110'.
      ENDMETHOD.                    "class_constructor
    ENDCLASS. "lcl_material IMPLEMENTATION
    START-OF-SELECTION.
      CALL METHOD lcl_material=>get_material_description.
      CALL METHOD lcl_material=>write_material_desc.
    Arun Sambargi.

  • Use of events and interface in class

    Dear All,
    Could you please explain why we use events and interface in class.
    Also please tell me the use of TRY and ENDTRY.
    Regards,
    Amar

    Events may be a way of communication b/w classes. Imagine you want to call certain code from one class, you would need for that public method, but you don't want to expose it to external user. So you may use events for that. Also events are used to notify that certain state of class has changed (tiggering event). Then all handlers of this event executes and react accordingly.
    Interfaces are a way of provide a service to class which implements it. Imagine that you have class office and hotel and gas station . They don't seems to have something in common. However, there can be some external energy provider which will be an interface. Each class which want to have a lease with this energy provided can implement it (the implementation can differ in some way), so he can provided energy to different classes. This way you will achieve polimorphism (meaning you call one interface method, but code behind it differs from class to class).
    Interfaces are also means of multiple inheritance. One class can implement several service (interfaces). In contrary it can oly inherit from one class.
    Try endtry are just new way of handling exceptions .
    Try to search a litte bit you will find lots of info on the above.
    Regards
    Marcin

  • Implements the method defined in interface

    I defined a interface such as
    interface IAuthorizer{
    boolean checkPermission(Set<IAttribute> subj, Set<IAttribute> Permission);
    In java 5, why does compiler not accept the method checkPermission signature of the following class
    class Auth1 implements IAuthorizer{
    boolean checkPermission(Set<IAttribute> subj, Set<IAttribute> Permission){
    Iclass Auth1 implements IAuthorizer{
    boolean checkPermission(Set subj, Set Permission){
    nstead, the compiler only accepts

    <If you compile the interface and the class in the same time (eg not having the interface in a jar file against which to compile the class), the compiler should accept your code.>
    The interface and class is even in the same package. The compiler does not accept method signature as
    boolean checkPermission(Set<IAttribute> subj, Set<IAttribute> perms)
    <If your interface is part of a library jar file, could it be that
    - the library is obfuscated using an obfuscater that doesn't know about generics?
    - the class is written against JDK 1.4 API (in which Set is not generic)?
    - the class is compiled using java 1.4 compiler?
    >
    no library is involved in the issue.
    class is written in JDK 1.5 API and use JDK 1.5 compiler.

Maybe you are looking for

  • Urgent 508 Question!

    The only thing i need to do is add a title or label attribute to some of the controls. One of the ones to begin with that i am fixing is the ADF tag af:selectBooleanRadio. When i add some text to the shortDesc field of the control, the html is produc

  • ITunes upgrade fails

    Every attempt to install iTunes upgrades since 0.1.0.79 has failed. It was suggested to download and install manually. This also fails. Any thoughts or suggestions appreciated. ken

  • Running FDS2 Express as a service on Linux (Fedora Core)

    Hello, I've just installed the Flex Data Service 2 Express on a dedicated server running on linux (Fedora Core). I can run the server and everything works fine but as soon as I loggout, the server stops running. I believe I need to run as a "backgrou

  • I lost some of my pictures

    i lost some of my pictures when i restore from i cloud on a new iphone 4s

  • Not synced when I activated....now no Outlook to sync

    Hi everybody, I activated my iPhone but I didn't sync contacts and calendar in the biginning because I didn't have Outlook installed yet, thought I could do it later since I was using Palm Desktop. I then istalled Outlook. Now when I check for syncin