热线电话:13121318867

登录
2019-03-20 阅读量: 486
什么情况使用Metaclasses

大多数时候我们不使用元类,它们就像黑魔法,通常用于复杂的东西,但很少有使用元类的情况 -

  • 正如我们在上面的例子中看到的,元类传播了继承层次结构。它也会影响所有子类。如果我们有这种情况,那么我们应该使用元类。
  • 如果我们想要在创建类时自动更改类
  • 如果您是API开发人员,则可以使用元类

正如蒂姆彼得斯所引用的那样

Metaclasses are deeper magic that 99% of users should never worry about. If you wonder whether you need them, you don’t (the people who actually need them know with certainty that they need them, and don’t need an explanation about why).
13.1369
5
关注作者
收藏
评论(0)

发表评论

暂无数据
推荐帖子