I'm developing an application which will be responsible for the communication between a client and a server program, responsible for fetching data from a database. For now, I think this is just a temporary approach that we are taking, since we are basically hard-coding all the request handlers, etc. We'll probably pick a serious web-framework in the future.
I'm using RMI (Remote Method Invocation) to create the communication. I decided to create 2 abstract classes, where one will be the at the top of all type of requests and the other similarly will be at the top of the hierarchy of all responses. For now I was just thinking that requests can contain anything of any type or object, whereas the base class of the responses will contain at least two fields, one for the status code (like HTTP's status codes) and one hash map that contains eventually data (similarly to JSON objects).
My problem is that there're may be multiple kinds of requests and responses. Maybe one request contains two hash maps, and another one array list and an integer, and so on and so forth. I'm not sure if this is the right approach, but it was the first one that intuitively came to my mind.
I was thinking that the decorator design pattern could help me, but then I thought twice, and actually the decorator is used mostly to add dynamically behaviour and not data, am I'm correct?
Which design pattern do you think is better for my situation? I think that pure inheritance is definitely not a good idea, because of the multiple and eventually complex combinations...
Aucun commentaire:
Enregistrer un commentaire