My two cents

Walter Bright newshound2 at digitalmars.com
Tue Oct 24 20:36:47 UTC 2017


On 10/24/2017 3:36 AM, Satoshi wrote:
> Can you provide an example?

I'd start with https://dlang.org/spec/interface.html

You'll see the same thing with Windows COM programming, and using interfaces in 
Java.

---- view.di ----
interface View {
     void render();
}
View createView();

---- button.di ----
import view;
interface Button : View {
     void simulateClick();
}
Button createButton();

---- closed_src_library.d ----
import view, button;
private class LibraryView : View {
    int hidden_data;
    void render() { do something with hidden_data }
}

private class LibraryButton : Button {
     int hidden_data;
     void simulateClick() { .... }
}

View createView() {
     return new LibraryView();
}

View createButton() {
     return new LibraryButton();
}

--- my_extension.d ---
import view, button;
class ExtendView : View {
     View base;
     this() {
         base = createView();
     }
     void render() {
         base.render();
         ... do my rendering ...
     }
}


More information about the Digitalmars-d mailing list