ole
(Ole Begemann)
June 7, 2021, 2:04pm
1
Does the Swift community have an accepted term for members defined in protocol extensions that are not default implementations?
That is, a protocol defines requirements:
protocol P {
// protocol requirement
func requirement()
}
And the protocol can provide default implementations in an extension:
extension P {
// default implementation
func requirement() { ⦠}
}
But there are also protocol extensions that don't implement requirements:
extension P {
// what do we call these?
func nonRequirementExtension() { ⦠}
}
Iām looking for a name to describe the latter. Do we have a good term for this?
Jumhyn
(Frederick Kellison-Linn)
June 7, 2021, 2:09pm
2
I usually call them "extension methods" (or "extension properties," etc.), but I'm not sure if that's generally accepted terminology.
5 Likes
millenomi
(Aura Lily Vulcano)
June 7, 2021, 2:59pm
3
I usually say 'we provide a method on an extension of $protocol_name_here called x()ā¦'.
4 Likes
I never use the terminology myself, but I think that they're traits. Either that, or if only the grouping that the protocol represents is a "trait", then they're "trait methods" and "trait properties".
protocol Trait { }
extension Trait {
var isThisATraitOrATraitProperty: Void { () }
func isThisATraitOrATraitMethod() { }
}
struct Type { }
extension Type: Trait { }
protocol Protocol { }
extension Protocol where Self: Trait { }
Someone who is not me has added Swift to the page. If it's incorrect, it should be edited.
In computer programming, a trait is a concept used in object-oriented programming which represents a set of methods that can be used to extend the functionality of a class.
Traits both provide a set of methods that implement behaviour to a class, and require that the class implement a set of methods that parameterize the provided behaviour.
For inter-object communication, traits are somewhere between an object-oriented protocol (interface) and a mixin. An interface may define one or more behavi...
1 Like
The protocols and their requirements would be traits. The extension methods are methods that work on any type that implements that trait.
2 Likes
ole
(Ole Begemann)
June 9, 2021, 12:53pm
6
Thanks everyone for your input so far.
Nevin
June 9, 2021, 1:02pm
7
I believe the terms commonly used in Swift are:
⢠protocol requirement : declared in the main body of the protocol
⢠customization point : declared in the main body of the protocol, and a default implementation is provided in an extension
⢠extension method : declared in an extension of the protocol
6 Likes