开发者

a couple of questions regarding design

I would like to hear what do you think about the design of this issue. I have to write webservice to allow user to modify dictionaries in database.

I got xml schema which looks like this (it's simplified):

AdminService which is a root and has a choice with:

  • AddCode[@DictionaryName, @Code, @Description]
  • RemoveCode[@DictionaryName, @Code, @Description]
  • DeleteCode(@dictionaryName, @Code, @Description]

The problem is that for some dictionaries there is more than these 2 attributes to be inserted - sometime they contain an additional code which will be hardcoded (it's more complicated but I've simplified it for the sake of this question, generally speaking the code will be different for each dictionary). Here is what I have:

At the beginning the incoming XML is converted into Java object using Jaxb, they pass me this Java object <- it has been implemented in this way and I cannot change it.

Here is my part:

I have a kind of router, which contains a list of registered services (I use Java, Spring, Hibernate). Inside this router there is a method which verifies if an objected created from xml contains AddCode Obj, or RemoveCode Obj. Based on and the name of dictionary it uses one of registered services to process the request, so for example there is a service like:

class Add[DictionaryName]CodeService implements Service {
  execute(ObjectfromXML);
}

which is used to create a code, when request came with CreateCode element. What is returned by this service (java obj or xml response) is out of scope for now.

The problem is that using approach I will need to create 3 classes like:

Add[DictionaryName]CodeService, Remove[DictionaryName]CodeService, Delete[DictionaryName]CodeService.

when a new dictionary is added.

It also means, that I would need to add these 3 services to Router each time and the size of Router will increase. I'm wondering if I should add a set of classes and do it in this way as below or use a different approach.

Router would contain only 3 services AddCodeService, RemoveCodeService, DeleteCodeService and AddService would contain all services which are used to add specific codes, i.e. Add[DictionaryName1]Service, Add[DictionaryName2]Service, etc.

Any Ideas? I also had problems with naming classes... I've trie开发者_运维技巧d to have a DictionaryService instead of Router, and Add[DictionaryName]CodeAction instead of Add[DictionaryName]CodeService but Service & Router sounds better - any comments about that?


You would need to provide more information. From the information given, I don't see why you'd need separate classes for each Dictionary. If the logic for each dictionary is different, I would have something like a "DictionaryService" per Dictionary, which handles all different methods add/delete/remove. Then you could have a registry (map) to lookup the service to be used for a specific Dictionary.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜