Skip to main content
added 121 characters in body
Source Link
Glorfindel
  • 3.2k
  • 6
  • 28
  • 34

There areSince the question originally did not mention PHP (just a code block without language specification), I've tried to come up with a couple of solutions, depending on the language in a few languages I've used:

  • Objective-C's version of interfaces, called 'protocols', can have optional methods.

  • In Swift, you can define a protocol extension with empty functions as default implementations for optional methods. They can (but do not have to be) overridden by other developers using the protocol (see here).

  • Java, version 8 and above, allow interfaces to have default methods which, like the Swift case, you should leave empty but might be overridden by other developers.

There are a couple of solutions, depending on the language:

  • Objective-C's version of interfaces, called 'protocols', can have optional methods.

  • In Swift, you can define a protocol extension with empty functions as default implementations for optional methods. They can (but do not have to be) overridden by other developers using the protocol (see here).

  • Java, version 8 and above, allow interfaces to have default methods which, like the Swift case, you should leave empty but might be overridden by other developers.

Since the question originally did not mention PHP (just a code block without language specification), I've tried to come up with a couple of solutions in a few languages I've used:

  • Objective-C's version of interfaces, called 'protocols', can have optional methods.

  • In Swift, you can define a protocol extension with empty functions as default implementations for optional methods. They can (but do not have to be) overridden by other developers using the protocol (see here).

  • Java, version 8 and above, allow interfaces to have default methods which, like the Swift case, you should leave empty but might be overridden by other developers.

Source Link
Glorfindel
  • 3.2k
  • 6
  • 28
  • 34

There are a couple of solutions, depending on the language:

  • Objective-C's version of interfaces, called 'protocols', can have optional methods.

  • In Swift, you can define a protocol extension with empty functions as default implementations for optional methods. They can (but do not have to be) overridden by other developers using the protocol (see here).

  • Java, version 8 and above, allow interfaces to have default methods which, like the Swift case, you should leave empty but might be overridden by other developers.