UML classes associations

0

I'm from the time of structured programming and now I'm coming back and trying to fit in with OOP. I made a diagram below, could you analyze if I'm on the right track?

I created this class Empresa thinking not to be limited in the two classes PessoaJuridica and PessoaFfisica .

    
asked by anonymous 04.07.2018 / 20:30

3 answers

3

What about the time of structured programming? Has anything changed that I do not know? I still do structured programming. Maybe I'm a bit confused about paradigms. One thing does not eliminate the other. I would even avoid taking on new paradigms without understanding this foundation and understand why you are adopting a new paradigm in your project. Doing it because it's fashionable is not a good reason.

Did you have a problem and now doing OOP resolves it? If not, you do not have to change. Was it procedural wrong? Are you going to do OO right? It's harder to do object-oriented right.

I'm not one of the more fans of getters / setters . And it has language that makes little sense, one of the reasons I no longer like UML (and many people are seeing that it was not to like). And it has ideo methodology that preaches that it should not use. Even OOP says this in its purest form, although I always find it overkill.

The model seems to be above average. But that's what I always say, I do not know what the problem is, I can not tell if it's the right solution.

Pessoa is abstract? should. The diagram does not show this.

You are not yet using the constructor correctly, it seems to have not read the links I passed in previous question .

I do not know if Contato should be this way, but I'm speculating on a problem I do not know. It might be the exact solution. Should not address have an independence? How is the relationship between the two structures made? If it persists how the relationship is managed?

I do not know what this Empresa is. What is written in the question does not tell me anything. Or say, that does not make sense. Whoever creates must justify why he has created. Never create something that you can not justify very well. But after the comments I saw that it does not make sense at all, for two reasons: the physical person can not be a company and the model is crooked so maybe not even have a company, probably did not understand what is his heritage. This is what I said in the previous question: first learn how to use the tools before using it.

Failure to understand what you are doing will make you commit several errors in sequence, and you may commit your entire life if you do not create a basis. In this case you need to create an object that is a person, and already has a type that defines it, it is Pessoa , you do not have to invent anything else. Even though it is abstract, and I said it should be, you can create concrete objects, through their derivatives, but save in a Pessoa variable, so you already have what you need. The object will be unique to that entity and will obviously follow only one of the two existing models: PessoaJuridica or PessoaFisica .

I do not know if tipo should be string , but may be, would need a deeper.

Do not miss some setters ? Maybe not, but does not it lack one or more methods that allow you to change the data consistently?

See Type of the CPF or CNPJ field in the VARCHAR or INT database .

In the comments talks a lot in companies, company is only legal entity. It may just be the use of the wrong term, but as I say, if you do not know how to even use the right names of things, you will not know what that means, what role that is in the model, then the error is imminent, look for

04.07.2018 / 20:44
1

Gathering some of the feedback information, the modeling needs became a bit clearer.

I understand that it would be interesting to have these classes:

  • PersonPhysical
  • PersonJuridica
  • Address
  • Person
  • Company
  • Contact

With some observations that guided me in the correction of your modeling:

  • Every company, regularly incorporated, is a legal entity, but not every legal entity is a company.
  • Individuals may have a Company, but an Individual may not be a company.

So

  • Empresa inherits from PessoaJuridica .
  • Pessoa has a Empresa . Remove the inheritance between Company and Person.
  • PessoaFisica and PessoaJuridica inherit from Person.
  • It would move the address information from Pessoa to a Endereco class. Person has a list of Endereco .
  • Pessoa has a list of Contato , as it currently stands.
  • Otherwise, I would use the class constructor to get their information, not set . Evaluate if you need all%% of existing%. If so, you can keep them.

    On the get field and what you explained in the comments, it appears to belong to a tipo class that inherits from Profissional and, in the case of a company, I believe the information belongs to PessoaFisica (of activity) of Ramo , where Empresa has Empresa . You can use this Ramo to Ramo and give up PessoaFisica , but you would need to know the context better to choose. But I leave both options.

    Finally, as I said in the comments, I believe you can choose not to use any inheritance in this model and use composition only. But in my answer I preferred to follow the reasoning of inheritance so as not to escape much of what I already had. Remember that there is no definite and definitive answer to this problem, as the possible solutions are several.

      

    I'm from the time of structured programming and now I'm coming back and trying to fit in with OOP. I made a diagram below, could you analyze if I'm on the right track?

    Just one comment on this statement. Much is heard about OOP being the evolution of structured programming, but it all depends on the problem it will solve. It is true that old-fashioned codes were common and OOP was sold as salvation, but it is possible to keep a non-OOP code well organized. By the way, in my profession, that's what I've seen the most.

    In fact, applying OOP to an application is quite tricky and is usually recommended for cases where the business rule is quite complicated, in which the Domain Driven Design (DDD) usually appears to give a certain organization to these classes all that can be repeated in different domains of the same application.

        
    09.07.2018 / 20:56
    0

    One of the principles governing object orientation is that classes have characteristics and behaviors that are inherent in them and translate what they represent.

    In your Person class you have put attributes such as neighborhood, zip code, city and state that are not a person's characteristics but the address associated with it. Yet, from what I understood, what you used as an attribute named address, would be the street address + number. These, together with the other attributes mentioned above, are associated with the set that characterizes a person's address. It would be the same line of reasoning you used to create a Contact class with the attributes inherent to it.

    I would advise you to put address as a class and bring all address data to be attributes of this new Address class. Then make a relationship between Person and Address as you did with Contact.

    By making these changes I believe your model will translate into an extensible code more correctly and allow reuse more efficiently.

        
    29.08.2018 / 12:57