RSS Feed for CreationalCategory: Creational

Java: Create Immutable Object using Builder Pattern »

To create immutable Java object, we should use the Builder Pattern, as described in Effective Java. This is the pattern I normally used now for immutable class. 1: public class Person { 2: private final String name; 3: private final int age; 4: private final String email; 5: private final String mobileNo; 6:  7:  8: […]

Singleton is a bad design pattern »

I am not totally against Singleton design pattern. However, based on experience, normally if there is Singleton design pattern in your application, you should carefully study your code. Usually there is always a better way of doing it other than using Singleton design pattern. Consider the following code snippet I encountered for one of the […]

Design Pattern in Java 101 – Builder Pattern (Creational Pattern) »

Download Source Code Builder pattern is used to construct a complex object from simple objects step by step. E.g., I have a Message class public class Message { private String sender; private String recipient; private String header; private String body; public String getSender() { return sender; } public void setSender(String sender) { this.sender = sender; […]