Design Patterns: Singleton

Ensuring single instance use during instantiation. Every so often in development, a business rule dictates that instantiation of a certain type produce only one instance during the lifetime of the application. The Singleton design pattern, one of the Creational Patterns, ensures that regardless of many instantiations of a class may be attempted, only the first…

Design Patterns: Service Locator

Completing the IoC Design Pattern. In my Design Patterns: Inversion of Control article, I illustrated how to decouple classes from having dependencies – the CustomerPayment class contained a dependency on the IPayment interface. Any class which has intimate knowledge of another is tightly-coupled to that class. By implementing the IoC pattern, you provide for greater…

Design Patterns: Inversion of Control

Providing flexibility into the domain by abstracting implementation. Using abstraction between concrete and class implementation, avoid tightly-coupled classes, which leads to changes in once class to ripple throughout your application. One method of doing this is the Inversion of Control design pattern which allows the class calling the behavior to be ignorant of its details,…

Design Patterns: Factory

Providing flexible object-instantiation. In this example, I’ll illustrate a method by which a SalesAssociate object may be instantiated that is more flexible than the traditional way – using a constructor. Instead I’ll implement a factory design pattern to create the instance. There are two advantages to this approach: You can return a null object, which…

Design Patterns: Adapter

Exposing class behavior from another class. Sometimes you might need to access and use functionality defined from one class from within your own class. To illustrate this pattern, I’ll begin with a simple class that contains one method I wish to invoke from within my other class – this could be any class containing any…