Problems with my privates ...

Posted by jmls on 13-Apr-2010 10:23

In interfaces, that is

I have an interface IFoo, with the following property

DEF PUBLIC PROPERTY Bucket AS CHAR NO-UNDO GET . SET.

I then create a class NewFoo, and define the following:

DEF PUBLIC PROPERTY Bucket AS CHAR NO-UNDO GET . PRIVATE SET.

Compiler complains "Access mode for SET of property 'Bucket' in class NewFoo is more restrictive than that of the matching property in abstract class or interface 'Component.Interface.IFoo'. (15146)"

So, I add PRIVATE to the Interface

DEF PUBLIC PROPERTY Bucket AS CHAR NO-UNDO GET . PRIVATE SET.

Compiler now complains "A property declaration in an interface cannot include a PROTECTED or PRIVATE access modifier on a GET or SET method. (14784)"

AAARRGGGHHHH.

So, I cannot use PRIVATE on a GET or SET if the class implements an interface ? Why ? I'm sure there's some proper reason in OO-World, but that just seems daft to me.

Help!!

Julian

All Replies

Posted by Peter Judge on 13-Apr-2010 10:31

Keep your privates to yourself: you need to leave off the 'SET' on the interface definition.

-- peter

Posted by whenshaw on 13-Apr-2010 10:32

Julian,

The short answer to your question is to NOT put the SET into the interface definition at all. You are then free to define it any way you like in the implementation -- an interface is only a guarantee of what's available from an implementor, it doesn't restrict you from adding things. (And the fact that it IS  a guarantee is why you can't define the SET as public (as you originally did, implicitly) and then make it private in the implementation).

--Wayne

Posted by jmls on 13-Apr-2010 10:35

great. Thanks.

I originally tried it without get or set, but that failed to compile. I didn't read the error message closely enough - it did say "needs one of either GET or SET"

Posted by jmls on 13-Apr-2010 10:35

yup, thanks!

Posted by Admin on 13-Apr-2010 10:56

Don't use the SET in the interface at all! It can still be PRIVATE or

PROTECTED in the class. But the SET is not part of the contract.

This thread is closed