comp.lang.ada
 help / color / mirror / Atom feed
From: Matthew Heaney <matthew_heaney@acm.org>
Subject: Re: ANNOUNCE: Abstract Factory posted to ACM patterns archive
Date: 1999/03/08
Date: 1999-03-08T00:00:00+00:00	[thread overview]
Message-ID: <m3u2vw1fbx.fsf@mheaney.ni.net> (raw)
In-Reply-To: 7bmcb5$jkf$1@nnrp1.dejanews.com

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.









  parent reply	other threads:[~1999-03-08  0:00 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-03-04  0:00 ANNOUNCE: Abstract Factory posted to ACM patterns archive Matthew Heaney
1999-03-04  0:00 ` dennison
1999-03-04  0:00   ` Peter Milliken
1999-03-08  0:00   ` Matthew Heaney [this message]
1999-03-08  0:00     ` Jerry van Dijk
1999-03-09  0:00       ` Matthew Heaney
1999-03-09  0:00       ` fraser
2011-10-14 18:51 ` Rego, P.
2011-10-14 19:29   ` Simon Wright
2011-10-14 19:56     ` Rego, P.
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox