2
I have a problem that seems fairly common to me. The problem, in the specific case, is the following: the user wants to register in the system the services available for sale along with the values. When selling a service, the user wants the service to be active for the customer.
Finally, for some services there are specific rules and properties that the system needs to consult. An example would be support service, which has the hours the customer pays per month. This service has a specific rule: it can only be performed if the hours have not yet been spent in the month, and has a specific property: the number of hours.
Now let’s see the problem: if the user registers the services manually, there is no way at first the system know for example which service is the support. Actually, they’re all gonna be the same to the system. This is because in theory there will be a single class with general properties, whose instances are the services registered for sale.
This clearly conflicts with needing to specify rules and details for specific types of service.
As I said, I think this may be more common than it seems at first. I mentioned a concrete case, but we could abstract it as follows: the user wants to register some objects in a personalized way, but these objects need to have specific behaviors, with specific properties and specific rules, which conflicts with the user wanting to register them at will.
In this sense the solution I identified was the following: identify the types of service, create a class for each type, and in the registration ask the user to choose the type, opening the possibility of customization. Here it seems that it would fit the use of inheritance, but I know that this is subtle.
Otherwise I thought in bounded contexts of the DDD. I even wondered if the problem would not be the term "Service" being used in two different contexts, representing different things. The problem is that despite identifying the problem, I did not identify how to deal with the issue of "service type".
As this seems to me even common, I thought if there would be a design Pattern that deals with it. Is this type of situation the subject of some design Pattern? There is a known and tested solution that addresses this type of problem?
Or the solution I proposed to create a class for each type of service, abstracting its main characteristics, allowing the user to choose the type in the register would be the best solution?
Without knowing details of the implementation, I believe your last paragraph is the best way.
– Oralista de Sistemas
@Renan, I did not give details of implementation, because I thought the question would be better received in a more general way. Do you think she could be better off giving details? Also, regarding the implementation, I only found a problem: how would I let the user choose the type that will be used to create the service at the end? An Enum with possible types and then a mapping of Enum values to classes?
– SomeDeveloper