문제

I'm planning to implement a process using a java app. The process has various phases. Each phase has an input and output.

So it is something like input1=>phase1=>outpu1=>phase2=>output2=>phase3=>final_output

I want to write a java application in which the users can extend any phase to implement their own functionality.

for e.g: lets say that phase1 sorts the given input. I want to let my app users create custom class which will replace the functionality of phase1. they may want to do counting instead of sorting.

Any ideas on how to do this? plugin architecture? Any examples of frameworks which work in similar way? Where to start? edit: the input is from the user. let us say my app takes a set of numbers and does sorting(phase1) then removing duplicates(phase2) and adding(phase3) and gives output. Now I want the phases to be customizable. Probably by allowing them to define their own class which does something else.

도움이 되었습니까?

해결책

An idea of solution: Phase would be an interface with a process() method, which can be implemented with any algorithm. This process() method could have an Output return type and take another Output as parameter, with Output another type (class or interface). And an Executor class, which will execute the whole process, with a an execute() method using a List of Phase, using the return ouput of each Phase as an input for the next one. The only open question is: what will be the input of the first Phase?

다른 팁

I think that your question is too generic to provide a framework. That being said, you could take a look at the Strategy Pattern (more here).

The aim of the pattern is to define behaviours and then, pass these behaviours as method parameters. This will allow you to have one method which does multiple things, depending on what type of parameter you have passed.

Please note however, that in my opinion, having the same method do sorting and counting will result in problems. Ideally, each method should, at least, do operations which are somewhat similar, so for sorting, you could have the method which does ascending and descending sorting and then, another method which does the counting.

Your question is so vague, you could implement this just by having a common interface with one method.

Is there a particular reason why the "phases" or stages cannot occur concurrently?

Or you could implement something far more complex such as a JMS based framwork or using something like SEDA

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top