Customer-supplier relationship model

Asked

Viewed 139 times

1

Long ago I asked a question here about modeling clients using object orientation. What I took from the answers is that customers, suppliers, and so on, rather than being characterized as entities themselves can be better understood as relationships between entities.

At the time I thought about it for a while and it actually makes more sense to consider that one company being another’s client is actually a status of that company. This approach has some advantages, among them allow a greater extensibility.

Recently I took an old system that I developed and felt the need to rethink it whole. In that I saw an opportunity to apply this type of modeling, but I found a problem.

In the specific case the system is used by a single company that keeps records of Customers, Suppliers and Carriers.

In the current version I applied the traditional approach. I have the classes Cliente, Fornecedor and Transportadora. It turns out that there is a huge amount of duplicate code, since most properties are common to legal persons in general.

I could use inheritance, but I decided to try using the approach suggested in the question I asked. I created a single class Empresa which has all the characteristics of a legal person.

So I created a class RelacaoComercial that shapes the relationship between a company and the company that uses the system. From there I created two classes RelacaoClientela and RelacaoFornecimento which they inherit from RelacaoComercial.

The class Empresa then has a property List<RelacaoComercial> RelacoesComerciais containing its business relations with the company using the system.

The difference between the traditional model and this is: in the traditional model a client is an instance of Cliente, whereas in this model a client is an instance of Empresa you own on the property RelacoesComerciais an instance of RelacaoClientela.

There is a requirement, however, to mark for each customer the suppliers it uses. In the current model I simply established an Nxn relationship between Cliente and Fornecedor.

But what about this new model? There is no class Cliente and not a class Fornecedor to establish the relationship. My idea was: in class RelacaoClientela reference a list of companies and enforce the business rule that only a company that is a supplier can be added to that list, but I don’t know if that’s the way.

Using this kind of model how can I make this kind of relationship?

  • I don’t know if you can understand the whole problem just with this information. Some things seem a little vague. Before trying to answer (if I understand the problem better), I will say that I do not understand this RelacaoComercial. Nor your relationship with Empresa. It gives the impression that it is not doing exactly what was said in the other question. I would imagine that the data from Cliente of Fornecedor , etc. relates directly to the company. Another point that has in the answer to that question is that it is possible to abstract the fact that the model does not differentiate customers, suppliers or keep as a single entity.

  • There I talked about screen, but I could do this in the system as a whole. I said could, not that it is a necessity. Regardless, I can’t imagine why it would be difficult to list the suppliers a customer has purchased. Unless the model is all wrong, but I don’t know how it’s modeled. I find this requirement strange, but if it exists the relationship is N:M even, it would be so no matter the modeling. Each Customer can have M suppliers. Each supplier can provide to N customers.

  • Nor should we call this "relationship", I think it should be "entity", maybe it’s because the model is wrong, but again, I don’t know this.

  • In fact what I had understood in that question is that we have a class representing legal persons in general. Here I called Empresa this class. From there, it would be necessary something to specify whether this company maintains customer relationship, supply, etc. In the suggestion you gave this would be done with properties: ÉCliente, ÉFornecedor, etc. But as you said yourself, you may need to specify attributes/methods that only exist for customers or suppliers. These attributes/methods cannot be in the class Empresa, since they do not exist for carriers.

  • That’s when I thought of this solution. I based myself a little on the Claims model used for authorization. A user has several Claims that define their identity. In this case I thought of doing something similar: a company has several established business relationships, customer relationship, supply and etc. From there on a company acts as Cliente simply add an instance of RelacaoClientela. That was the initial idea I had proposed. The class RelacaoComercial would be there for what Empresa had a "generic" list of business relations.

  • But as this was not working very well initially, I decided to follow another approach proposed in the other question. I created a class Empresa and created classes Cliente, Fornecedor and Transportadora with reference to Empresa. As in that specific area customers, suppliers and carriers at all times are legal persons, I’m just wondering if it’s not the case of using inheritance instead of composition.

  • I think I understand the class now. It might be interesting what you did, if I understand correctly. If you make inheritance, you’ll go back to the traditional model of separate roles. Again, without more details I can not answer this specific question, because it is no longer so conceptual, it is more concrete. Maybe your mistake is that you still think of the papers as a focal point and not the company as that point. Composition is to make the company have the roles (business relations), not to make the papers have an information of Empresa. This is equal to inheritance. See: http://answall.com/q/86715/101

  • I edited the question a little bit. Actually, I could try to make it more abstract. Notice that it all comes down to the following: if we model PessoaJuridica with a class and possible relationships (clientele, supply, etc.) in the way I suggested, when there is Nxn relationship between two legal entities that have different performances (one is client and the other supplier), how to model this relationship? I thought I’d put a list of Empresa in RelacaoClientela and impose a business rule of only being able to add, if the company is supplier, but I do not know if it is a good approach, it seems strange to me.

  • I don’t really understand what the problem is. Maybe the modeling is wrong, but I don’t know what it is. If you just think it’s weird, maybe it’s because the requirement is weird, that’s all. Maybe it’s not even weird.

  • If you create a diagram of entities and relationships can facilitate obtaining the answer.

Show 5 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.