09-02-2008 4:33 PM
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
09-02-2008 4: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
09-02-2008 4: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
09-02-2008 10:49 PM
Hello Radhu
You will find many ABAP classes where you have public instance attributes yet they are read-only, e.g. (IF_PT_EMPLOYEE~PERNR of CL_PT_EMPLOYEE).
Adavantage of such an approach (instead of a GET method for the PERNR) is the more direct access to this key attribute of the class.
Regards
Uwe
09-03-2008 9:51 AM
>
> 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
A good start, but not right
Only methods that are designed to be accessed outside of the class should be public. Methods that are designed to be used only by the class or its subclasses should be protected. Methods that are designed to be use only by the class should be private.
Same goes for attributes, types etc.
Essentially, everything should be private, unless it needs to be otherwise.
Some developers will tell you that ALL attributes should be private/protected, and they should only be accessible, publicly, through setter and getter methods. This is my preferred approach, but I wouldn't insist on it.
09-03-2008 11:13 AM
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
09-02-2008 5:29 PM
09-03-2008 6:37 AM
09-03-2008 7: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 ..
09-04-2008 5:48 AM
09-04-2008 5: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.
Regards
Abhijeet
11-28-2008 12:34 PM
09-04-2008 6:02 AM
09-04-2008 9:29 AM
Same example as Sridevi D
Did you both cut and paste from the same source?
09-04-2008 9:37 AM
09-04-2008 10:03 AM
Hi Shankar,
Please check these threads
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
12-01-2008 5: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