Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any implementation of class interfaces for Smalltalk?

Tags:

smalltalk

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

like image 935
Kevin Driedger Avatar asked Nov 28 '22 22:11

Kevin Driedger


2 Answers

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.
like image 78
Lukas Renggli Avatar answered Feb 24 '23 10:02

Lukas Renggli


After a discussion today with a coworker of mine it seems to me that the answer is any class could be considered an interface because any class can be passed in a message to any other class.

Any number of classes in smalltalk can respond to the same message, therefore you don't need interfaces as per C# and java.

like image 22
Kevin Driedger Avatar answered Feb 24 '23 09:02

Kevin Driedger