How to reuse class values?

0

I have three classes, the third one depends on the values of the other two (depends on E of class Material and A , Ix , Iu and Iz of class Geometria . I know I need to fix the 3rd class, but I do not know how (or even if what's 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
    
asked by anonymous 10.05.2018 / 03:01

1 answer

0

As commented by Anderson Carlos Woss, you have to be careful about multiple inheritance, in your case, I see this way: A cross-section has a Material and a Geometria , but is not in itself neither a material nor a shape / geometric figure.

Can you understand the difference? It has both features but is not a "descendant" of them.

An example class that would inherit Material could be Concreto for example, as Cubo could inherit from Geometria and so it goes .. (this of course implying that classes would be abstract) / p>

Regarding the code, something like this should serve:

# Remove a herança
class SecTrans(object):
  pass  # Colocar o resto aqui

material = Material('Queijo', 3, 5)
geometria = Geometria('Circulo')
transversal = SecTrans(material.E, geometria.A, 6, 7, 8)
    
10.05.2018 / 05:57