Java provides inbuilt features to implement Prototype design pattern. But, before using that I will show you how you can create a prototype without any help from any libraries. So, we have a Person class. public class Person { private String firstName; private String lastName; private String country; public Person(){} public Person(final String firstName, final String lastName, […]
Builder Design Pattern implementation in Java
There are many cases where, you do not need to provide values for all the variables and it is still a valid object, for example Java HttpClient. To this class you just have to provide a very basic minimum values and it will work. In the classes, where an instance is expected to work with […]
Implement Singleton design Pattern using static class
Using static class to provide singleton feature, allows to lazy instance creation. The instance is not created until you access that static class. As, the class and instance is static, we have only one instance, and this by java programming language design. public final class SingletonStaticWay { static class Inner { private final static SingletonStaticWay […]
Singleton Design Pattern Implementaion using synchronization in Java
Singleton class can have only one object in an entire application. In this implementation, I use a function to create an object and I use synchronization to restrict entry of more than one thread into the block that creates the instance. I double check for null status of the object, to prevent creation of multiple instances […]
Builder Design Pattern Implementation using Java Programming Language.
You can watch me live coding builder design pattern on youtube. The Builder pattern is used for creation of instances where there are many properties. And, an instance can be a valid instance with most of the properties having no values at all. One of the examples in Java is StringBuilder , we use append method to […]
Singleton Design Pattern Implementaion in Java
In this post, I am trying to explain singleton design pattern, using java programmig language. Source Code of Singleton desing pattern. There are two ways which we can do it. We can use an Inner static class to keep a final instance of our target class. Or, we can use double null-check with synchronized block […]