BasePatterns.org

"A good designer must rely on experience, on precise, logic thinking; and on pedantic exactness. No magic will do." - Niklaus Wirth

About

Pattern recognition is one of our most valuable skills. So many aspects of our lives depend on it.

Software development also increasingly relies on emergent patterns for improving quality based on previously successful approaches.

BasePatterns.org explores some of the fundamental approaches used in developing modern software.

October 18th 2011
Tags: Uncategorized

No Comments

Prevent multiple instances of an application

A simple way to prevent running of multiple instances of your application is to use Socket communication. For example, in Groovy the first thing you would execute is something like this: [code] try { // choose a unique port (!!) new Socket('localhost', 1337) ...
November 2nd 2009
Tags: Java

No Comments

Service Selector

Sometimes we may have more than one implementation and/or instance of a service to which we need to route requests. Routing may be controlled by a number of different factors, such as the request type, request arguments, runtime configuration, etc. An implementation of such routing might look something like this: [java] public interface ...
October 13th 2009
Tags: Java

No Comments

Uniform Caching

Typically object caching in Java is managed by the container or framework in use. Occasionally however there is a need to manually cache domain-specific objects, whereby a java.util.Map implementation will not suffice. Using the popular ehcache framework as an example, the following pattern is typically observed: [java] public class SomeClass { private ...
October 8th 2009
Tags: Java

No Comments

Whiteboard Registry

In OSGi using a publisher/subscriber design can be somewhat more complicated that traditional Java environments: [java] public class SomeBundleActivator implements BundleActivator { private SomeService service = ... private ServiceRegistration registration; public void start(BundleContext context) { registration = context.registerService(SomeService.class.getName(), service, null); } ... } public class AnotherBundleActivator ...
September 30th 2009
Tags: Java

2 Comments

OSGi Service Locator

The Service Locator pattern is a well-established mechanism for accessing local and remote services in a consistent manner: [java] public interface ServiceLocator { <T> T findService(String serviceName) throws ServiceNotAvailableException; } [/java] Using a structured service name interface we can improve uniformity and reduce the potential for typos: [java] public enum ServiceName { SomeService("SomeService"); ...