a short question:
class ItemActionObject
{
private final Object moreParameters;
private final Object otherDependencies;
private final Item item;
public ItemActionObject(Item item, Object moreParameters, Object otherDependencies)
{
this.item = item;
this.moreParameters = moreParameters;
this.otherDependencies = otherDependencies;
}
public Object process()
{
//do some processing -> return result
}
}
VS
class ItemHandler //or ItemService
{
private final Object otherDependencies;
public ItemHandler(Object otherDependencies)
{
this.otherDependencies = otherDependencies;
}
public Object process(Item item, Object moreParameters,)
{
//do some processing -> return result
}
}
ActionObject:
- It seems to be more object oriented
- It treats the item as part of its own instance (in design-view)
- I can add there some more methods, to change options (moreParameters) later
- I dont have one process-method with a lot of arguments
- But: I have a lot of boilerplate code
- But: I instantiate one object only for one process-run and throw that object away after that.
Handler-Method:
- It is classic procedural-programming, i guess? (a negative point?)
- It has a separate view on the behaviour and on the item (in design view)
- It dont waste that much ressources, if i want to process 100 000 items, so i dont have to create 100 000 ItemActionObjects to process them, i just have to do 100 000 method-calls to process(item...)
Examples: Design: Object method vs separate class's method which takes Object as parameter? (the pdfPrinter is designed with a Service/Handler-class)
Example2: Some CSV-, or HTML-Export handler or Action-Object, where the export-classes encapsualte the behaviour of the export-algorithm and the item is some item with a well-definend interfaces, from where the exporter can get the correct data out of them to do its job.
Example3: I think a lot of things or all things in the world we can design like ItemActionObject or ItemHandler
So my question is, which one should i choose? Maybe your answer is: it depends. So my question is also, which more criteria i have to know to decide which solution is better. Maybe there are some criteria to get me on the way in some situations to use ItemActionObjects, in other situations ItemHandlers. But maybe there are also often criterias which speaks for both solutions. And which should i use then? (Im not a friend of throwing a coin^^)