Python abstract classes - how to discourage instantiation?

后端 未结 5 1454
面向向阳花
面向向阳花 2021-02-07 04:58

I come from a C# background where the language has some built in \"protect the developer\" features. I understand that Python takes the \"we\'re all adults here\" approach and

5条回答
  •  伪装坚强ぢ
    2021-02-07 05:23

    Based on your last sentence, I would answer answer "just document it". Anyone who uses a class in a way that the documentation says not to must accept responsibility for any strange behavior.

    There is an abstract base class mechanism in Python, but I don't see any reason to use it if your only goal is to discourage instantiation.

提交回复
热议问题