What is a partial class?

2019-03-27 12:08发布

What is and how can it be used in C#.
Can you use the same concept in Python/Perl?

8条回答
成全新的幸福
2楼-- · 2019-03-27 12:58

Because python is a dynamic language you don't need a concept like partial class. In python is possible to extend object with functionality in runtime so it possible to break class declaration into different files

查看更多
我命由我不由天
3楼-- · 2019-03-27 13:03

The c# partial class has been already explained here so I'll just cover the python part. You can use multiple inheritance to elegantly distribute the definition of a class.

class A_part1:
    def m1(self):
        print "m1"

class A_part2:
    def m2(self):
        print "m2"

class A(A_part1, A_part2):
    pass

a = A()
a.m1()
a.m2()
查看更多
登录 后发表回答