Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using a local clone.

Interface specifications for aggregate types

Version 1
Created 2013-09-08
StatusDraft
Last modified 2013-09-08
Author Simen Kjærås

Abstract

An interface specification is a complete list of implemented functions of an aggregate type.

Rationale

It may at times be hard to get a full overview of the implemented interface of a class, to find which member functions are there and what their exact signatures are. While an interface may put a lower limit on the implemented member functions, additional functions may be implemented willy-nilly.

This DIP seeks to solve one of the main problems addressed by DIP47, albeit by a different route.

Syntax

Interface specifications add an optional section to aggregate types:

class C {
    // Declaration
    interface {
        this(float)
        int foo();
        void bar(ref int n);
    }
    // Definition
    this(float f) {
    }
    int foo() {
        return 3;
    }
    void baz(ref int n) {
    }
}

Semantics

  1. Parameter names may be omitted in the declaration, but must otherwise match those in the definition.
  2. Types, parameter types, attributes, and UDAs in declaration must be present in both locations.
  3. Default parameter values must be repeated in both locations or not at all.
  4. It is an error for @safe/@trusted/@system, private/package/public/export access, linkage and storage classes to differ between declaration and definition.

Existing Code

Interface specifications will not break any existing code.

This document has been placed in the Public Domain.