Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Exploring Interfaces in Other Languages

00:00 Interfaces in Other Languages Interfaces appear in many programming languages and their implementation varies greatly from language to language. Here you’ll compare interfaces in Python to Java, C++, and Go.

00:17 Unlike Python, Java contains an interface keyword. Keeping with the file parser example, you declare an interface in Java as seen on screen. Next, you would create two concrete classes to implement the FileParserInterface.

00:33 To do so, you must use the implements keyword. In the class definition, you can see the implementation of a Java interface on screen.

01:39 As you can see, a Python interface gives you more flexibility during creation than Java does. Like Python, C++ uses abstract base classes to create interfaces.

01:51 When defining an interface in C++, you use the keyword virtual to describe a method that should be overwritten in the concrete class. When you want to implement the interface, you’ll give the concrete class name followed by a colon, and then the name of the interface. On screen, you can see an example demonstrating the implementation of this interface.

02:50 And as you can see, there are similarities between Python and C++. They both make use of abstract base classes to simulate interfaces.

03:01 Although Go syntax is reminiscent of Python, the Go programming language contains an interface keyword like Java. Here you can see how a fileParserInterface would be created in Go.

03:14 A big difference between Python and Go is that Go doesn’t have classes. Go is similar to C in that it uses the struct keyword to create structures.

03:24 A structure is similar to a class in that a structure contains data and methods, but unlike a class, all of the data and methods are publicly accessed. The concrete structs in Go will be used to implement the fileParserInterface.

04:13 Unlike a Python interface, a Go interface is created using struct and the explicit keyword interface.

04:22 In the next section of the course, you’ll take a look back at what you’ve learned.

Become a Member to join the conversation.