Lesson 36 of 55
15 mins readPython Implementing Interfaces with Classes
In Plain English
Classes can implement one or more interfaces, guaranteeing at compile time that all specified properties and methods exist with matching signatures.
Core Rules to Remember

implements: Binds a class to an interface contract at compile time.

Multiple Contracts: A single class can implement multiple independent interfaces.
Live Interactive Example
Hit Run Code to see it liveEnforcing Contracts on Classes
Python 3.12
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
Output Console
Click "Run Code" to view the rendered output.
How it works: UserProfile implements both Serializable and Loggable, fulfilling both contracts completely.
Your Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Micro Exercise
Implement HealthCheck Interface
Declare interface HealthCheck with ping(): boolean and serviceName: string.
Create class RedisHealth implementing HealthCheck with serviceName "Redis" and ping() returning true.
Instantiate and print `${serviceName} status: ${ping()}`.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Sandbox Output
Click "Run & Check" to test your solution.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.