cancel
Showing results for 
Search instead for 
Did you mean: 

Calling privated methods of a standar class from other zclass

Former Member
0 Kudos

Hi all.

I trying to call a privated method of a STANDAR_YYYY standar class(this class have all its methods privated). I see that this Class have a interface IF_STANDARD_YYY.

I have other ZXXXX class and it have one attribute YYYY_ATTR TYPE REF TO STANDAR_YYYY. In a method i instance the standar class (create object YYYY_ATTR...) but when i try to call a method <b>YYYY_ATTR->method1</b> i have a error activing the object ("you cannot access privated method YYYY_ATTR->method1). I was thinking that maybe using the interface IF_STANDAR_YYY in my ZXXXX class i will to call the private methods of the standar class STANDAR_YYY but when i did it obtanin this error "Before the IF_STANDARD_YYY statment, the interface in question must be fully defined". <b>What is wrong ?????</b>. If anybody can help me please!!!

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Usually, in Object Oriented Programming, you can't access private methods out side the class that defines them.

If you want to access these methods, you MUST use the class that defines them, using interfaces don't makes an private method to be accessed from another class and you can't access a private method from a class that inherites from the private class.

There is no other way that use the class that defines them, or to make a manual copy of them :).

Maybe it will be helpfull for you to read Design Patterns in Object Oriented, I think Composition Pattern (I think this is the name of the pattern) is the one you must refer to.

Former Member
0 Kudos

"Usually, in Object Oriented Programming, you can't access private methods out side the class that defines them."

?????????????

uhmmmmm.....

Thanks Jorge but i don't think so. I'm working with the web module IcWebClient at CRM 4.0 and i have a sample. If i wasn't sure, i never had post my question in this forum. Maybe i should post it at Web Applications Forum

Former Member
0 Kudos

I think that we are talking about the same.

I have read again your first post and I see that you talk about a class that has an attribute that refers to the class with the private access you want to use, sorry, I haven't seen before :P. (I think this is the pattern composition , if this is it's name).

Former Member
0 Kudos

I agree with Jorge. If the method is defined private then you are not going to be able to call it outside of the class.

The class that defines the private method is the only class that can call the method at any time. It is not the same to have an object that has an instance of the class invoke the method.

It makes no difference whether the caller has this reference by way of an attribute of any scope. Nor is the fact that the method implements an interface relevant.

Sounds like you need to ask SAP to consider changing the interface of the class.

Scott

Former Member
0 Kudos

Specials thanks to Sancho and Scott.

I was testing and the only way to do that is modifying the SAP interface with the methods that i will use or maybe inserting my ZCLASS like a friend in the SAP standard class. I will to ask SAP to consider changing the interface of the class.

Thanks a lot friends.