A long time ago I asked a question here on client modeling using object orientation. What I took from the answers is that clients, suppliers, and etc., rather than being characterized as entities themselves, can best be understood as relationships between entities.
At the time I thought about it for a while and it really makes more sense to consider one company being a customer of another is actually a status of that company. This approach has some advantages, among them allowing greater extensibility.
Recently I picked up an old system that I developed and felt the need to rethink it whole. In this I saw an opportunity to apply this type of modeling, but I encountered a problem.
In this case, the system is used by a single company that maintains records of Customers, Suppliers and Carriers.
In the current version I applied the traditional approach. I have classes Cliente
, Fornecedor
and Transportadora
. It turns out that there is a huge amount of duplicate code, since most properties are common to legal entities in general.
I could use inheritance, but I decided to try to use the approach that was suggested in the question I asked. I created a single Empresa
class that has all the characteristics of a legal entity.
So I created a RelacaoComercial
class that models the relationship between a company and the company that uses the system. From there I created two RelacaoClientela
and RelacaoFornecimento
classes that inherit from RelacaoComercial
.
The class Empresa
then has a List<RelacaoComercial> RelacoesComerciais
property containing your business relationships with the company that uses the system.
The difference between the traditional model and this is then: in the traditional model a client is an instance of Cliente
, whereas in this model a client is an instance of Empresa
that has in the RelacoesComerciais
property an instance of RelacaoClientela
.
There is a requirement, however, to mark for each customer the vendors that he uses. In the current model I simply established a NxN relationship between Cliente
and Fornecedor
.
But in this new model? There is no class Cliente
and no class Fornecedor
to establish the relation. My idea was: in the RelacaoClientela
class referencing a list of companies and enforcing the business rule that only a company that is a supplier can be added to that list, but I do not know if that is the way.
Using this type of template how can I make this kind of relationship?