0
I have three classes, the third one depends on the values of the other two (it depends on the E
class Material
and of A
, Ix
, Iu
and Iz
class Geometria
. How can I do this? I know I need to correct the 3rd class, but I don’t know how (or even if what is there is right).
class Material(object):
def __init__(self, nome, E, ni):
self.nome = nome
self.E = E
self.ni = ni
class Geometria(object):
def __init__(self, nome):
self.nome = nome
self.A = 0.
self.Ix = 0.
self.Iy = 0.
self.Iz = 0.
self.chi = 0.
def retangular(self, b, h):
self.A = b * h
self.Iz = b * h ** 3 / 12.
self.Iy = h * b **3 / 12
self.Ix = ( 1 / 3 - 0.21 * b / h * ( 1 - b ** 4 / ( 12 * h ** 4 ) ) ) * h * b ** 3
self.chi = 1.2
class SecTrans(Material, Geometria):
def __init__(self, E, A, Iz, Iy, Ix):
self.EA = E*A
self.EIz = E*Iz
self.EIy = E*Iy
self.EIx = E*Ix
Can you describe what each class is? Because using multiple inheritance, you need to be very careful with the defined fields. For example, both
Material
how muchGeometria
own the fieldnome
, then what should be thenome
ofSecTrans
? Use multiple inheritance only when you are sure of what you are doing. IfSecTrans
only depends on the values of others, I don’t see why use inheritance in this case. Just passing them as a parameter would be enough.– Woss
The material class is in relation to the material used. For example, concrete, steel, wood, etc. Each has a different E and ni. The geometry class deals with the areas and moments of inertia of the cross section of the concrete bar, steel, wood studied and the Sectrans class calculates the stiffness of the bar in question, which depends on the material and geometry. I don’t know if I was too clear, I’m terrible at explaining
– Michele Fonsaca
Then read about class composition.
– Woss