ole
(Ole Begemann)
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)
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)
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.
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)
6
Thanks everyone for your input so far.
Nevin
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