Introduce Field Refactoring  

 

�� ������ Introduce Field ï¿½ï¿½ï¿½ï¿½ï¿½ä¸µ ������ ��ſ��� ��������  overview�� �����ϰ�  how  �� �����丵�� IntelliJ IDEA���� ���� �� �ִ°��� �����մϴ�.

����


Introduce Field ï¿½ï¿½ï¿½ï¿½ï¿½ä¸µï¿½ï¿½ ���ο� �ʵ带 �����ϰ�, ���õ� ǥ���İ� �Բ� �װ��� �ʱ�ȭ�մϴ�.  ï¿½ï¿½ï¿½ï¿½ ǥ������ �ʵ��� ������� ��ü�˴ϴ�.


���� ���, �����丵 ���� �Ϻ� �ڵ尡 ���⿡ �ֽ��ϴ�:

 
    public class MyApplet extends JApplet {
 
        public void init() {
            Container cp = getContentPane();
            cp.setLayout(new FlowLayout());
            cp.add(new Button("Button"));
        }
    }


�츮�� Introduce Field �����丵�� �����ϱ� ���� ���ο� ��ư ("Button")�� �����մϴ�.

���� �츮�� ������ �ڵ带 �����ϴ�:

 
    public class MyApplet extends JApplet {
        private JButton button = new JButton("Button");
 
        public void init() {
            Container cp = getContentPane();
            cp.setLayout(new FlowLayout());
            cp.add(button);
        }
    }

 

�ʵ� �����ϱ�


�ʵ带 �����ϱ� ����, �����Ϳ��� ���ο� �ʵ忡 �Ҵ�� ǥ������ �����Ͻʽÿ�.




Introduce Field �����丵�� ���� ǥ������ �����ϱ� ���� Ctrl + W  (�ܾ� ����)�� ����ϴ� ���� ���� �����մϴ�.

�ڵ��� ���� Ȯ���� �����ϰ� ����� ij���� ������ ��� ���� ��ġ�ϰ�, Ctrl + W�� �� �� ������ � ǥ�����̶� ���� �ڵ忡�� �����ص� �����ϴ�:


�� �޴����� �Ǵ� �����Ϳ��� ������ ��ư�� Ŭ���Ͽ� �ҷ����� �˾� �޴����� Refactor Introduce Field...  ï¿½×¸ï¿½ï¿½ï¿½ Ŭ�� �Ͻʽÿ�.

������ Introduce Field ï¿½ï¿½ï¿½Ì¾ï¿½Î±×°ï¿½ ��Ÿ���ϴ�:



Introduce Field ï¿½ï¿½ï¿½Ì¾ï¿½Î±ï¿½ï¿½ï¿½ �ֻ�������, ���� �ʵ��� Ÿ���� ǥ�õ˴ϴ�.

Name �ؽ�Ʈ �ʵ忡�� ����� �ʵ忡 �̸��� �Է½�ų �� �ְų�, IDEA�� ���� ���ȵ� �ϳ��� ����� �� �ֽ��ϴ�.  Æ¯ï¿½ï¿½ ���ȵ� �̸��� �� Ÿ�� ������ ���õ� ǥ���Ŀ� �����մϴ�.

���� ����� ï¿½Úµï¿½ ��Ÿ�� �ɼ� ï¿½ï¿½ï¿½ï¿½ �ʵ带 ���� �̸� �ĺ� ��ȣ�� �����ߴ���� ���ȵ� �ʵ� �̸��� �����ϴ� ���� IDEA�� ���� ���� ���Դϴ�.


���� ���õ� ǥ������ ���� �߻��� ������, �׵� ��δ� �����Ϳ��� ������ ���Դϴ�. �׸��� Replace all occurrences of expression (  <number of occurrences found>  ) üũ�ڽ��� ���̾�α� �������� �ٴڿ��� ��Ÿ�� �� �Դϴ�. ���� üũ�ڽ��� ���õǸ�, ���õ� ǥ������ ��� �߻��� ��ü�� �� �Դϴ�. �׷��� ������ ������ ����� �� ������ ǥ���ĸ��� ����� �� �Դϴ�.

 


���̾�α״� 3���� �ɼ� �׷��� �����ϴ�:

�ʱ�ȭ

�ʵ尡 �ʱ�ȭ�� ���� �����մϴ�:

 Current method - �ʵ�� ���õ� ǥ���Ŀ� �ռ� �޼ҵ� ������ ��� �ʱ�ȭ�˴ϴ�.
 
Field declaration - �ʵ�� �ٸ� �ʵ�� �Բ� �ʱ�ȭ�˴ϴ�.
 
Class constructor - �ʵ�� Ŭ���� �����ڿ��� �ʱ�ȭ�˴ϴ�.

���ü�

�ʵ带 ���� ���ü� ������ �����մϴ�:

 Private  
 
Package local  
 
Protected  
 
Public  

�ٸ� ������

�ʵ带 ���� �������� �����մϴ�:

 Final  


 


���� �ʵ尡 ������ �޼ҵ�� �ʱ�ȭ�Ǹ� final üũ �ڽ��� �Ұ����ϰ� �ϰ� �˴ϴ�.


���� ���õ� �ڵ尡 ��ȿ�� ǥ������ ǥ������ ������ ��ſ��� ������ ���� �޽����� ������Ʈ �� ���Դϴ�: