You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'd like to suggest a different approach for this proposal: instead of a class to implement protocols on declaration it will implement different protocols in a different statement for each protocol. This approach is known as Traits and can be seen in Scala, Rust, and other languages.
Traits enable better separation of concerns, composability, and are a static single solution for associating a protocol to a class, already declared (like Object) or not.
protocolProtocolName{// declare a symbol which must be implementedrequiredMethodName;// and some methods that are provided by implementing this protocolprovidedMethodName(...parameters){methodBody;}}classClassName{}implementProtocolNameforClassName{[ProtocolName.requiredMethodName](){// this is the implementation for this class}}
I'd like to suggest a different approach for this proposal: instead of a class to implement protocols on declaration it will implement different protocols in a different statement for each protocol. This approach is known as Traits and can be seen in Scala, Rust, and other languages.
Traits enable better separation of concerns, composability, and are a static single solution for associating a protocol to a class, already declared (like
Object
) or not.References:
Traits: Composable Units of Behavior | Nathanael Schärli, Stéphane Ducasse, Oscar Nierstrasz
and Andrew Black
Syntax
Example
The text was updated successfully, but these errors were encountered: