0

Java service classes... I have two service classes one for 'store'(save) data, another service for 'load' to display content.

It was implemented , now new requirement - depends on user input for load (for ex version) if it is not latest one do some logic to upgrade(based on some xslt transfomation) and save(store) the content. In this scenario for upgrade ,'save' logic is same as in actual 'store' service.

I should reuse the code for 'save' which is for load service also. One restriction is shouldn't call storeservice from load service.

I need to put common logic/code in some helper/util class?. Is it good design creating a helper/util class ??.In that case almost 90% code for store service need to move into util/helper class!!!!

any other thought for the solution

closed as unclear what you're asking by gnat, Christophe, Bart van Ingen Schenau, Doc Brown, user22815 Nov 28 '16 at 16:29

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Define service class. – Tulains Córdova Oct 26 '16 at 13:29
  • @TulainsCórdova No need to be offensive. This is obviously someone without an advanced knowledge of English, but enough to get by. The language of his question is perfectly understandable if you make an effort (there may be other issues, though). – Andres F. Nov 16 '16 at 21:24
2

Another option can be: Use a parent class with common functionalities and then some interfaces for each service with specific logic. example:

  • Service --> common methods for save, load with implementations because are common, or even you could use another helper class if you want.

Interfaces for each specific service if you need specific methods which allows to you more specific functions for each service and even create more implementations of each service for different purposes:

  • ServiceOneInterface
  • ServiceTwoInterface

Then you could create each service as:

  • MyServiceOne extends Service implements ServiceOneInterface
  • MyServiceTwo extends Service implements ServiceTwoInterface

Not the answer you're looking for? Browse other questions tagged or ask your own question.