How can one make variables inherent to an object or system?

For example, when creating a web browser, each option that is created for the user to have control over (i.e. how a window opens, if downloads start immediately, if a download window opens or not, etc.) must be checked on every single event that involves this object or system using disgusting if-blocks.

Is it possible to make these features inherent to the system, such that they need not be checked again once the configuration has been modified?

(*I may be trying to make a non-constant variable be a constant after it is set, but I'm not sure, because I am still grasping at this concept that popped into my mind and may not make sense due to the nature of computers and how they must check every single thing every single time, which we don't mind so much since they do it all so darn fast.)


This question came to me when I was thinking about ASIC design versus universal computing. Analog systems are naturally faster because they just "are", but at the cost of non-adaptability. We created more univeral models (desktop computers) and higher level languages to allow for this adaptability, but at the cost of speed. The speed reduction is a result of the additional overhead and many other things, one of these many things being constant state checking which is realized in the form of 'disgusting if-blocks'. So I suppose that I am looking for a way to simulate the static analog property in a dynamic system.

I thought of this problem further when I used my arm earlier today: my arm 'just was', and I didn't need to check if it was still attached and functional, or explain to it how to brush my teeth... it just knew! When did I lose you?

  • I am not entirely sure what you mean. Could you add an example to your question?
    – Philipp
    Apr 10, 2015 at 21:25
  • In addition to the web browser user configuration example?
    – user58446
    Apr 10, 2015 at 21:48
  • Your brain checks every time whether your arm is attached and functional, you simply don't think about it because this checking is several stack layers deep. When you move your arm you are simply calling an API perfected by millions of years of evolution. You are just abstracted from the details. Apr 10, 2015 at 22:13
  • And so I am trying to bury these base functions into deeper layers so that I can achieve the type of simplicity in programming... if this is possible. It sounds like 'stategy pattern' may be the closest thing so far to describing what I am thinking.
    – user58446
    Apr 10, 2015 at 22:18
  • But even the strategy pattern wouldn't save you from your original problem: You will either have to read your state in order to make a decision, or you have to update your cache whenever a property changes. In both cases, you still need to iterate over the mapping from to decision. If you want to cut down on complexity, you can aim for a hierarchical decision tree instead, where (when using the cached approach), changes will only bubble so far before they detected not to have an impact on the decision. You can make the decision from both sides in this case and meet in the middle.
    – Ext3h
    Apr 11, 2015 at 10:20

1 Answer 1


"disgusting if-blocks" can be avoided by using polymorphism to replace conditionals, or more specifically, by applying the strategy pattern. In your example, one could have objects representing a "window open" strategy, a "download strategy", a "download window opening strategy", and so on.

Not the answer you're looking for? Browse other questions tagged or ask your own question.