The singleton design pattern guarantees that only one instance of a given class will be constructed. But, how can we address any exceptions that get thrown while this instance is being created? In today’s post, we’ll show how this issue can be solved using a special singleton initialization method, along with Java’s standard IllegalStateException class.
Tag: java
Helper Methods and Code Readability
Helper methods, or helper functions, are smaller pieces of code that perform part of an overall task. Often, when we write helper methods, it’s because we want to factor out a piece of code that’s common across multiple higher-level methods. But, we shouldn’t be afraid to write helper methods just for the sake of improved readability in a single algorithm as well.
Making Objects Immutable
This blog post describes what immutable objects are in object-oriented programming. After reading this post, you should be able to implement immutable objects, and understand how they can be used to prevent unintended side effects in our code.