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

About ABAP Object

Former Member
0 Likes
699

Hello All,

i have some question about ABAP Object.

What is the meaning of friend class and singleton?

Regards,

Luke

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
658

hi,

Generally users of a class may only access the public components of that class. Sometimes, however, you might want to create a closer link between classes. The concept of friends could be of use here.

In this case a class can permit explicitly named users (friends) to access its protected and private components.

All the users specified as friends can also access PROTECTED a nd PRIVATE components of the class in question if the Modeled only flag was not set in step 4. The friends relationship is always one-sided and is not inherited. This means that friends of a superclass are not automatically friends of the subclasses.

Singelton property is used for instantiating an element only

once....

Cardinality : number of possible elements within the node.

Singleton property means whether or not all instances of this node get created at runtime or not.

Follow this lik .

http://help.sap.com/saphelp_erp2005/helpdata/en/7a/787e40417c6d1de10000000a1550b0/content.htm

Hope this helps, Do reward.

Edited by: Runal Singh on Mar 28, 2008 12:30 PM

5 REPLIES 5
Read only

Former Member
0 Likes
658

FRIEND CLASS is a concept useing which a child can access private components of the base class in it

FRIENDSHIP is extended by parent to the child

FRIENDSHIP is not transtive

VISIBILITY is allways 1st preference in the object oriented programing

the PRIVATE components are not inherited to the child class but thriugh that child class we can acess PRIVATE components of the BASE CLASS

*For this we need to create an object of the BASE CLASS with in the child class to access PRIVATE components *

FRIENDS key word along with the child class name is used in the parent clas definition section to consider a child as a friend

ABAP Objects - Defining a Local Class as FRIENDS

ABAP Objects - Defining a Local Interface as FRIENDS

Why should it not be possible to call methods of this class "simultaneously"?

For example, if you have a static method GET_INSTANCE and the singleton instance has not been created yet the first call will create the instance whereas the second call will simply retrieve the already created instance.

If the local table is an instance attribute it will vanish as soon as you do not have any reference to your singleton anymore.

Reward points..

Read only

Former Member
0 Likes
659

hi,

Generally users of a class may only access the public components of that class. Sometimes, however, you might want to create a closer link between classes. The concept of friends could be of use here.

In this case a class can permit explicitly named users (friends) to access its protected and private components.

All the users specified as friends can also access PROTECTED a nd PRIVATE components of the class in question if the Modeled only flag was not set in step 4. The friends relationship is always one-sided and is not inherited. This means that friends of a superclass are not automatically friends of the subclasses.

Singelton property is used for instantiating an element only

once....

Cardinality : number of possible elements within the node.

Singleton property means whether or not all instances of this node get created at runtime or not.

Follow this lik .

http://help.sap.com/saphelp_erp2005/helpdata/en/7a/787e40417c6d1de10000000a1550b0/content.htm

Hope this helps, Do reward.

Edited by: Runal Singh on Mar 28, 2008 12:30 PM

Read only

matt
Active Contributor
0 Likes
658

If class/interface A is defined in class B as a friend, then class/interface A can access all the private and protected (and of course public) attributes, methods, types of class B.

"The friends of a class have unlimited access to the protected and private components of the class and can create instances of the class without constraints. "

matt

Read only

Former Member
0 Likes
658

Hi,

The addition Friends makes class class a friend of classes classi and or interfaces ifaci.At the sam time, all subclasses of classes classi, all classes that implement one of the interfaces ifaci and all interfaces that have one of the interfaces ifaci as a component interface become friends of class. you have to specify at least one class or interface.

The friends of a class have unrestricted access to the protected and private components of that class, and can generate unrestricted instances of the class.

The friends of class are not automatically friends of subclasses of class. the addition Friends does not make class a friend of its friends.

Thea ddition global is allowed only when you use the addition public for the global class of a class pool at the same time.You can list other global classes and interfaces from the class library after global friends.This addition is generated when the Class Builder creates a global class and you specified friends at the corresponding tab page of the class Builder.

`

In the example , classs c2 is a friend of interface i1, and therefore also of the implementing class c1. It can instantiate these objects and access their private component a1.

interface i1.

...

endinterface.

class c1 definition create private friends i1.

private section.

data a1(10) type c value 'Class 1'.

endclass.

class c2 definition.

public section.

interfaces i1.

methods m2.

endclass.

class c2 implementation.

method m2.

data oref type ref to c1.

create object oref.

write oref->a1.

endmethod.

enclass.

Kindly Reward Points If You Found The Reply Helpful,

Cheers,

Chaitanya.

Read only

GrahamRobbo
SAP Mentor
SAP Mentor
0 Likes
658

Hi Luke,

A class grants friendship to other classes and interfaces. These friends can then access the protected and private components of the granting class and can always create instances of this class.

A class that grants friendship is not automatically a friend of it's friends - it is a one-sided relationship.

Subclasses of friends also become friends.

Subclasses of the grantor of friendship do not automatically grant friendship as well.

Cheers

Graham Robbo