Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Classes

Former Member
0 Likes
672

Hi,

plz give me solution

Difference between public and private classes wrf ABAP Objects?

4 REPLIES 4
Read only

Former Member
0 Likes
620

Visibility Sections

You can divide the declaration part of a class into up to three visibility areas:

CLASS class DEFINITION.

PUBLIC SECTION.

...

PROTECTED SECTION.

...

PRIVATE SECTION.

...

ENDCLASS.

These areas define the external visibility of the class components, that is, the interface between the class and its users. Each component of a class must be assigned to one of the visibility sections.

Public Section

All of the components declared in the public section are accessible to all users of the class, and to the methods of the class and any classes that inherit from it. The public components of the class form the interface between the class and its users.

Protected Section

All of the components declared in the protected section are accessible to all methods of the class and of classes that inherit from it. Protected components form a special interface between a class and its subclasses. Since inheritance is not active in Release 4.5B, the protected section currently has the same effect as the private section.

Private Section

Components that you declare in the private section are only visible in the methods of the same class. The private components are not part of the external interface of the class.

for more help :

http://help.sap.com/saphelp_nw70/helpdata/en/73/d18759b27011d194ef0000e8353423/frameset.htm

Edited by: Abap-fresher on Mar 29, 2008 7:24 AM

Read only

uwe_schieferstein
Active Contributor
0 Likes
620

Hello

Public classes (i.e. instantiation is public) can be instantiated directly.

Example: CL_PO_HEADER_HANDLE_MM

Private (or protected) classes (i.e. instantiation is private or protected) require a static factory method or a factory class for instantiation.

Example: IF_RECA_MESSAGE_LIST / CL_RECA_MESSAGE_LIST => factory class CF_RECA_MESSAGE_LIST

Regards

Uwe

Read only

Former Member
0 Likes
620

Hi,

These areas define the external visibility of the class components, that is, the interface between the class and its users. Each component of a class must be assigned to one of the visibility sections.

Public Section

All of the components declared in the public section are accessible to all users of the class, and to the methods of the class and any classes that inherit from it. The public components of the class form the interface between the class and its users.

Protected Section

All of the components declared in the protected section are accessible to all methods of the class and of classes that inherit from it. Protected components form a special interface between a class and its subclasses. Since inheritance is not active in Release 4.5B, the protected section currently has the same effect as the private section.

Private Section

Components that you declare in the private section are only visible in the methods of the same class. The private components are not part of the external interface of the class.

go through this links:

http://www.sapgenie.com/abap/OO/index.htm

http://www.geocities.com/victorav15/sapr3/abap_ood.html

http://www.brabandt.de/html/abap_oo.html

Check this cool weblog:

/people/thomas.jung3/blog/2004/12/08/abap-persistent-classes-coding-without-sql

/people/thomas.jung3/blog/2004/12/08/abap-persistent-classes-coding-without-sql

/people/sap.user72/blog/2005/05/10/a-small-tip-for-the-beginners-in-oo-abap

/people/ravikumar.allampallam/blog/2005/02/11/abap-oo-in-action

/people/thomas.jung3/blog/2005/09/08/oo-abap-dynpro-programming

http://help.sap.com/saphelp_nw04/helpdata/en/c3/225b6254f411d194a60000e8353423/frameset.htm

For funtion module to class

http://help.sap.com/saphelp_47x200/helpdata/en/c3/225b5954f411d194a60000e8353423/content.htm

for classes

http://help.sap.com/saphelp_47x200/helpdata/en/c3/225b5c54f411d194a60000e8353423/content.htm

for methods

http://help.sap.com/saphelp_47x200/helpdata/en/08/d27c03b81011d194f60000e8353423/content.htm

for inheritance

http://help.sap.com/saphelp_47x200/helpdata/en/dd/4049c40f4611d3b9380000e8353423/content.htm

for interfaces

http://help.sap.com/saphelp_47x200/helpdata/en/c3/225b6254f411d194a60000e8353423/content.htm

For Materials:

1) http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCABA/BCABA.pdf -- Page no: 1291

2) http://esnips.com/doc/5c65b0dd-eddf-4512-8e32-ecd26735f0f2/prefinalppt.ppt

3) http://esnips.com/doc/2c76dc57-e74a-4539-a20e-29383317e804/OO-abap.pdf

4) http://esnips.com/doc/0ef39d4b-586a-4637-abbb-e4f69d2d9307/SAP-CONTROLS-WORKSHOP.pdf

5) http://esnips.com/doc/92be4457-1b6e-4061-92e5-8e4b3a6e3239/Object-Oriented-ABAP.ppt

6) http://esnips.com/doc/448e8302-68b1-4046-9fef-8fa8808caee0/abap-objects-by-helen.pdf

7) http://esnips.com/doc/39fdc647-1aed-4b40-a476-4d3042b6ec28/class_builder.ppt

😎 http://www.amazon.com/gp/explorer/0201750805/2/ref=pd_lpo_ase/102-9378020-8749710?ie=UTF8

1) http://www.erpgenie.com/sap/abap/OO/index.htm

2) http://help.sap.com/saphelp_nw04/helpdata/en/ce/b518b6513611d194a50000e8353423/frameset.htm

Cheers,

vasavi.

Read only

Former Member
0 Likes
620

Hi,

We use these keywords to specify access levels for member variables, or for member functions (methods).

  • Public variables, are variables that are visible to all classes.

  • Private variables, are variables that are visible only to the class to which they belong.

  • Protected variables, are variables that are visible only to the class to which they belong, and any subclasses.

Deciding when to use private, protected, or public variables is sometimes tricky. You need to think whether or not an external object (or program), actually needs direct access to the information. If you do want other objects to access internal data, but wish to control it, you would make it either private or protected, but provide functions which can manipulate the data in a controlled way.

Take the following example :

public class bank_balance

{

public String owner;

public int balance;

public bank_balance( String name, int dollars )

{

owner = name;

if (dollars >= 0)

balance = dollars;

else

dollars =0;

}

}

We have declared our string and integer to be public. This means that any object in the system can change the balance (setting it to zero, or even giving us a negative balance). This could cause the program to fall over, even though we wrote code in our constructor to prevent negative balances.

Instead, we should have provided a getBalance/setBalance method, and made our balance private or proteced. Other objects can still access the data, but they can't put invalid data in.

public class bank_balance

{

public String owner;

private int balance;

public bank_balance( String name, int dollars )

{

owner = name;

if (dollars >= 0)

balance = dollars;

else

dollars =0;

}

public int getBalance()

{

return balance;

}

public void setBalance(int dollars)

{

if (dollars >= 0)

balance = dollars;

else

dollars = 0;

}

}

Thanks&Regards,

Phani.