Search code examples
smalltalk

Is there any implementation of class interfaces for Smalltalk?


In C# classes can have interfaces that can have multiple implementations. How do you do that in smalltalk?


Solution

  • First of all you typically don't need interfaces, because if an object implements the same messages as another one it can replace it. In Java and C# you cannot do this unless they are in the same hierarchy, thus you need interfaces.

    • In (all) Smalltalk there are protocols (method categories) that serve the purpose of informally grouping methods together.
    • In Pharo Smalltalk there are Traits. At first they look like interfaces, but they are also able to provide an implementation.