How to achieve Protocol Oriented Programming in Py

2019-08-05 12:45发布

I'm new in Python programming with a strong background in Objective-C and Swift. One of the cool thing I love in Swift is the Protocol Oriented Programming with default implementation. I would like to know if it's possible to have the same behaviour in Python?

I'm not sure if it would be a good solution because POP solve problems of the single inheritance but in python we can use multiple inheritance. The thing is that I've heard since the beginning of my programming journey that the multiple inheritance is bad.

From what I think to do is to:

  • Use a abstract class
  • Implement some method of this abstract class
  • Make a class inherit from the abstract class

So I'm curious to know if people use POP in Python? And if yes how they do it?

0条回答
登录 后发表回答