www.digitalmars.com         C & C++   DMDScript  

D - Properties in Interfaces?

reply Russ Lewis <spamhole-2001-07-16 deming-os.org> writes:
How about allowing people to define properties as members of
interfaces?  This would allow people to use member-data style syntax for
properties of interfaces, while still allowing it all to come through a
vtable:

    interface MyIntf
    {
        void myProp(int val);
        int myProp();
    }

    class MyClass : MyIntf
    {
    public:
        void myProp(int val);
        int myProp();
    }
    class MyClass2 : MyIntf
    {
    public:
        int myProp;
    }

    MyIntf obj = new MyClass;
    MyIntf obj2 = new MyClass2;
    obj.myProp = 1;
    obj2.myProp = 2;
    printf("%d %d\n", obj.myProp, obj2.myProp);

In order for MyClass2 to work, the compiler would have to generate
wrapper accessor functions for the myProp property of that class, of
course.  However, MyClass could work without any compiler-generated
code.

--
The Villagers are Online! http://villagersonline.com

.[ (the fox.(quick,brown)) jumped.over(the dog.lazy) ]
.[ (a version.of(English).(precise.more)) is(possible) ]
?[ you want.to(help(develop(it))) ]
May 28 2002
parent "OddesE" <OddesE_XYZ hotmail.com> writes:
"Russ Lewis" <spamhole-2001-07-16 deming-os.org> wrote in message
news:3CF456D0.B775BF8E deming-os.org...
 How about allowing people to define properties as members of
 interfaces?  This would allow people to use member-data style syntax for
 properties of interfaces, while still allowing it all to come through a
 vtable:

     interface MyIntf
     {
         void myProp(int val);
         int myProp();
     }

     class MyClass : MyIntf
     {
     public:
         void myProp(int val);
         int myProp();
     }
     class MyClass2 : MyIntf
     {
     public:
         int myProp;
     }

     MyIntf obj = new MyClass;
     MyIntf obj2 = new MyClass2;
     obj.myProp = 1;
     obj2.myProp = 2;
     printf("%d %d\n", obj.myProp, obj2.myProp);

 In order for MyClass2 to work, the compiler would have to generate
 wrapper accessor functions for the myProp property of that class, of
 course.  However, MyClass could work without any compiler-generated
 code.

 --
 The Villagers are Online! http://villagersonline.com

 .[ (the fox.(quick,brown)) jumped.over(the dog.lazy) ]
 .[ (a version.of(English).(precise.more)) is(possible) ]
 ?[ you want.to(help(develop(it))) ]
I know Delphi supports this kind of construction and I think it is also in the IDL spec. Seems good enough of an idea to me! -- Stijn OddesE_XYZ hotmail.com http://OddesE.cjb.net _________________________________________________ Remove _XYZ from my address when replying by mail
May 29 2002