Posts

Showing posts from September, 2014

Null Object Pattern

Want to avoid the crazy if conditions in your application and ensure that it does not crash and yet provide a good logging mechanism? Use the Null Object Pattern. You will end up writing in more classes but it will help you make a good stable app. Imagine you are trying to find something in a hierarchy; lets say a game object. Lets say the method used to find this gameobject is FindGameObject("Avatar") which returns either null or a valid game object. You cannot guarantee that this method will always return a valid game object. So you end up adding a condition like this GameObject obj = FindGameObject("Avatar"); if(obj != null) Printf("Do something"); Imagine if the hierarchy is long and you end up nesting the conditions like this GameObject objRoot = FindGameObject("Avatar"); if(objRoot != null) GameObject objParent =objRoot.FindGameObject("AvatarMain"); if(objParent != null) GameObject objChild = objParent.FindGameObjec...