What are some (concrete) use-cases for metaclasses?

前端 未结 19 942
悲&欢浪女
悲&欢浪女 2020-12-07 06:51

I have a friend who likes to use metaclasses, and regularly offers them as a solution.

I am of the mind that you almost never need to use metaclasses. Why? because I

相关标签:
19条回答
  • 2020-12-07 07:55

    The only legitimate use-case of a metaclass is to keep other nosy developers from touching your code. Once a nosy developer masters metaclasses and starts poking around with yours, throw in another level or two to keep them out. If that doesn't work, start using type.__new__ or perhaps some scheme using a recursive metaclass.

    (written tongue in cheek, but I've seen this kind of obfuscation done. Django is a perfect example)

    0 讨论(0)
提交回复
热议问题