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=0.6 required=5.0 tests=BAYES_20,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,386670df95abccf1 X-Google-Attributes: gid103376,public From: Matthew Heaney Subject: Re: ANNOUNCE: Abstract Factory posted to ACM patterns archive Date: 1999/03/08 Message-ID: #1/1 X-Deja-AN: 452508814 Sender: matt@mheaney.ni.net References: <7bmcb5$jkf$1@nnrp1.dejanews.com> NNTP-Posting-Date: Mon, 08 Mar 1999 01:45:56 PDT Newsgroups: comp.lang.ada Date: 1999-03-08T00:00:00+00:00 List-Id: dennison@telepath.com writes: > For those of us not up on the latest hip OO lingo, could someone please > explain what a "factory" is? FOLDOC didn't know, and the ACM website just > assumed I know. "Factory" just has its common meaning: an abstraction that you use to create other abstractions. This is why it falls under the rubric of "creational patterns." Different factories create different items. Consider "factories that make hamburgers." MacDonald's is a factory that creates one kind of hamburger. Burger Kind is different factory that creates another kind of hamburger. Carl's Jr. is yet another different factory that creates yet another kind of burger. Now think of code: package Hamburgers is type Root_Hamburger_Type (<>) is abstract tagged limited private; type Hamburger_Access is access all Root_Hamburger_Type'Class; ... end Hamburgers; package MacDonalds is function New_Hamburger return Hamburger_Access; end MacDonalds; package Burger_King is function New_Hamburger return Hamburger_Access; end Burger_King; Now, if we do this: package Hamburger_Factory renames Burger_King; and then a client does this: with Hamburger_Factory; procedure Eat is Hamburger : constant Hamburger_Access := Factory.New_Hamburger; begin ... A client who wants to eat a hamburger doesn't have to care which restaurant it came from, because he's only referring to the factory "in the abstract" (hence the name), by with'ing Hamburger_Factory. Library-level package renaming is a feature Ada provides for implementing static abstractions.