Thursday, September 13, 2012

A Design pattern to avoid if-else ladder


Did you ever wrote a code that is having a long if else ladder? and did you ever thought of avoiding it? I am sure you would have written if else ladders atleast once. So what is wrong with it? Nothing special, one time I had to review a code that was having miles long if-else ladder and after scrolling so much and reviewing the code I had to put a plaster on my right hand index finger. [just kidding :) ]

Android Main thread says :I Still know what you did last summer


The latest version of android does not allow network activities on its main thread. It is a very good principle, so that the app will appear to load faster and you can do the costly operations in the background. So what would you do if you want to make a network connection when the app loads? One of the recommended solution android provides is the use of Async Task. This class is a wrapper over the java timer task and will do the processing in a seperate thread. This design provides an opportunity for the main thread to continue its job while the async task work in the background to finish the networking activities.