Interfaces is an actively used design pattern.

?Years Old
  • Interfaces ranks in the top 50% of entities I track
  • the Interfaces wikipedia page
  • I have 13 facts about Interfaces. what would you like to know? email me and let me know how I can help.

Languages with Interfaces include java, kotlin, objective-c, swift, typescript

Example from java:

interface MyInterface{  
   /* This is a default method so we need not
    * to implement this method in the implementation 
    * classes  
   default void newMethod(){  
       System.out.println("Newly added default method");  
   /* Already existing public and abstract method
    * We must need to implement this method in 
    * implementation classes.
   void existingMethod(String str);  
public class Example implements MyInterface{ 
  // implementing abstract method
    public void existingMethod(String str){           
        System.out.println("String is: "+str);  
    public static void main(String[] args) {  
      Example obj = new Example();
      //calling the default method of interface
        //calling the abstract method of interface
        obj.existingMethod("Java 8 is easy to learn"); 

Example from kotlin:

interface Named {
   val name: String
interface Person : Named {
    val firstName: String
    val lastName: String
    override val name: String get() = "$firstName $lastName"

Example from objective-c:

@protocol Printing
   -(void) print;

Example from swift:

protocol MyProtocol {
init(parameter: Int)
var myVariable: Int { get set }
var myReadOnlyProperty: Int { get }
func myMethod()
func myMethodWithBody()
extension MyProtocol {
func myMethodWithBody() {
  // implementation goes here

Example from typescript:

interface SquareConfig {
   color?: string;
   width?: number;

Last updated November 21st, 2019