How do you call "non-requirement" protocol extensions?

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?

I usually call them "extension methods" (or "extension properties," etc.), but I'm not sure if that's generally accepted terminology.


I usually say 'we provide a method on an extension of $protocol_name_here called x()ā€¦'.


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.


Thanks everyone for your input so far.

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

Terms of Service

Privacy Policy

Cookie Policy