Design Pattern in OO ABL – Part 1 of 3

Design Pattern in OO ABL – Part 1 of 3

Wikipedia says: ‘In software engineering, a software design pattern is a general, reusable solution to a commonly occurring problem within a given context in software design.’

Patterns are conceptual work, the idea has been known to the public ever since the publication of the book ‘Design Patterns: Elements of Reusable Object-Oriented Software’, in 1995.

In a larger project design patterns help to keep the code reusable, readable, and to avoid problems in the long term. E.g. using the “Builder Pattern” allows changing and adding parameters of often used objects late in a project.

This article will describe how to implement some of the patterns in OpenEdge Object Oriented ABL – shortly named OO ABL. The chosen patterns are very common and often used. The view to the patterns is driven by daily, practical work.

This article is based on a presentation of Michael Barfs, first held at Germany’s Progress User Group meeting in March 2018.

Pattern 1 – Builder (Creational Pattern)

The Builder Pattern is a Creational Pattern, it uses a second object to create and set up an object.

Imagine you have an object like this:


For several ways to create an instance of the ‘user’ there are several constructors in the class with more or less parameters.

So if you would like to create a user object with all parameters, the code looks like this:

With builder, the object diagram looks like this:


Besides the User object there is an UserBuilder object. This object has all the properties from the User object, but the constructor only has the mandatory properties (First and Last name). For every other property there is a method with a descriptive name, e.g. for iAge there is SetAge.

The secret is hidden in the setter methods:

The setter method sets the according property and returns itself (THIS-OBJECT). That means, the output is the builder object and this can be used to set another property or to complete the object.

This structure is called chaining. By the way, the created UserBuilder object is thrown away immediately and will hopefully be removed by the garbage collector.

Advantages of Builder Pattern:

  • Readable – the property is named by the setter method
  • Less confusion with parameters – they are named
  • Auto-complete suggests property methods
  • Shorter than setting properties in user object
  • Simple to change the base object without changing existing calls

To make the advantages clearer, here is an example of a procedural code with a lot of parameters.

The code is a shortened version of the full call.

The parameters are in a given order (like a very large constructor). If a parameter is added, removed or changed, every existing calls needs to be changed, too.

The programmers were so desperate, that they added a universal parameter (List of key=value{Delimiter}key=value…). That was done to allow changing the parameters without changing existing code. These kinds of lists are very good as a short term fix, but bad in long-term maintenance.

So that is was working solution, but not a good one.

Here is the approach with the Builder Pattern (excerpt).

The code is much more readable and you can add parameters without changing existing code.

The Builder Pattern will make the code more readable, better working due to auto-complete and allows changes later in a project.

Pattern 2 – Singleton (Creational Pattern)

The Singleton Pattern is a Creational Pattern, it is a substitution for global objects in OO.

There are no global objects in OO languages, but many people see the need for kinds of global structures, e.g. read only setup information.

Some people disagree with the idea of the Singleton Pattern, since they see it as an Anti Pattern. Here is a good discussion about the pros and cons of using Singleton and what to consider .

If you use a Singleton for read-only content and Dependency Injection for dependent state information, it should be OK.

The Singleton is using the effect, that static elements (object, properties) are kind of global. They are instantiated during first access and they exist as long as the session is running. They can not deleted.

Here is the base code.

Note the PUBLIC STATIC property and the PRIVATE constructor.

Note also that the configuration object is created during the first call of the object instance (oInstance).

Here is the usage of the configuration object.

Advantages of Singleton Pattern:

  • Solves problem of global settings
  • Inheritance is possible (which is not possible from a static object)
  • Has some logic during instantiation
  • Can be re-instantiated (which is not possible with a pure static object)


The Singleton Pattern will make kinds of global settings available.

Programmers must care about dependencies! It would be best to use Singleton for read only and Dependency Injection for a local active program state.

Pattern 3 – Multiton (Creational Pattern)

The Multiton Pattern is a Creational Pattern, like a bunch of Singletons. It is using a static element for singular data access.

The Multiton returns an object based on an index value. It will guarantee that every call using this index value will return the same object.  This is useful, when you have multiple run time objects that are accessing one piece of data.

Here is the object structure.


Sample code of the declaration part. Note that the temp-table is static (global).

The access method is public, but static.
When an instance is asked for an entry, an existing object or new object will be returned.
The reference in the temp-table is permanent, so garbage collection will not happen.

The constructor is private, it will be called from the code above and not from the code using the Multiton.
This sample code is loading data from the database.

Finally, here is the usage.
We give a customer number to the Multiton and receive a customer object.


  • The basic idea of Multiton is to have thread safe objects
    (which is at the moment not important for OOABL)
  • The objects are like global, so they accumulate
    (the programmer may delete them)
  • Creating/Accessing 10000 objects is OK, 100000 is not (much slower)
    (Performance test in OE 11.7x)


  • Vulnerable to side effects, e.g. like global shared buffer
  • Unit tests becomes more complex
  • OOABL performance problems with lots of objects

The Multiton can be used without any considerations for reading data, like in reports or display only.

Subscribe now to our newsletter

Sign up now to get informed about new releases, updates and changes within the Tools4Progress and OF-1 software family and about IAP events.

The Multiton Pattern will allow program-wide access to unique resources. This could be streams, WebServices, ESB access, DB connections and data.

But for updating data, the programmer is highly responsible to make sure to avoid side effects! And the OOABL may be too slow for large numbers of instantiated objects.

Klaus Erichsen
Based on a presentation by Michael Barfs
Hamburg, April 2018

Contact me: ed.pa1532268609i@ek1532268609

Any code is given as example and “as is”. Usage is allowed, but IAP is not responsible for the outcome.