TEAM-ADA Archives

Team Ada: Ada Programming Language Advocacy

TEAM-ADA@LISTSERV.ACM.ORG

Options: Use Forum View

Use Monospaced Font
Show Text Part by Default
Condense Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Sender:
"Team Ada: Ada Advocacy Issues (83 & 95)" <[log in to unmask]>
Subject:
From:
Matthew Heaney <[log in to unmask]>
Date:
Wed, 3 Mar 1999 21:04:20 -0800
Reply-To:
Matthew Heaney <[log in to unmask]>
Parts/Attachments:
text/plain (64 lines)
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.

<http://www.acm.org/archives/patterns.html>

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
body:

subscribe patterns <your full name>

to the ACM mailing-list server.

<mailto:[log in to unmask]>

Matt


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.


Discussion

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
book.

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
use.

ATOM RSS1 RSS2