1. Computing
Send to a Friend via Email

Design Patterns in Delphi

Exploring design patterns, focusing on implementation issues in Delphi


"Patterns describe a problem which occurs over and over again in our environment, and then describe the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice."

Design Patterns
Patterns are devices that allow programs to share knowledge about their design. In our daily programming, we encounter many problems that have occured, and will occur again. The question we must ask ourself is how we are going to solve it this time.

In object-oriented programming, a pattern can contain the description of certain objects and object class to be used, along with their attributes and dependencies, and the general approach to how to solve the problem. By analogy, design patterns are to object-oriented programming what algorithms are to procedural programming. The basic elements of procedural programming (step instruction, conditionals, and branching) aren't very useful without concepts like linked list and quicksort to give them some structure.
In other words, Design Patterns provide tested and effective solutions to common problems that occur in software development.

The Delphi way...
Introduction to Design Patterns in Delphi - 2
This paper takes some sample patterns from Design Patterns book and discusses their implementation in Delphi. The following patterns are discussed and illustrated in Delphi to give you a starting point for implementing your own Delphi patterns: Singleton, Adapter, Template Method, Builder, Abstract Factory and Factory Method.

Introduction to Design Patterns in Delphi - 1
In this great article the concept of Design Patterns is introduced through the eyes of a Delphi programmer. The author goes straight to the heart of the matter with sample implementations in Delphi's Object Pascal. The following design patterns are covered: Singleton, Template Method, Strategy, Observer and Adapter.

Patterns Page
"The design patterns are not about designs such as linked lists and hash tables that can be encoded in classes and reused as is. Nor are they complex, domain specific designs for an entire application or subsystem...." The following design patterns are covered: Wrapper, Mediator, Singleton, Decorator, Lock, Visitor, Observer, Abstract Factory, Builder and factory Model.

Here are some more articles with design pattern implementation in Delphi.

Creating a real singleton class in Delphi
A singleton is a class that supports the creation of just one object. It's like your computer -- there's just one keyboard. So if you were writing Delphi code that simulated your computer, you would want just one object instance to deal with keyboard read, write, and control activities. The article describes how to create a class that follows the singleton pattern. The class described will take care of the singleton requirements and effects itself, effectively leaving the programmer to use the class as any others.

The Iterator Pattern
Enter the Iterator - a mechanism for iterating (hence the name) through a list without having to use an integer property.

The Observer Pattern
When we use Delphi to design forms and data modules, every time we place a component on the designer, several things change: the form now shows an appropriate representation of the component, the object inspector changes to show the properties of the component and, if we press Alt-F12, we see the .DFM file now contains information about the component. Whether this behaviour was modelled correctly on the Observer pattern or not, the result is that several 'interested parties' got to know about a change in the content of the project that we are working on.

A Recycling Factory Pattern in Delphi
The problems of using and reusing many varying size objects in an application can cause fragmentation of the heap that can slow down processing speed. In this article, the author uses a factory object to make and recycle objects with minimal fragmentation effects.

©2014 About.com. All rights reserved.