我是python的新手,我一直在尝试使用组合而不是继承来代替下面的代码无效我在常规类中尝试过Job_cls = Job但这只能让我访问Job类中的方法。我似乎无法通过使用composition的Permanent类访问Job类的属性和方法。我在线查看了无数的视频和博客,但大多数都引用了self.L1 = Job(Location)这样的属性。你的帮助将不胜感激。
class Job:
def __init__(self, location, salary, description, fee):
self.location = location
self.salary = salary
self.description = description
self.fee = fee
def Charge(self):
if self. fee > 1000 :
print("sell")
else:
print("Reject")
def Charge2(self):
self.salary = int(self.salary * self.rate)
class permanent(Job):
rate =1.05
permanent1 = permanent("london", 23000, "Accounts Assistant", 1200)
permanent1.rate=1.06
permanent1.Charge2()
print(permanent1.salary)