Thursday 16 June 2016

Creating special F dependent on class A

Current situation:

New situation required:

We don't wish to touch the intervening classes, as they are called from different parts of the application for different reasons.

Solutions:
  1. provide a boolean flag all up/down the chain
  2. provide a "nicer" boolean flag, for example an enum or a Factory that determines which f should be created
  3. use a static flag in f2, in class a2 just set the flag appropriately -> completely unthreadsafe.
  4. use the ThreadLocal storage to store the boolean in a/a2 and read it in f/f2.
  5. in e -> call up the stacktrace and check for the existence of class a2.
  6. in e -> throw exception, call up the stacktrace and cehck for the existence of class a2.

However, the underlying problem is of course, that the two classes are too far apart, and there is too much tight coupling between the intervening classes and the rest of the system.

Also, the whole problem might go away with Functional Programming, but I'm not sure about that.

What do the experts say?

No comments:

Post a Comment