Skip to content

Suggestion: Implicit interfaces #4633

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
b-strauss opened this issue Sep 3, 2015 · 2 comments
Closed

Suggestion: Implicit interfaces #4633

b-strauss opened this issue Sep 3, 2015 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@b-strauss
Copy link

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?`;
    }
}
@mhegazy
Copy link
Contributor

mhegazy commented Sep 3, 2015

look like the same as #3854

@danquirk
Copy link
Member

danquirk commented Sep 4, 2015

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.

@danquirk danquirk closed this as completed Sep 4, 2015
@danquirk danquirk added the Duplicate An existing issue was already created label Sep 4, 2015
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants