如何通过SubClass中的对象编辑Super Class的对象

时间:2016-10-02 06:48:21

标签: django

基本上我有两个类(Customer,EmpClass),我多次尝试找到一种方法,一个员工(EmpClass的对象)可以执行客户类对象可用的功能,退款,退出和所以代表一个客户上下班,以后在查询时我可以告诉哪个员工已经为特定客户执行了哪些操作。 并提前感谢:)

我的模特:

class Customer(object):
''' this class contains all Customer related Information and Functions'''

    BankName = "SBH"

    def __init__(self, Cname,CacountNumber, Cbalance):

        self.Cname = Cname
        self.CacountNumber = CacountNumber
        self.Cbalance = Cbalance

    def Deposit(self, DepositAmount):
        self.Cbalance = self.Cbalance + DeposetAmount


    def WithDraw(self, WithDrawAmount):
        if WithDrawAmount > self.Cbalance:
            raise InSuffetiantFunds
        self.Cbalance = self.Cbalance - WithDrawAmount


    def C_Info(self):

        print "Bank Name :", Customer.BankName
        print "Customer Name :", self.Cname
        print "Customer Acount Number : ", self.CacountNumber
        print "Customer Balance :", self.Cbalance 

class EmpClass(Customer):
        ''' this class contains all Employee related Information and Functions'''

    BankName = "SBH"

    def __init__(self, EmpName,EmpId,):
        self.EmpName = EmpName
        self.EmpId = EmpId 
        Customer.__init__(self, Cname,CacountNumber, Cbalance)

    def E_Info(self):
        print "Bank Name :", EmpClass.BankName
        print "Employee Name:", self.EmpName
        print "Employee Id : ", self.EmpId

1 个答案:

答案 0 :(得分:0)

在python中有super,它使您可以调用继承的类功能。

var marker = L.marker(latlng)
    .bindTooltip("Test Label", 
    {
        permanent: true, 
        direction: 'right'
    }
);

如果您在python3,则不再需要将参数传递给class EmpClass(Customer): def __init__(self, EmpName, EmpId, *args, **kwargs): self.EmpName = EmpName self.EmpId = EmpId super(EmpClass, self).__init__(*args, **kwargs)

使用*args and **kwargs将参数传递给父级,而不在子类中再次定义它们。