I'm creating some kind of filtering system, which is based on that the different elements accept/produce the same kind of 'context'.
For example with the following, the process can be modelled:
{generate_numbers(1..100)} --> {is_prime} --> {output}
The context can be a simple 'HashMap'. generate_numbers
creates contexts where 'x' is set to some number is_prime
uses this context, looks for 'x' and puts 'prime'=true/false accordingly.
pros:
- flexibility (easily extendable further (HashMap))
cons:
- typeless values are casted all over the place
It is also a viable approach to declare everything as a field in the 'context', but this way the easily extendability is sacrificed (i can live with that)
But...the situation is a bit more complicated because these transformator elements are scattered all over the application's packages:
{generate_numbers(1..100)} --> {is_prime} --> {calc(f_1)} --> {output}
{--------------- pkg_A ------------------} | {--------- pkg_B -------}
So there are parts where pkg_A does some work, then there are places where pkg_B parts process the context --> that's why i would like to mix the two methods
I've come up with the following ideas:
option 1
- say i've named the basic HashMap containing context E
- create subclasses of E where some entries are presented in field for which getters/setters are availibe
- in every processing function cast the incoming argument into the required class type
pro:
- relatively easy to implement
con:
- should syncronize the HashMap content w/ the field
- more than one way to access a value can cause confusion
option 2
- create some 'tool' classes which do the casting
pro:
- no runtime casting for a subclass at every function
con:
- access is always translated down to HashMap access
- there is a casting every time a field is read
option 3
i'm entirely wrong, i should address the problem in a different way
UPDATE:
with "how to promote a context class?" i mean that how can i make a relatively convienient context which will carry all the messy stuff the application is working on, because in the current workflow these informations are blurred with the control logic