Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

How to define interfaces, exceptions, enums INSIDE an interface?

I have an interface:

public interface Map
{
}

Now, I wanted to define a private inteface or a sub-interface that is defined only inside the Map interface. I also wanted to define some exceptions and enums.

It is easy to do with classes:

public class Map
{
private class Entry
{
}
}

Unfortunately, you can't define types inside an interface. I had to define MapEntry as a separate public interface:

public interface MapEntry
{
}

What would be the best design solution for sub-interfaces? Just curious.


Comments

  • binar0binar0 Member Posts: 6
    : I have an interface:
    :
    : public interface Map
    : {
    : }
    :
    : Now, I wanted to define a private inteface or a sub-interface that is defined only inside the Map interface. I also wanted to define some exceptions and enums.
    :
    : It is easy to do with classes:
    :
    : public class Map
    : {
    : private class Entry
    : {
    : }
    : }
    :
    : Unfortunately, you can't define types inside an interface. I had to define MapEntry as a separate public interface:
    :
    : public interface MapEntry
    : {
    : }
    :
    : What would be the best design solution for sub-interfaces? Just curious.
    :
    :
    :

    I think what you are looking for is to define these things within a namespace. In this way you can refer to all within the namespace thusly:

    namespace.interface.
    namespace.enum.

    etc...

Sign In or Register to comment.