Design Patterns Archives | Code Pumpkin https://codepumpkin.com/category/design-patterns/ Let us code with pumpkin Fri, 20 Dec 2019 18:43:47 +0000 en-US hourly 1 https://codepumpkin.com/wp-content/uploads/2017/04/cropped-codepumpkinforIcon-2-32x32.png Design Patterns Archives | Code Pumpkin https://codepumpkin.com/category/design-patterns/ 32 32 Breaking Singleton using reflection and Enum Singleton https://codepumpkin.com/breaking-singleton-using-reflection-and-enum-singleton/ https://codepumpkin.com/breaking-singleton-using-reflection-and-enum-singleton/#disqus_thread Sat, 13 Jan 2018 21:15:24 +0000 http://codepumpkin.com/?p=3681 This is our fifth article in the series of Singleton Design Pattern. The purpose of the singleton class is to control object creation, limiting the number of objects to only one. In our previous articles, we have discussed how we can create Singleton Design Pattern in Single-threaded and multithreaded environment. We have also discussed how we can […]

The post Breaking Singleton using reflection and Enum Singleton appeared first on Code Pumpkin.

]]>
https://codepumpkin.com/breaking-singleton-using-reflection-and-enum-singleton/feed/ 0
Preventing Cloning in Singleton Design Pattern https://codepumpkin.com/preventing-cloning-in-singleton-design-pattern/ https://codepumpkin.com/preventing-cloning-in-singleton-design-pattern/#disqus_thread Sat, 13 Jan 2018 15:52:32 +0000 http://codepumpkin.com/?p=3624 This is our third article on Singleton Design Pattern. The purpose of the singleton class is to control object creation, limiting the number of objects to only one. In our previous two articles, we have discussed how we can create Singleton Design Pattern in Single-threaded and multithreaded environment. In this article, we will discuss how we can […]

The post Preventing Cloning in Singleton Design Pattern appeared first on Code Pumpkin.

]]>
https://codepumpkin.com/preventing-cloning-in-singleton-design-pattern/feed/ 0
Serialization and Singleton Design Pattern https://codepumpkin.com/serialization-singleton-design-pattern/ https://codepumpkin.com/serialization-singleton-design-pattern/#disqus_thread Sat, 13 Jan 2018 15:11:26 +0000 http://codepumpkin.com/?p=3579 This is our forth article in the series of Singleton Design Pattern Articles. The purpose of the singleton class is to control object creation, limiting the number of objects to only one.  In our previous three articles, we have discussed how we can create Singleton Design Pattern in Single-threaded and multithreaded environment. We have also discussed how […]

The post Serialization and Singleton Design Pattern appeared first on Code Pumpkin.

]]>
https://codepumpkin.com/serialization-singleton-design-pattern/feed/ 0
Singleton Design Pattern Using Double Checked Locking https://codepumpkin.com/double-checked-locking-singleton/ https://codepumpkin.com/double-checked-locking-singleton/#disqus_thread Sat, 06 Jan 2018 18:48:33 +0000 http://codepumpkin.com/?p=3493 This is our second article in the series of Singleton Design Pattern.  In this article, we will see different thread safe approaches for lazy Initialization Singleton Design Pattern like Using Synchronized getInstance() method, Double checked locking approach and Bill Pugh Implementation using Inner class. For navigating to the other articles on Singleton Design Pattern, please refer table of contents on the right […]

The post Singleton Design Pattern Using Double Checked Locking appeared first on Code Pumpkin.

]]>
https://codepumpkin.com/double-checked-locking-singleton/feed/ 4
Object Pool Design Pattern https://codepumpkin.com/object-pool-design-pattern/ https://codepumpkin.com/object-pool-design-pattern/#disqus_thread Sat, 29 Jul 2017 12:04:44 +0000 http://codepumpkin.com/?p=1299 Object pool design pattern is one of the Creational Design Pattern. In very simple term, this design pattern means To Reuse the objects which are very costly to create. Object pooling is creating objects of the class at the time of creation and put them into one common pool. Now whenever application needs object of that class […]

The post Object Pool Design Pattern appeared first on Code Pumpkin.

]]>
https://codepumpkin.com/object-pool-design-pattern/feed/ 0
What is the use of private constructor in java? https://codepumpkin.com/use-private-constructor-java/ https://codepumpkin.com/use-private-constructor-java/#disqus_thread Sun, 09 Jul 2017 10:16:35 +0000 http://codepumpkin.com/?p=1697 In Java, we can use any access modifier (i.e. public, protected or private) with constructor.  So, what are the uses of making constructor private? First thing that strikes your mind is Singleton Design Pattern which is also one of the most asked Core Java Interview Question to the 3-4 yr exp Java developers.  Apart from creating singleton class, private constructor […]

The post What is the use of private constructor in java? appeared first on Code Pumpkin.

]]>
https://codepumpkin.com/use-private-constructor-java/feed/ 1
Mediator Design Pattern https://codepumpkin.com/mediator-design-pattern/ https://codepumpkin.com/mediator-design-pattern/#disqus_thread Sun, 11 Jun 2017 06:50:18 +0000 http://codepumpkin.com/?p=1399 Mediator Design Pattern is one of the Behavioral Design Pattern. With the Mediator Design Pattern, communication between objects is encapsulated with a mediator object. Objects no longer communicate directly with each other, but instead communicate through the mediator. This reduces the dependencies between communicating objects, thereby lowering the coupling. Definition GoF Definition: Define an object that encapsulates […]

The post Mediator Design Pattern appeared first on Code Pumpkin.

]]>
https://codepumpkin.com/mediator-design-pattern/feed/ 0
Observer Design Pattern https://codepumpkin.com/observer-design-pattern/ https://codepumpkin.com/observer-design-pattern/#disqus_thread Wed, 07 Jun 2017 18:09:23 +0000 http://codepumpkin.com/?p=1257 Observer Design Pattern is one of the Behavioral Design Pattern. Observer design pattern is useful when you are interested in the state of an object and want to get notified whenever there is any change.  Definition GoF Definition : The Observer Design Pattern defines a one-to-many dependency between objects so that when one object changes state, all […]

The post Observer Design Pattern appeared first on Code Pumpkin.

]]>
https://codepumpkin.com/observer-design-pattern/feed/ 1
Builder Design Pattern https://codepumpkin.com/builder-design-pattern/ https://codepumpkin.com/builder-design-pattern/#disqus_thread Thu, 27 Apr 2017 10:46:48 +0000 http://codepumpkin.com/?p=815 Builder design pattern is a creational design pattern like Factory Pattern and Abstract Factory Pattern. For better understanding of  any  design pattern, You should know the problems faced by programmers before that design pattern was introduced. What are the traditional ways of creating an object of a class? We can provide either constructor or a static factory method to get the object  of […]

The post Builder Design Pattern appeared first on Code Pumpkin.

]]>
https://codepumpkin.com/builder-design-pattern/feed/ 0
How to create Immutable Class in Java https://codepumpkin.com/create-immutable-class-java/ https://codepumpkin.com/create-immutable-class-java/#disqus_thread Mon, 24 Apr 2017 04:06:48 +0000 http://codepumpkin.com/?p=771 Immutable class is a class which once created, it's contents can not be changed. In other words, Immutable objects are the objects whose state can not be changed once constructed.  In Java, String and all the wrapper classes e.g. Boolean, Integer, Long, etc are immutable classes. We can also create our own immutable class.  Why should we write Immutable Classes? Here are […]

The post How to create Immutable Class in Java appeared first on Code Pumpkin.

]]>
https://codepumpkin.com/create-immutable-class-java/feed/ 8