Category: design pattern
By admin on Nov 5, 2008 in Java, Refactoring | Comments Off on Java: Refactoring Methods
Here are the guidelines that we follow to refactor the methods in one of the legacy Java application, simplified from Martin Fowler refactoring book. Rename a method to server its purpose Add a parameter to the method if it is required Remove a parameter if it is not required Separate query from modifier and let […]
By admin on Oct 7, 2008 in .NET, Enterprise, free ebook | 2 Comments
.NET Enterprise Solutions … Software Engineers on their way to Pluto .NET Enterprise Solutions … Best Practices for the Connoisseur .NET Enterprise Solutions … Interoperability for the Connoisseur Downloadable here
By admin on Oct 5, 2008 in Java, Programming, Refactoring | Comments Off on Java: Refactor Code by Introducing NULL Object
This is from the Refactoring book by Martin Fowler. In our code we always need to check if a object is null, and depending on it, different actions are taken. E.g. for the following code 1: if (subscriber == null) { 2: ratePlan = defaultRatePlan; 3: } else { 4: ratePlan = subscriber.getRatePlan(); 5: } […]
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 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 Aug 5, 2008 in Framework, Java, Programming | 1 Comment
This is the sequel of my previous post on the AppFuse source code, a good MVC framework. Thanks to Matt Raible and the team for this wonderful framework. By reading the code, I can understand the framework better in order to use it correctly. For AppFuse, for the data access layer you can use Hibernate, […]
By admin on Aug 3, 2008 in Framework, Java, Programming | 2 Comments
I have been using AppFuse in several projects. It is a excellent framework which implemented a proper MVC architecture. In order to better understand the framework, I spent sometime browsing through the source code, I also tried looking for some local SEO services where I could help fast. In Part I of this articles I […]
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 May 3, 2008 in Java, Others, Programming | 1 Comment
Download Source Code This is the design pattern I came across while browsing through my RSS feed reader. Not very confirmed now from where I read about this. It is quite hard to apply this to the data access layer since I use ORM tools but I am not sure how this can be applied […]
By admin on Mar 17, 2008 in Behavioral, Java, Programming | Comments Off on Design Pattern: Design a Simple Workflow using Chain of Responsibility Pattern
Download Source Code I was trying Apache Commons Chain when I was trying to design a simple workflow system for my back-end application using the Chain of Responsibility design pattern. Chain of Responsibility is a popular technique for organizing the execution of complex processing flows. It is not difficult if you want to write it […]
By admin on Feb 15, 2008 in design pattern | 2 Comments
This is one of the applications that I developed some time back and I am going to use it to demonstrate some of the design patterns. Basically this is a simplied share trading system. You can have a look at the E-R diagram here. The MySQL script can be downloaded here. MySQL Script Using this […]
By admin on Feb 15, 2008 in .NET, Creational, design pattern | Comments Off on Design Pattern in .NET 101 – Abstract Factory Pattern (Creational Pattern)
Download Sample Code Abstract Factory pattern provides an interface for creating families of related or dependent objects without specifying their concrete classes. E.g. I have a DocumentFactory class that either returns DefaultDocumentFactory or CustomDocumentFactory dependening on the environment variable. using System; using System.Collections.Generic; using System.Text; namespace AbstractFactory { abstract class DocumentFactory { public static DocumentFactory […]
By admin on Feb 15, 2008 in .NET, Creational, design pattern | Comments Off on Design Pattern in .NET 101 – Abstract Factory Pattern (Creational Pattern)
Download Sample Code Abstract Factory pattern provides an interface for creating families of related or dependent objects without specifying their concrete classes. E.g. I have a DocumentFactory class that either returns DefaultDocumentFactory or CustomDocumentFactory dependening on the environment variable. using System; using System.Collections.Generic; using System.Text; namespace AbstractFactory { abstract class DocumentFactory { public static DocumentFactory […]
By admin on Feb 15, 2008 in .NET, Creational, design pattern | Comments Off on Design Pattern in .NET 101 – Abstract Factory Pattern (Creational Pattern)
Download Sample Code Abstract Factory pattern provides an interface for creating families of related or dependent objects without specifying their concrete classes. E.g. I have a DocumentFactory class that either returns DefaultDocumentFactory or CustomDocumentFactory dependening on the environment variable. using System; using System.Collections.Generic; using System.Text; namespace AbstractFactory { abstract class DocumentFactory { public static DocumentFactory […]
By admin on Jan 26, 2008 in Behavioral, design pattern, Java, Programming | 1 Comment
Download Sample Code A Command pattern is an object behavioral pattern that allows us to achieve complete decoupling between the sender and the receiver. It allows you to encapsulate a request as an object, thereby letting you parameterize clients with different requests, queue or log requests. Here is a rewrite of the C# example provided […]
By admin on Jan 26, 2008 in Behavioral, design pattern, Java, Programming | 1 Comment
Download Sample Code A Command pattern is an object behavioral pattern that allows us to achieve complete decoupling between the sender and the receiver. It allows you to encapsulate a request as an object, thereby letting you parameterize clients with different requests, queue or log requests. Here is a rewrite of the C# example provided […]
By admin on Jan 22, 2008 in Enterprise, Java, Programming | 1 Comment
Download Sample Code This is Part II of the previously described Lazy Load pattern. value holder A value holder is used as a generic Lazy Load. It is an object that wraps some other object. To get the underlying object you ask the value holder for the value, and the first access will pull the […]
By admin on Jan 22, 2008 in Enterprise, Java, Programming | 1 Comment
Download Sample Code Lazy Load is one of the object relational behavioral patterns. With lazy load, an object does not contain all of the data you need but knows how to get it when it is needed. This pattern is commonly found in most of the OR mappers, e.g. Hibernate. E.g. when you load the […]
By admin on Jan 12, 2008 in .NET, Creational, Programming | 1 Comment
Download Sample Code Factory Method Pattern defines an interface for creating an object, but let subclasses decide which class to instantiate. It lets a class defer instantiation to subclasses. E.g., I defined a abstract News class. using System; using System.Collections.Generic; using System.Text; namespace FactoryPattern { abstract class News { } } Different kinds of news […]
By admin on Jan 10, 2008 in .NET, Programming, Structural | Comments Off on Design Pattern in .NET 101 – Facade Pattern (Structural Pattern)
Download Sample Code Facade Pattern provides a unified interface to a set of interfaces in a subsystem. It defines a higher-level interface that makes the subsystem easier to use. E.g. I have a Call Details Record (CDR) to be processed by different systems. It is defined in the CDR class using System; using System.Collections.Generic; using […]