Java design pattern

I am trying to create an application where I will have a feature map IAction

. Each object IAction

has a method IAction IAction.processAction()

where it fulfills the knowledge contained in it. This can query the database calling the web service, etc. After each control is executed, it is IAction

then dispatched to the next instance IAction

.

When the application starts, it will contain a map Map

, which will be in the correct order of execution. The Integer

type key Map

is the order of execution. IAction.processAction()

can go to the last one IAction

on the map or stop it all together.

I can visualize the code in my head and I wrote a few lines to help me with this. I'm looking for a design template that can easily help with this type of processing. I'm not sure if the Command pattern would fit this role.

I was hoping someone would tell me which templates they think are appropriate for the account or not.

+2


source to share


4 answers


It looks like the Command pattern definitely has some relevance here.

However, I think you are on the wrong path. Design Swatches are essentially meant to be examples and recipes to guide your thoughts along product lines as you design how a product will work. What you do by adopting a good design and then trying to curb it into the "official" design pattern is the opposite.



Also, what's the key on your sitemap IAction

? It looks like a (possibly linked) list is a much more natural structure for them.

+4


source


This sounds like a variation on Chain of Responsibility.



+3


source


Your IAction follows the Command pattern neatly .

Your list of actions to take might be Composite .

+1


source


Posting the code will help us provide good solutions. Without a code, you only get recommendations.

And one more thing: Design patterns are just guidelines . When implementing a solution, you do not have to decide your solution in a specific design pattern. Once you start solving your problem, you can decide if your solution fits a particular pattern. If not, you can implement your solution without any design pattern.

Command_Pattern seems to be the solution for executing simple commands

. If your teams are independent of each other, a simple team pattern solves your problem. If some of your commands depend on other commands, you should use the Chain-of-responsibility_pattern setting a hierarchy.

The Composite template can be used to store all of your commands in a Map object.

0


source







All Articles