Skip to content

Suggestion: Implicit interfaces #4633

Closed

Description

Caveat: I have mainly written dart code during the last 12 months.

I think it would be great if a class would implicitly define an interface that you could implement (like in dart). The implicit interface would only contain the public instance members of the class and of any interfaces it implements.

This would help in cases where you don't have control over a class, it exists in some third party library, and they haven’t exposed an explicit interface.

Example:

class Person
{
    // Not in the interface, since this is private
    private name;

    // Not in the interface, since this is a constructor.
    constructor(name : string)
    {
        this.name = name;
    }

    // In the interface.
    greet(who : string) : string
    {
        return `Hello, ${who}. I am ${this.name}.`;
    }
}

// An implementation of the Person interface.
class Imposter implements Person
{
    greet(who : string) : string
    {
        return `Hello, ${who}. Do you know who I am?`;
    }
}

Activity

  1. mhegazy commented on Sep 3, 2015

    @mhegazy
    Contributor

    look like the same as #3854

  2. danquirk commented on Sep 4, 2015

    @danquirk
    Member

    Yep. To be clear, this is true today:

    if a class would implicitly define an interface that you could implement (like in dart). The implicit interface would only contain the public instance members of the class and of any interfaces it implements.

    The problem is just that if there are non-public members they are not dropped but are also considered part of the implicit interface of the class. The issue Mohamed mentions covers lifting this restriction somehow.

  3. locked and limited conversation to collaborators on Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions