I'm trying to understand some workings of Abap-OO.
In C# it is possible to restrict a type to be any type but conform at least to certain (multiple) interfaces through constraints in generics by doing:
where T : IAmInterfaceA, IAmInterfaceB
Is it possible to archive the same in abap-oo? I want to pass in any object as a parameter to a method that conforms to two interfaces.
For example I want to have those two interfaces:
I do not want to have an extra interface combining the methods those two provide separately.
For example there could be a manager class that wants to save objects but only if they're valid:
Manager.Save(/* <object that conforms to both interfaces IValidate and ISaveable> */ );
So if I got a simple class like SimpleData : IValidate, ISaveable
objects of this class could be passed into the method but another object whose class only implements ISaveable
cannot be passed in.
In C# I would simply define the save method as a generic method:
static bool Save<T>(T dataObject) where T : IValidate, ISaveable { /* ... */ }
How to do this in abap-oo, if possible?
In ABAP, you have to either create a combining interface or check the condition at run-time (which I would NOT advise). You can only use a single type for a parameter. More complex constraints like the ones you quoted are not possible as far as I know.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With