Skip to Content

Reg: Public and Private class

Hi all

I am new to abab objects and i got the technical details about public as well as private section..can any one let me in which case we have to go for public and in which case we have to go for private section and what are the limitation in both the cases??

Thanks

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

9 Answers

  • Best Answer
    avatar image
    Former Member
    Sep 02, 2008 at 03:56 PM

    Declare all your Methods in Public section and all your data in the private section.

    Use your methods to access the private data.

    Thanks,

    Karthik

    Add comment
    10|10000 characters needed characters exceeded

    • Hey All,

      I would agree with Matthew's approach. But more generally its a question of design. While thinking about the design of your application/module or whatever, you should carefully take into consideration who should have access to what and who should be allowed to see what.

      When implementing a pattern, e.g. singleton, there are certain rules (a private constructor which is called by a public getInstance Method) which you should stick to or take into account.

      So there is no general answer on what kind of accessibility or access you should choose, it always depends on your application and how you would like others to use it and be save that nothing brakes. Just be aware of what different techniques really mean and try to use them to solve problems at design-time.

      A tutorial, like suggested before, can give you the security to understand the impact of declaring something as private, protected or public and by that increase your confidence that you know what you are doing.

      Cheers,

      Justus

  • avatar image
    Former Member
    Sep 04, 2008 at 04:56 AM

    Hi,

    ABAP OBJECTS is an Object Oriented part of ABAP. Now to start with ABAP Objects, I would suggest you to first read some documentation on Object Oriented Programming.

    Private attributes are the attributes which are declared in Private section of a class. These attrbutes cannot be accessed from outside the class. This is called Information Hiding or Encapsulation.

    Public attributes are those attributes which can be accessed by outside user.They are declared in PUBLIC SECTION of class.

    Check this link, this link will guide you on ABAP OBJECTS.

    http://www.sap-press.de/katalog/buecher/htmlleseproben/gp/htmlprobID-28?GalileoSession=22448306A3l7UG82GU8#level3~3

    Regards

    Abhijeet

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 02, 2008 at 04:29 PM

    This message was moderated.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 03, 2008 at 05:37 AM

    This message was moderated.

    Add comment
    10|10000 characters needed characters exceeded

  • Sep 03, 2008 at 06:14 AM

    Hi..

    sometimes a little googling helps...

    Check this : http://www.abaplearning.com/abap-tutorials/abap-objects

    A very good example of public, private and protected attributes / methods is given.

    Check it out ..

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 04, 2008 at 04:48 AM

    This message was moderated.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 04, 2008 at 05:02 AM

    This message was moderated.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 04, 2008 at 09:03 AM

    Hi Shankar,

    Please check these threads

    visibility-sections

    visibility-of-component

    public-n-private-access

    reg-create-private-public-protected

    Check this WIKI for example regarding VISIBILITY SECTION.

    https://www.sdn.sap.com/irj/sdn/wiki?path=/display/snippets/abapObjects-CreatingyourFirstLocalClass-Definingthe+Visibility

    If you want more.. Search SDN for these kind of questions...

    Good luck

    Narin

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Dec 01, 2008 at 05:51 AM

    hi Radhu Shankar G

    if u want tht ur one class element is access by the other class by inhert tht call...thn u declare tht class as public..or the element of tht as public....

    nd if u want tht no other class can access the elemt of the base tthn declarre it as private....nd onn inheritance these class element r nt access by the other class object...fine..

    regards

    Ritesh

    Add comment
    10|10000 characters needed characters exceeded