Doubts about class composition or inheritance

1

I have some doubts in this composition between ClienteJuridico and PhysicalClient with NotaFiscal . I did a search and I saw that I could instantiate the objetos of these classes inside another, in this case it would be the composition, but how could I inherit the attributes of these classes in the NotaFiscal class?

    
asked by anonymous 25.11.2018 / 20:18

1 answer

3

I find it a little strange ClienteJuridico , and ClienteFisico , inherit from Pessoa . Not totally absurd, but it seems conceptually wrong, maybe it's just a matter of name. Will one day these people can not be suppliers or have other roles? It will be weird. But that's not the problem.

Do you have to decide, either to inherit or to compose? They are essentially antagonistic. A% of% is a NotaFiscal ? As? I can not imagine how this is possible, so inheritance seems discarded. The composition seems appropriate. But it has problems. I can not imagine why a customer should refer to an invoice object. I also find it strange that NF allows both CPF and CNPJ.

The inheritance of ClienteJuridico in NotaFiscal seems even more absurd (I'm not sure what this class does). My suggestion is to revise your concept of what an inheritance is. There is material on the subject here on the site.

And I notice other problems in the model, but they are details that are not the focus of the question.

Note that the use of the term attribute is correct because this is UML, but when referencing the language this is called field .

    
25.11.2018 / 20:30