�� ������ Introduce Parameter
�����丵 ������ overview�� �����ϰ� how �� �����丵�� IntelliJ
IDEA���� ���� �� �ִ°��� �����մϴ�.
���� ����� �޼ҵ� �ݿ��� �Ѿ�� �Ϻ� ���� �ʿ�� �ϸ� Introduce
Parameter �����丵�� �Ű� ������ �޼ҵ� ���� �߰��ϱ� ���� ���˴ϴ�. �޼ҵ� ����� ���� ����˴ϴ�. �Ű� ������ ������ �޼��� �ñ׳��� ����
�����丵(������ ������Ʈ��Ʈ�� �ܼ��� �ؽ�Ʈ�μ� ���Ե� ��)�� ���� �ʰ� �ذ�˴ϴ�.
���� ���, �����丵 ���� ���� �ڵ尡 �ֽ��ϴ�:
public int myMethod(int aParam) {
return aParam + (aParam + 1);
}
public void anotherMethod() {
myMethod(5);
}
�׸��� ����� �� �ٸ� �Ű� ������ (aParam + 1) ǥ���� ��ſ� myMethod �� �����ϴ� ���� �����߽��ϴ�. �����丵 ���� ����� ���� �ڵ带 ���� ���Դϴ�:
public int myMethod(int aParam, int newParam) {
return aParam + newParam;
}
public void anotherMethod() {
myMethod(5, (5 + 1));
}
���ο� �� ���� newParam �� �����Ǿ��� �޼ҵ� �ݿ��� �� ���� ���� �ʱ�È�Ǿ����ϴ�.
�� ���� ����
|
�Ű� ������ �����ϱ� ����, �����Ϳ��� �Ű� ������ ��ü�� ǥ������ �����Ͻʽÿ�.


|
Introduce Parameter �����丵�� ������ ǥ������ �����ϱ� ���� Ctrl +
W (�ܾ� ����)�� ����ϴ� ���� ���� �����մϴ�. �ڵ��� ���� Ȯ���� �����ϰ� ����� ij���� ������ ��� ���� ��ġ�ϰ�, Ctrl +
W�� �� �� ������ � ǥ�����̶� ���� �ڵ忡�� �����ص� �����ϴ�.
|
���� �޴����� �Ǵ� �����Ϳ��� ������ ��ư�� Ŭ���Ͽ� �ҷ����� �˾� �޴����� Refactor
| Introduce
Parameter... �� Ŭ���մϴ�. �Ǵ� Ctrl + Alt + P ����Ű�� ����մϴ�.

|
���� ���� ������ �����丵�� �����ϸé¼, ����� ������ �װ� ������ ij���� ��ġ�� �� �ֽ��ϴ�. �׷��� �ʵ� ������ �����丵�� �����ϱ� ����, �ʵ尡 �����Ϳ��� ���õǾ�߸� �Ѵٶ�� ���� �����Ͻʽÿ�.
|
���� Introduce
Parameter ���̾�α��� ��Ÿ���ϴ�:

���̾�α״� ������ ��� �����ϴ�:
Parameter of type
|
������ �Ű� ������ ���� Ÿ���� �����Ͻʽÿ�.
|
Name
|
������ �Ű� ������ ���� �̸��� Ÿ�����ϰų�, IDEA�� ���� ���ȵ� �ϳ��� ����մϴ�.
|
Declare final
|
���� ���õǸ�, ������ �Ű� ������ ���������� ����˴ϴ�.
|
Preview usages to
be changed
|
�� üũ �ڽ��� �����ϸ� ����� � ����� �߰ߵǾ����� �����ϰ�, �׵��� ��ü�� �����ϵ��� ����մϴ�. �� üũ �ڽ��� ���õ��� ���� ��, IDEA�� ��ü�� �ڵ������� �����մϴ�.

|
������ üũ �ڽ��� ���õ��� �ʾ��� ����, ���� �߰ߵ� ����� � �б� ���� ���Ͽ��� �����ϸ� ����� ��� ��ü�� Ȯ���ϴ� ������Ʈ�� ��ſ� ���� �� �Դϴ�.
|
|
|
�����丵�� �����ϱ� ���� Enter�� �����ʽÿ�.
Ư���� ����
|
���� Ư���� �̽��� ��޵Ǿ�߸� �մϴ�:
���� �ʵ尡 �޼ҵ� ���𿡼� ���ο� �Ű� �����μ� �����DZ⸦ ���ϸ�, �޼ҵ� �ݿ��� �� �ʵ�� Ŭ���� �ν��Ͻ��� �ʵ�μ� ������ ���Դϴ�.
���� ������ ����ϰ� �ִ� �ʵ带 �߰��մϴ�:
public class AClass {
public int myField;
public int myMethod(int aParam) {
return aParam + (myField + 1);
}
}
public class AnotherClass {
AClass aClass = new AClass();
public void anotherMethod() {
aClass.myMethod(5);
}
}
�����丵 ���� ����� ������ �ڵ带 ���� ���Դϴ�:
public class AClass {
public int myField;
public int myMethod(int aParam, int newParam) {
return aParam + newParam;
}
}
public class AnotherClass {
AClass aClass = new AClass();
public void anotherMethod() {
aClass.myMethod(5, (aClass.myField + 1));
}
}
���� Ŭ���� ���� ��Ұ� �����ϱ� ������(���� ���, ���� �������� �ʵ�� private�Դϴ�), �װ��� �޼ҵ� �ݿ� ���Ե� ���Դϴ�. �׷��� �� ������ ������ �ȵǰ� ����� �����μ� ������ ���Դϴ�.
���� ����� ���Ϳ� �Բ� Introduce
Parameter �����丵�� ���� �ʵ带 ����ϸ�, ��ſ��� Ȯ��� ���̾�α׷� ������Ʈ�� ���Դϴ�:

���̾�α״� �ɼ� �׷� Replace
fields used in expressions with their getters�� �����ϴ�:
Do not
replace
|
�ʵ��� ��� �͵� ���Ϳ� �ݷ� ��ü���� ���� ���Դϴ�.
|
Replace
fields inaccessible in usage context
|
��� �������κ��� ���� �׼����� �� ���� �ʵ常�� ���Ϳ� �ݷ� ��ü�� ���Դϴ�.
|
Replace all
fields
|
��� �ʵ�� ���Ϳ� �ݷ� ��ü�� ���Դϴ�.
|
|
���� ���� ������ �����丵�� �����ϸ� �� ���� �ΰ��� üũ �ڽ��� �Բ� Introduce
Parameter ���̾�α׸� �θ� ���Դϴ�. ���� ���, ����� ������ �ڵ带 �����ϴ�:
public int myMethod(int firstPar) {
int secondPar = firstPar + 1;
return firstPar + secondPar;
}
�׸��� ����� secondPar ������ �����ϰ� �ִ� Introduce
Parameter �����丵�� �����մϴ� .
����� ������ ���̾�α� �������� �� ���Դϴ�:

Replace all occurrences
(<number_of_occurences> occurrences)
|
�����ϸ�, ���õ� ������ ��� �߻��� �Ű� ������ ��ü�� ���Դϴ�. �׸��� Delete
variable üũ �ڽ��� ��� �����ϰ� �ϰ� �˴ϴ�.
�׷��� ������, ������ ���õ� ���� ����� �Ű� ������ ��ü�� ���Դϴ�.

|
������ ���õ� ������ �� �̻��� �� ���� �߻��� ���� ��쿡 �� üũ �ڽ��� ��Ÿ���ϴ�.
|
|
Delete
variable definition
|
�����ϸ�, ���� ���Ǵ� ������ ���Դϴ�.
|
Use variable initializer
to initialize parameter
|
�����ϸ�, ���� �̴ϼȶ������� �޼ҵ� �ݿ��� �� ������ �ʱ�È�ϱ� ���� ���� ���Դϴ�.
|
|
Enter�� ������ �����丵�� ������ ���Դϴ�.
|
���� ���� �޼ҵ� �Ű� ������ Ŭ���� �ν��Ͻ� �Ǵ� ǥ���� ������ ����ȴٸ�, Introduce Parameter �����丵�� ����ϴ� ���� ������� ���ۿ��� ���� �� �ֽ��ϴ�. ���� ���, �׷� �ڵ��� ��쿡��:
class AClass {
int field;
int method() {
return field;
}
}
class Usage {
void method(List list) {
int sum = 0;
for(Iterator it = list.iterator(); it.hasNext(); ) {
sum += ((AClass) it.next()).method();
}
}
}
�׸��� field �ʵ带 ���� ����� �����丵 ���� �ڵ�:
class AClass {
int field;
int method(int newfield) {
return newfield;
}
}
class Usage {
void method(List list) {
int sum = 0;
for(Iterator it = list.iterator; it.hasNext(); ) {
sum += ((AClass) it.next()).method(((AClass) it.next()).field);
}
}
�ݺ� ���� ������ ����� �����ߴ� ������ �ƴ� �� ��� �����˴ϴ�
�׷���, IDEA�� �Ͻ��� ������ ���������� ����� �� �ְ�, ����/����/���� ����� new Ű���� ���� ���� ��츦 �ذ��� �� �ֽ��ϴ�.
���� ���:
public int myMethod(List list) {
return list.size();
}
public void anotherMethod() {
myMethod(new ArrayList());
}
�׸��� �����丵 ���� �ڵ�:
public int myMethod(List list, int newPar) {
return list.size();
}
public void anotherMethod() {
final ArrayList list = new ArrayList();
myMethod(list, list.size());
}
���ο� ���� list �� �����ǰ� �޼ҵ� ���� ���� ���Ǵ� ��� �� ������ �� ������ ï¿½ï¿½ï¿½ï¿½Ï¸é¼ ï¿½ï¿½ï¿½ï¿½ï¿½Ë´Ï´ï¿½.
|