Builder Pattern For Complex Validations

Builder Pattern For Complex Validations


So, here is an extensible API for complex validations. I’ve written a small piece of code for common validations. The code can be extended to introduce more complex validations. Highlights – Builder Pattern Extensible code Non-instantiable Validation class Used a variety of concepts I discussed in the past month Here is the link to the github respository. Do check it out. https://github.com/73ddy/poc_trunk

Item 12: Consider implementing comparable


Usually while thinking of real time examples for a code solution, one often ends up comparing two objects. e.g. listing the companies in IT in the reverse order of their turnovers. This needs some comparison between 2 instances of object say TurnOver. Enough for the intro, the title tells you where exactly I am heading. Advantages of implementing comparable Implement for natural comparing TreeSet uses compareTo for comparing and sorting a set HashSet uses equals to avoid redundant keys Arrays.sort(a); ...

Item 11: Override clone judiously


Before talking on the clone method in java, I must list some very important facts. Object class has a clone method, but it is protected. So, it is not available to our objects.  One can always override the clone method, but you will get CloneNotSupportedException unless you make the class implement Cloneable interface and implement the clone method.  Java’s default clone method supports only a shallow copy of the object.a) super.clone returns an object of class Objectb) Shallow copy of ...

Item 10: Always override toString


Providing a good toString makes your class pleasant to use. Not only the users of your class will love using the toString method, even the debuggers IDEs use the toString method of your object. e.g. Which would you rather see when printing a map, “{Jenny=PhoneNumber@163b91}” or “{Jenny=(707) 867-5309}” When practical, the toString method should return all of the interesting information contained in the object It makes sense to display the whole phone number at once. Missing out the area code or ...


A good bird’s view of java exceptions and errors.