I do not want to use Switch in my code, so I\'m looking for some alternative
Example with Switch:
function write(what) { switch(w
An alternative is to define a class with a write method, and override that in subclasses Red and Blue to do the right thing.
write
Red
Blue
Whether or not that is better than your proposed solution, depends on your particular situation.