blob: 8c458fe07c2008d02f41b4c1e9b556cd3c58759d [file] [log] [blame]
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta name="copyright" content="Copyright (c) IBM Corporation and others 2000, 2005. This page is made available under license. For full details see the LEGAL in the documentation book that contains this page." >
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<title>
Replacing constructor calls with factory method invocations
</title>
<link rel="stylesheet" href="../book.css" charset="ISO-8859-1" type="text/css">
</head>
<body>
<h1> Replacing constructor calls with factory method invocations </h1>
To replace calls to a constructor with calls to an equivalent factory method:
<ul>
<li> In a Java editor or Java view, select the constructor declaration</li>
<li> Do one of the following:
<ul>
<li> From the menu bar, select <strong>Refactor &gt; Introduce Factory</strong> or </li>
<li> From the pop-up menu, select <strong>Refactor &gt; Introduce Factory</strong> </li>
</ul>
</li>
</ul>
<p>
You will be asked what to name the new factory method, on what class it should be placed,
and whether to make the constructor private when the refactoring is complete. When the
refactoring executes, it will create the new factory method, which will call the selected
constructor and return the created object. All references to the constructor will be
replaced by calls to the new factory method.
</p>
<img src="../images/ngrelr.png" alt="Related reference" border="0" > <br>
<a href="../reference/ref-menu-refactor.htm">Refactoring actions</a> <br>
<a href="../reference/ref-117.htm">Refactoring dialogs</a> <br>
<a href="../reference/ref-13.htm">Java preferences</a>
</body>
</html>