menu
  Home  ==>  papers  ==>  design_patterns  ==>  gof_design_patterns   



1 - The 23 patterns from the Gof

This page simply allows you to download the Delphi source code of the Design Pattern samples presented in the GOF book. GOF stands for Gang Of Four, which is the nickname of the four authors who wrote the book which started the whole pattern movement:

Erich GAMMA, Richard HELM, Ralph JOHNSON, John VLISSIDES
Design Patterns
    Elements of Reusable Object-Oriented Software
Addison Wesley - 1994 - ISBN 0-201-63361-2
Most of the example in the book are coded in Smalltalk, and some in C++. We present here the Delphi version.



2 - The Delphi Source Code

For each of those 23 programs
  • we tried as much as possible to follow the syntax of the book examples
  • the programs, like those in the book, have no practical use. Most of them do not compute or display anything (all the classes should have been initialized, a main entry point written etc). Some classes are even incomplete (missing constructor, no attributes ...). The samples were presented to illustrate some pattern coding techniques, not to show how to write an accounting application or a word processor.
  • however, all our projects will compile:
    • there are no missing definitions or classes
    • the Delphi Syntax is correct
  • we did not use any visibility feature (PUBLIC, PROTECTED, PRIVATE) although the C++ programs in the book sometimes use PRIVATE. We prefixed the PRIVATE or PROTECTED attributes or methods with an underscore ("_"), which is a nice convention anyway.
  • our code is not "minimal": some classes contain a CONSTRUCTOR which simply calls INHERITED, and this CONSTRUCTOR could be removed
  • we did not present any UML diagram, nor any motivation and explanation about each pattern. You will find those in the Pattern Book
  • the splitting of each pattern code into several Delphi UNITs is a personal choice: the Gof book does not specify any file distribution. An easy solution would have to place each pattern in a single file (a .DPR in console mode, for instance). However separating classes in several UNITs often highlights relationships (we have to add USES clauses) or circular references. This helped us to better understand the pattern participant's dependencies.
  • the small expression interpreter used in Facade and Interpreter is the only piece we coded entirely
  • each .ZIP file contains the Gof Copyright, with the book title, the authors and the publisher
  • you will also find other Gof pattern source code, written in CPP, Java or C#. Some of those sources have been changed in the hope to provide better examples. This is not our choice: we simply adapted the syntax of the book samples to Delphi and added whatever syntactic sugar was necessary to be able to compile (IMPLEMENTATION, CONSTRUCTOR etc).
  • Gof also published a "Design Patterns CD". It seems that the CD contains:
    • the electronic version of the book in hyper text
    • the sample source code in C++ and Smalltalk
    Please visit the AMAZON web site and search "VLISSIDES" or any of the other authors.


One might wonder why we took the pain to write those Delphi codes:
  • they allow you to follow the Gof explanation with Delphi coded examples
  • they could be used as starting point for more elaborate example
There is no doubt however that the .ZIP alone are totally useless. My best advice would be: go buy the book, and read it from cover to cover.



Some remarks about our coding conventions:

  • the Gof patterns are classified into creational, structural, behavioural. When you unzip our files, they will also be places in those categories.
  • many classes in the book are "abstract classes". We tried as much as possible to communicate this in our code:
    • by using a comment "// -- abstract"
    • adding the VIRTUAL; ABSTRACT; options to the methods
    • by using "_abstract_" in the CLASS name
    We could of course have used COM INTERFACEs, but this would have been further away from the book which has CPP examples but not Microsoft COM examples.
  • CLASS FUNCTIONs have only be used for the Singleton pattern
  • some code snippets in the book are common to several patterns, like the MAZE example. But there are some variations between the examples. To avoid confusion, we numbered MAZE.PAS versions, so that each .ZIP is totally self sufficient and independent from the other .ZIP
  • the book also presents in an appendix some common geometric code (to define points, shapes etc). This has not been coded, since WINDOWS.PAS (containing the tPoint definition), TYPES.PAS (with the Point function) and CLASSES.PAS (for the tList) already provide this standard code
  • for each of our 23 example
    • a folder "_xxx\" will be created during unzip (xxx being one of the pattern name: "factory", "visitor" etc)
    • each project is named P_GOF_XXX.DPR U_GOF_XXX.PAS U_GOF_XXX.DFM
    • the Gof class definition and code proper are in one or several units in the "GOF\UNITS\" sub folder.
    Each project has its own .ZIP, which contains ALL necessary units. The files are independent of where you will unzip them (all pathes in the .DOF are relative). Therefore:
    • download any of the .ZIPs
    • copy it in any folder. For instance C:\GOF\
    • unzip the whole thing
    • load the .DPR
    • compile


3 - Download The Sources

This is the list of the 23 .ZIP files (around 20 K each, 35 K for the biggest, Interpreter)


4 - Other Papers with Source and Links

Database
database reverse engineering Extraction of the Database Schema by analyzing the content of the application's .DFMs
sql parser Parsing SQL requests in Delphi, starting from an EBNF grammar for SELECT, INSERT and UPDATE
ado net tutorial a complete Ado Net architectural presentation, and projects for creating the Database, creating Tables, adding, deleting and updating rows, displaying the data in controls and DataGrids, using in memory DataSets, handling Views, updating the Tables with a DataGrid
turbo delphi interbase tutorial develop database applications with Turbo Delphi and Interbase. Complete ADO Net architecture, and full projects to create the database, the Tables, fill the rows, display and update the values with DataGrids. Uses the BDP
bdp ado net blobs BDP and Blobs : reading and writing Blob fields using the BDP with Turbo Delphi
interbase stored procedure grammar Interbase Stored Procedure Grammar : The BNF Grammar of the Interbase Stored Procedure. This grammar can be used to build stored procedure utilities, like pretty printers, renaming tools, Sql Engine conversion or ports
using interbase system tables Using InterBase System Tables : The Interbase / FireBird System Tables: description of the main Tables, with their relationship and presents examples of how to extract information from the schema
eco tutorial Writing a simple ECO application: the UML model, the in memory objects and the GUI presentation. We also will show how to evaluate OCL expressions using the EcoHandles, and persist the data on disc
delphi dbx4 programming the new dbExpress 4 framework for RAD Studio 2007 : the configuration files, how to connect, read and write data, using tracing and pooling delegates and metadata handling
blackfishsql using the new BlackfishSql standalone database engine of RAD Studio 2007 (Win32 and .Net) : create the database, create / fill / read Tables, use Pascal User Defined Functions and Stored Procedures
rave pdf intraweb how to produce PDF reports using Rave, and have an Intraweb site generate and display .PDF pages, with multi-user access
embarcadero er studio Embarcadero ER Studio tutorial: how to use the Entity Relationship tool to create a new model, reverse engineer a database, create sub-models, generate reports, import metadata, switch to Dimensional Model
Web
sql to html converting SQL ascii request to HTML format
simple web server a simple HTTP web Server and the corresponding HTTP web Browser, using our Client Server Socket library
simple cgi web server a simple CGI Web Server which handles HTML <FORM> requests, mainly for debugging CGI Server extension purposes
cgi database browser a CGI extension in order to display and modify a Table using a Web Browser
whois a Whois Client who requests information about owners of IP adresses. Works in batch mode.
web downloader an HTTP tool enabling to save on a local folder an HTML page with its associated images (.GIF, .JPEG, .PNG or other) for archieving or later off-line reading
web spider a Web Spider allowing to download all pages from a site, with custom or GUI filtering and selection.
asp net log file a logging CLASS allowing to monitor the Asp.Net events, mainly used for undesrtanding, debugging and journaling Asp.Net Web applications
asp net viewstate viewer an ASP.NET utility displaying the content of the viewtate field which carries the request state between Internet Explorer and the IIS / CASSINI Servers
rss reader the RSS Reader lets you download and view the content of an .RSS feed (the entry point into somebody's blog) in a tMemo or a tTreeView. Comes complete with an .HTML downloader and an .XML parser
news message tree how to build a tree of the NNTP News Messages. The downloaded messages are displayed in tListBox by message thread (topic), and for each thread the messages are presented in a tTreeVi"ew
threaded indy news reader a NewsReader which presents the articles sorted by thread and in a logical hierarchical way. This is the basic Indy newsreader demo plus the tree organization of messages
delphi asp net portal programming presentation, architecture and programming of the Delphi Asp Net Portal. This is a Delphi version of the Microsoft ASP.NET Starter Kit Web Portal showcase. With detailed schemas and step by step presentation, the Sql scripts and binaries of the Database
delphi web designer a tiny Delphi "RAD Web Designer", which explains how the Delphi IDE can be used to generate .HTML pages using the Palette / Object Inspector / Form metaphor to layout the page content
intraweb architecture the architecture of the Intraweb web site building tool. Explains how Delphi "rad html generator" work, and presents the CLASS organization (UML Class diagrams)
ajax tutorial AJAX Tutorial : writing an AJAX web application. How AJAX works, using a JavaScript DOM parser, the Indy Web Server, requesting .XML data packets - Integrated development project
asp net master pages Asp.Net 2.0 Master Pages : the new Asp.Net 2.0 allow us to define the page structure in a hierarchical way using Master Pages and Content Pages, in a way similar to tForm inheritance
delphi asp net 20 databases Asp.Net 2.0 and Ado.Net 2.0 : displaying and writing InterBase and Blackfish Sql data using Dbx4, Ado.Net Db and AdoDbxClient. Handling of ListBox and GridView with DataSource components
asp net 20 users roles profiles Asp.Net 2.0 Security: Users, Roles and Profiles : Asp.Net 2.0 offers a vaslty improved support for handling security: new Login Controls, and services for managing Users, grouping Users in Roles, and storing User preferences in Profiles
bayesian spam filter Bayesian Spam Filter : presentation and implementation of a spam elimination tool which uses Bayesian Filtering techniques
TCP/IP
tcp ip sniffer project to capture and display the packets travelling on the Ethernet network of your PC.
sniffing interbase traffic capture and analysis of Interbase packets. Creation of a database and test table, and comparison of the BDE vs Interbase Express Delphi components
socket programming the simplest Client Server example of TCP / IP communication using Windows Sockets with Delphi
delphi socket architecture the organization of the ScktComp unit, with UML diagrams and a simple Client Server file transfer example using tClientSocket and tServerSocket
Object Oriented Programming Components
delphi virtual constructor VIRTUAL CONSTRUCTORS together with CLASS references and dynamic Packages allow the separation between a main project and modules compiled and linked in later. The starting point for Application Frameworks and Plugins
delphi generics tutorial Delphi Generics Tutorial : using Generics (parameterized types) in Delphi : the type parameter and the type argument, application of generics, constraints on INTERFACEs or CONSTRUCTORs
UML Patterns
the lexi editor delphi source code of the Gof Editor: Composite, Decorator, Iterator, Strategy, Visitor, Command, with UML diagrams
factory and bridge patterns presentation and Delphi sources for the Abstract Factory and Bridge patterns, used in the Lexi Document Editor case study from the GOF book
gof design patterns delphi source code of the 23 Gof (GAMMA and other) patterns: Composite, Decorator, Iterator, Strategy, Visitor, Command
Debug and Test
Graphic
delphi 3d designer build a 3d volume list, display it in perspective and move the camera, the screen or the volumes with the mouse.
writing a flash player build your own ShockWave Flash movie Player, with pause, custom back and forward steps, snapshots, resizing. Designed for analyzing .SWF demos.
Utilities
the coliget search engine a Full Text Search unit allowing to find the files in a directory satisfying a complex string request (UML AND Delphi OR Patters)
treeview html help viewer Treeview .HTML Help Viewer : the use of a Treeview along with a WebBrowser to display .HTML files alows both structuring and ordering of the help topics. This tool was used to browse the Delphi PRISM Wiki help.
Delphi utilities
delphi net bdsproj structure and analysis of the .BDSPROJ file with the help of a small Delphi .XML parser
dccil bat generator generation of the .BAT for the Delphi DCCIL command line compiler using the .BDSPROJ
dfm parser a Delphi Project analyzing the .DFM file and building a memory representation. This can be used for transformations of the form components
dfm binary to text a Delphi Project converting all .DFM file from a path from binary to ascii format
component to code generate the component creation and initialization code by analyzing the .DFM. Handy to avoid installing components on the Palette when examining new libraries
exe dll pe explorer presents and analyzes the content of .EXE and .DLL files. The starting point for extracting resources, spying .DLL function calls or injecting additional functionalities
dll and process viewer analyze and display the list of running processes, with their associated DLLs and Memory mapped files (Process Walker)
Controls
find memo a tMemo with "find first", "find next", "sort", "save" capabilities
Helper units
windows environment read and write Windows Environment strings
stdin stdout send and receive strings from a GUI application to a CONSOLE application




5 - Your Comments



As usual:
  • please tell us at fcolibri@felix-colibri.com if you found some errors, mistakes, bugs, broken links or had some problem downloading the file. Resulting corrections will be helpful for other readers
  • we welcome any comment, criticism, enhancement, other sources or reference suggestion. Just send an e-mail to fcolibri@felix-colibri.com.
  • or more simply, enter your (anonymous or with your e-mail if you want an answer) comments below and clic the "send" button
    Name :
    E-mail :
    Comments * :
     

  • and if you liked this article, talk about this site to your fellow developpers, add a link to your links page ou mention our articles in your blog or newsgroup posts when relevant. That's the way we operate: the more traffic and Google references we get, the more articles we will write.
Created: sep-04. Last updated: jul-15 - 98 articles, 131 .ZIP sources, 1012 figures
Copyright © Felix J. Colibri   http://www.felix-colibri.com 2004 - 2015. All rigths reserved
Back:    Home  Papers  Training  Delphi developments  Links  Download
the Pascal Institute

Felix J COLIBRI

+ Home
  + articles_with_sources
    + database
    + web_internet_sockets
    + oop_components
    + uml_design_patterns
      – the_lexi_editor
      – gof_design_patterns
      – factory_and_bridge
    + debug_and_test
    + graphic
    + controls
    + colibri_utilities
    + colibri_helpers
    + delphi
    + firemonkey
    + compilers
  + delphi_training
  + delphi_developments
  + sweet_home
  – download_zip_sources
  + links
Contacts
Site Map
– search :

RSS feed  
Blog