by davedx · 2y ago · 0 comments
I raised my eyebrows at this part though where the type constraints part was being explained:
> Coming from an Object-Oriented background, you may be tempted to compare Contracts to "Interfaces", but you'll find that while they may be used to a similar effect, they are not the same thing. The intention of an "Interface" is to encode subtyping relationships between types, whereas Claro has absolutely no notion of subtyping. [1]
IME with e.g. C#, interfaces are exactly for this kind of thing? Abstract classes and classes are more used for polymorphism?
But I admit it's been a while since I worked with C# and I may be remembering this stuff wrong.
[1] https://docs.clarolang.com/generics/contracts/contracts.gene...
Arguably, today the line is somewhat blurred because interfaces can have default member implementations (which are used to extend interfaces without making it a breaking change) but generally you are correct. An abstract class and subclasses that inherit from it signifies what the type is while the interfaces a class or struct implements signify what the type does.
[1] https://docs.clarolang.com/generics/contracts/dynamic_dispat...