The following message is a courtesy copy of an article
that has been posted to comp.lang.ada as well.
I have prepared a short article on how to implement the Abstract Factory
pattern in Ada95, and posted it to the ACM patterns archive. The
introduction of the article appears below.
I've been slowly converting the C++ examples in the book Design Patterns
to Ada95. In each article I discuss the pattern, explain how to
implement it in Ada, and explore various idioms and language features.
A complete, working example with all the code is included.
You can subscribe to the patterns list by sending a message with the
subscribe patterns <your full name>
to the ACM mailing-list server.
<mailto:[log in to unmask]>
Abstract Factories Revisited
In this article I discuss an alternate version of the abstract factory,
implemented using static polymorphism.
The example also uses the smart pointer pattern to take care of memory
management, and declares a singleton instance of an abstract data type.
Way back when I showed how to implement the abstract factory pattern in
Ada95, using an example that more or less followed the one in the GoF
In that version, the abstract factory is implemented as a class. You
decide which kind of factory you want, and declare an instance of that
specific type, which gets elaborated during program initialization.
Ed Colbert gave me the idea that the abstract factory could be
implemented as a library-level renaming of another package. What a
great idea! Static polymorphism without it being a generic.
In this alternate version of the abstract factory pattern, I got rid of
the factory types, and just implemented factories as packages with an
identical interface. The actual factory that is used as _the_ factory
is chosen by way of a library-level renaming.
If you recall, the example from the book was a maze game, in which you
enter rooms, doors, and walls. Another version of the game features
"enchanted" maze items, and you select which version of the game you
want by choosing a different factory.
What we do here is first declare a family of maze item types, then
create a (singleton) maze object, using the factory to select the maze
items. You get a maze whose behavior changes based on which factory you