Home > Archive > Cobol > April 2005 > Please Explain about FACTORY
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Please Explain about FACTORY
|
|
| apknight 2005-04-27, 8:55 pm |
| Please Explain about FACTORY and Some Example .....
| |
| Michael Wojcik 2005-04-28, 8:55 pm |
|
In article <bdfbe.1134798$8l.491135@pd7tw1no>, "James J. Gavan" <jgavandeletethis@shaw.ca> writes:
> Lueko Willms wrote:
> Constructor - YES
Though languages with constructors can also have factories.
Factories are quite common in more complex Java APIs, such as JAX,
for example. They have certain advantages over constructors (like
polymorphism).
There was an article in DDJ a few years back on what's wrong with
Java's "new" and why factories are better in some cases.[1] You
need to be a registered user to read the whole thing.
1. http://www.ddj.com/documents/s=7027/ddj0204a/0204a.htm
--
Michael Wojcik michael.wojcik@microfocus.com
I would never understand our engineer. But is there anything in this world
that *isn't* made out of words? -- Tawada Yoko (trans. Margaret Mitsutani)
| |
| Pete Dashwood 2005-04-29, 3:55 am |
|
"Lueko Willms" <l.willms@jpberlin.de> wrote in message
news:9VZ$-BE9flB@jpberlin-l.willms.jpberlin.de...
> . On 26.04.05
> wrote dashwood@enternet.co.nz (Pete Dashwood)
> on /COMP/LANG/COBOL
> in 3d4cvoF6re3v6U1@individual.net
> about Re: Please Explain about FACTORY
>
>
> PD> It's a place where you make things.
> PD>
> PD> In Object Oriented COBOL it contains storage and methods that can be
> PD> used to generate objects of the class.
>
> Is that what in other languages is called the constructor or
> desctructor?
>
Yes. In other languages it is a constructor. (ususally it implements the
'NEW' method of the class. You don't need a factory for this, as this method
can be inherited from the class base, but putting it in the factory makes it
explicit, and the factory can combine references to other obect methods that
cannot be achieved by inheritance alone. For example, the factory could
store internally a number of references to related objects for a specific
instance of a specific object it was being asked to create. When the
specific object was instantiated, the factory would 'gather' the object
references of the related objects as part of an 'initialisation' or
'startup' for the new obect. These object references can be stored in the
factory's local storage. The reference returned for the new object can then
be used to access the related objects, via the factory.
This is just one use of the factory. (Most OO languages provide a similar
facility, not just COBOL...)
The factory does not normally deal with destruction (although it certainly
can), as this is achieved by nulling the object reference. (Some less OO
systems require the specific invocation of a garbage collection object or
method. I believe VB, Java, and Fujitsu COBOL, garbage collect
automatically when pointers are nulled.) Stateless systems like JavaScript
don't even need the pointer to be nulled, although it can be...
Often, the factory is useful where there is a hierarchy of objects, as it
can automatically 'fill in the blanks' when a new object at a new level is
instantiated.
HTH,
Pete.
|
|
|
|
|