Kode Log

Change is now. Learn, unlearn & relearn.


code quality

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… Continue Reading →

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… Continue Reading →

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,… Continue Reading →

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… Continue Reading →

Item 7: Avoid finalizers

There is no guarantee that the finalize method will be called immediately. So, one should not depend upon it for anything time critical. The Great Ancient Myth System.gc and System.runFinalization call finalizers with guarantee. The Truth They even don’t guarantee… Continue Reading →

Item 6: Eliminate obsolete object references

Please take a minute to go through the code given below. /** * Example of a memory leak * * @author lekhak.tumblr.com */ public class Stack { private Object[] elements; private int size = 0; private static final int DEFAULT_INITIAL_CAPACITY… Continue Reading →

Item 5: Avoid creating unnecessary objects

Avoid creating unnecessary objects This post will be bulleted as it shares more than one instance to take care of. new String(“SomeString”) This is a crime, the reason being Strings in java are immutable objects. “SomeString” string is an object… Continue Reading →

Item 4: Enforce noninstantiability with a private constructor

In the previous post we made a class static factory methods by enforcing a private constructor and exposing a public static final instance. This item of the book effective java is no different. Here too the author Joshua Bloch suggests-… Continue Reading →

© 2019 Kode Log — Powered by WordPress

Theme by Anders NorenUp ↑