private vs protected in Interfaces

Andrej Mitrovic andrej.mitrovich at gmail.com
Sat Aug 14 10:45:08 PDT 2010


On page 217+218 there are two interfaces that define some final methods with
the same name, and a class that inherits from both:

interface Timer
{
    final void run() {}
}

interface Application
{
    final void run() {}
}

class TimedApp : Timer, Application
{
    void run() {}    // cannot define run()
}

Okay, it hijacks both methods which are final, it won't compile which is
what we want.
TDPL states: "To access those methods for app of type TimedApp, you'd have
to write app.Timer.run() and app.Application.run() for Timer's and
Application's version", where the inheriting class does not hijack the
methods.

So that would look like this:

interface Timer
{
    final void run() {};
}

interface Application
{
    final void run() {};
}

class TimedApp : Timer, Application
{
}

import std.stdio;

void main()
{
    auto app = new TimedApp;
    app.Timer.run();  // error, no Timer property
    app.Application.run(); // error, no Application property
}

This looks to me like a DMD bug? I know I can do calls like these if a class
inherits from another class:

class Timer
{
    final void run() {};
}

class Application
{
    final void run() {};
}

class TimedApp : Timer//, Application
{
}

import std.stdio;

void main()
{
    auto app = new TimedApp;
    app.Timer.run();  // works fine
    //~ app.Application.run();
}

(Note I've had to comment out inheriting Application since MI is disallowed
in D). This will now run. Is this a DMD bug?


On Sat, Aug 14, 2010 at 4:56 PM, Andrej Mitrovic <andrej.mitrovich at gmail.com
> wrote:

> I agree, NVI really looks like a nice idiom/pattern to me, I'd hate to
> loose it.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20100814/d8437b6c/attachment.html>


More information about the Digitalmars-d mailing list