By admin on Aug 31, 2008 in Creational, design pattern, Java, Programming | 1 Comment
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: […]
By admin on May 31, 2008 in Creational, Java, Programming | 8 Comments
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 […]
By admin on Dec 31, 2007 in Creational, Java, Programming | 1 Comment
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; […]