[Issue 2051] New: interfaces should allow private methods

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Apr 28 00:08:43 PDT 2008


http://d.puremagic.com/issues/show_bug.cgi?id=2051

           Summary: interfaces should allow private methods
           Product: D
           Version: unspecified
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: andrei at metalanguage.com


Consider: 

interface Foo
{
    private void bar();
}

class Bar : Foo
{
}

void main()
{
    Foo bar = new Bar;
    bar.bar;
}

This code has a link-time error. Removing "private" yields (correctly) a
compile-time error. So we have a bug already :o).

Adding a function void bar() {} to Bar keeps the link-time error in vigor,
whether or not the function is private. 

Now, if we want D to allow Sutter's NVI idiom
(http://www.gotw.ca/publications/mill18.htm) easily, it would need to enact the
following rules:

* A private method in an interface is part of that interface's table of
signatures.

* A class implementing a private method in an interface cannot graduate its
visibility (e.g. protected or public).

With these rules in place, D would support NVI very naturally. I think that's a
powerful paradigm that would lead to very expressive and robust interfaces.


-- 



More information about the Digitalmars-d-bugs mailing list