‎2009 Aug 04 11:18 AM
Hi there OO-style ABAPers,
I've just begun an ABAP OO adventure and have such a small problem ...
... I created a class, let's say MyClass which has some private attributes (Let's say MyAttr1, MyAttr2). Now I'm Implementing an interface let's say MyIface which has an attribute MyIfaceAttribute.
But after implementing interface - MyIfaceAttribute is automatically set to public in MyClass and there is no possibility to edit it.
And now I've got a small mess:
private MyAttr1
private MyAttr2
public MyIfaceAttribute
... whilst I'd like to have them all private
How can I change MyIfaceAttribute accessibility implemented in MyClass into private ?
‎2009 Aug 04 11:25 AM
Hello Pjotr
Private attributes do not make sense in interfaces. In order to "protect" you public interface attribute from being modified externally just define the attribute as READ-ONLY.
If you want to provide MODIFY access to the attribute you need to add a SET_MYATTRIBUTE method to your interface.
Regards
Uwe
‎2009 Aug 04 11:25 AM
Hello Pjotr
Private attributes do not make sense in interfaces. In order to "protect" you public interface attribute from being modified externally just define the attribute as READ-ONLY.
If you want to provide MODIFY access to the attribute you need to add a SET_MYATTRIBUTE method to your interface.
Regards
Uwe
‎2009 Aug 06 9:50 AM
Uwe Schieferstein
Private attributes do not make sense in interfaces.
Could You please tell me why? I'm a real newbie in object oriented way of thinking, what is the argument not to make private attribute in interface? I would be really thankful for explaining.
Greetings. P.
‎2009 Aug 06 10:08 AM
Hi Piotr,
Interfaces from definition are public and they do not distinguish any other visibility. One of the reason would be that when you implement this interface in your class, it must be visible in all its subsequent classes (inherintng from this class). For private attributes/methods it wouldn't be feasible, though for protected it would.
Therefore entire definition of interfaces is just inlcuded in public section of class implementing it.
Moreover the interfaces are mainly designed to behave polimorphically so using one reference variable you can call different methods implementation (interface methods). This must be available from outside of interface/class implementing it. That's why its definition must only be public.
Regards
Marcin
‎2009 Aug 06 8:54 PM
Hello Piotr,
in ABAP OO an interface is intended as well known API to deal with. Therefore it would contradictionary to hide elements of an interface. Or in other words if it should´t be public / used by others why should an element part of the interface. Just remove it from the interface and move it to the implementing class.
Best Regards
Klaus
‎2009 Aug 06 3:03 PM
Once you implement the interface in your class, you can set the Aliases and the visibility of the component.
In SE24 (Global class builder) you would find the Aliases tab.
Here you can specify the "simple" name of the attribute and methods as well as you can specify the visibility.
Regards,
Naimesh Patel