What are Interfaces and what are some usage cases?

About Monkey 2 Forums Monkey 2 Programming Help What are Interfaces and what are some usage cases?

This topic contains 1 reply, has 2 voices, and was last updated by  nobuyuki 2 years, 10 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #1610

    jondecker76
    Participant

    Trying to get familiar with Monkey2.  I’ve been looking around but have not been able to find a good clear explanation of what Interfaces are and what they could potentially be used for.  The documentation doesn’t really say much about them

     

     

    Thanks

    #1615

    nobuyuki
    Participant

    Interfaces are used in situations where you might want to simulate what multiple inheritance normally offers in a limited way.  By specifying that a class conforms to an interface (classes can conform to multiple interfaces), then you can specify elsewhere that something takes an interface type and normally unrelated classes can use it.

    This is useful when you want to create modular systems (like for example, a standard library) since interfaces decouple the definition from the implementation.  Without interfaces, a lot more care and foresight must be taken in the design of a set of classes because a change to the implementation sometimes ends up needing a change in the definitions to remain straightforward.

    A good example of the use of interfaces is when implementing containers.  Another is for the sorting of containers — mx2 uses function calls for this, but .NET languages use generic interfaces to assume a safe definition of what the potential sorting and collating operations are for any particular implementation.

    http://monkey2.monkey-x.com/mx2-docs/std-std-collections-icontainer/

    Hoping that generic interfaces are implemented eventually, since their initial absence in monkeyX affected the design of a few base libraries from some users…

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.