From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,386670df95abccf1,start X-Google-Attributes: gid103376,public From: Matthew Heaney Subject: ANNOUNCE: Abstract Factory posted to ACM patterns archive Date: 1999/03/04 Message-ID: #1/1 X-Deja-AN: 451034191 Sender: matt@mheaney.ni.net NNTP-Posting-Date: Wed, 03 Mar 1999 21:01:01 PDT Newsgroups: comp.lang.ada Date: 1999-03-04T00:00:00+00:00 List-Id: 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 body: subscribe patterns to the ACM mailing-list server. 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.