�޼ҵ带 ������ �����丵���� �����

 

�� ������ Make Method Static ï¿½ï¿½ï¿½ï¿½ï¿½ä¸µ ������  overview�� �����ϰ� how �� �����丵�� IntelliJ IDEA���� ���� �� �ִ°��� �����մϴ�.

����


Make Method Static �����丵�� �� �޼ҵ带 �ٸ� Ŭ������ �̵��ϴ�Move Members �����丵�� ���� ������ �ܰ� �Ӹ��ƴ϶� Ŭ���� �ν��Ͻ��� �������� �ʰ� �� �޼ҵ带 ������ ������� ����� ���� �������� �޼ҵ带 ������ ������ ��ȯ�ϴµ� ���ȴ�. Ÿ�� �޼ҵ尡 �������� ����� �����丵 ����, �׸��� ��� ���� �ִٸ� Ŭ�����κ��� �ʿ��� �Ű� ������ �߰��� ���Դϴ�.


���� ���, ���� �ڵ尡 �����丵 ������ �ֽ��ϴ�.  ï¿½ï¿½ï¿½ï¿½ï¿½ �� ���� Ŭ������ �����ϴ�:

 
public class ConnectionPool{
    HashMap mPool;
 
    Connection getConnection(String name){
        return (Connection) mPool.get(name);
    }
}
 
public class Processor{
    ConnectionPool myCP;
 
    void detach(String name){
        myCP.getConnection(name).abortConnection();
    }
}

 

�׸��� �װ��� getConnection ï¿½Þ¼Òµå¸¦ �������� ����⿡ �����ϴ�.  ï¿½ï¿½ï¿½ï¿½ï¿½ ���ÿ� ����, �����丵�� ���� �� ���� ��� ���� �� ���� ���� ���� �� �ֽ��ϴ�:


���� ����� Ŭ���� �ν��Ͻ��� �����ϴ� �Ű� ������ �ʿ�� �ϸ�:

 
public class ConnectionPool{
    HashMap mPool;
 
    static Connection getConnection(ConnectionPool connectionPool, String name){
        return (Connection) connectionPool.mPool.get(name);
    }
}
 
public class Processor{
    ConnectionPool myCP;
 
    void detach(String name){
        ConnectionPool.getConnection(myCP, name).abortConnection();
    }
}


�Ǵ� ����� �Ű� �����μ� �� ������ �ʵ带 ����ϰ� �;��Ѵٸ�:

 
public class ConnectionPool{
    HashMap mPool;
 
    static Connection getConnection(HashMap mPool1, String name){
        return (Connection) mPool1.get(name);
    }
}
 
public class Processor{
    ConnectionPool myCP;
 
    void detach(String name){
        ConnectionPool.getConnection(myCP.mPool, name).abortConnection();
    }
}

 

�޼ҵ带 �������� �����


�޼ҵ带 �������� ����� ����, ù ��°�� ij���� ���� ���� ������ �Ǵ� ����� �������� �DZ⸦ ���ϴ� �޼ҵ��� ���� �����Ͻʽÿ�.



���� �޴����� �Ǵ� �����Ϳ��� ������ ��ư�� Ŭ���ϴ� �Ϳ� ���� �ҷ����� �˾� �޴����� Refactor Make Method Static...  ï¿½ï¿½ Ŭ���Ͻʽÿ�.

���� �޼ҵ尡 � Ŭ���� ���� ��Ҹ� ����ϸ� ������ Introduce Parameter ï¿½ï¿½ï¿½Ì¾ï¿½Î±×°ï¿½ ��Ÿ���ϴ�:



���̾�α״� ������ ��� �����ϴ�:

�̸��� �ִ� �Ű� �����μ��� ��ü �߰�


���� üũ�ϸ�, �޼ҵ� ����� �ݷ� �Ű� �����μ��� Ŭ���� �ν��Ͻ��� �߰��մϴ�.


���� Ÿ�� �޼ҵ尡 �� Ŭ������ �� ������ �޼ҵ带 ����ϸ� �� üũ �ڽ��� �ڵ������� ���õ˴ϴ�.  ï¿½ï¿½ï¿½ï¿½ ����� �׷� �� ������ �޼ҵ带 ���� üũ �ڽ��� �����ϸ� Problems Detected ï¿½ï¿½ï¿½Ì¾ï¿½Î±×¿ï¿½ �Բ� ��� �ް� �� �� �Դϴ�. ���� ����� �װ��� �����ϰ� Continue�� ������ �����丵�� ����� ���̳� ��� �ڵ�� �������� �ȵ����� �𸨴ϴ�.

�ʵ忡 ���� �Ű� ���� �߰�

���� üũ�ϸ� �޼ҵ忡 ���� ���Ǵ� �ʵ��� ����� ��� �����ϰ� �մϴ�.  ï¿½ï¿½Ï¿ï¿½ï¿½ï¿½ ����� �޼ҵ忡 �� �����μ� �Ѿ�� �� ������ �ʵ带 �޼ҵ� ����/�ݿ��� �ʵ��� ������ �����ϴ� Move Up  / Move down ï¿½ï¿½Æ°ï¿½ï¿½ ����Ͽ� �����ϰų�/�������� ���� �� �ֽ��ϴ�.


���� Ÿ�� �޼ҵ尡 �� Ŭ������ �� ������ �ʵ带 ����ϸ� �� üũ �ڽ��� �ڵ������� ���õ˴ϴ�.  ï¿½ï¿½ï¿½ï¿½ ����� �׷� �� ������ �ʵ带 ���� üũ �ڽ��� �����ϸ� �����丵�� ����� ���̳� ��� �ڵ�� �������� �ȵ����� �𸨴ϴ�.


���� ����� Ÿ�� �޼ҵ忡 ���� ����ϴ� �� ������ �ʵ带 ���� �����ϸ�  Problems Detected ï¿½ï¿½ï¿½Ì¾ï¿½Î±×¿ï¿½ �Բ� ��� �ް� �� �� �Դϴ�. ���� ����� �װ��� �����ϰ� Continue�� ������ �����丵�� ����� ���̳� ��� �ڵ�� �������� �ȵ����� �𸨴ϴ�.

����� �̸� ���� ���

�� üũ �ڽ��� �����ϸ� ����� � ����� �߰ߵǾ����� �����ϰ�, �׵��� ��ü�� �����ϵ��� ����մϴ�.  ï¿½ï¿½ üũ �ڽ��� ���õ��� ���� ��, IDEA�� ��ü�� �ڵ������� �����մϴ�.


������ üũ �ڽ��� ���õ��� �ʾ��� ����, ���� �߰ߵ� ����� � �б� ���� ���Ͽ��� �����ϸ� ����� ��� ��ü�� Ȯ���ϴ� ������Ʈ�� ��ſ� ���� �� �Դϴ�.


���� Ŭ���� ���� ����� ��� �͵� Ÿ�� �޼ҵ忡 ���� ������ ������, Make Method Static ï¿½ï¿½ ������ ���� ���� ���Դϴ�:



�װ��� �� üũ �ڽ��� �����ϴ�:

Replace usage  qualifiers with class references  

���� üũ�Ǹ�, Ŭ���� �̸��� �Բ� Ŭ���� ��� ���ľ ��ü�մϴ�.

Preview usages  to be changed  

���� ï¿½ï¿½ï¿½Ê½Ã¿ï¿½.

 

���ۿ�


Make Method Static �����丵�� �����ϸ� ����� ������ ���ۿ��� �˰� �־�߸� �մϴ�. ���� ���μ��� Ŭ����������� ����� ������ �ڵ带 �����ϴ�:

 
public class Processor{
    void detach(String name){
        ArrayList connectionPools = new ArrayList();
 
        for (Iterator iterator = connectionPools.iterator(); iterator.hasNext();) {
            ((ConnectionPool) iterator.next()).getConnection(name).abortConnection();
        }
    }
}

 

�����丵 �Ŀ� �ڵ尡 �ֽ��ϴ�

 
public class Processor{
    void detach(String name){
        ArrayList connectionPools = new ArrayList();
 
        for (Iterator iterator = connectionPools.iterator(); iterator.hasNext();) {
            ConnectionPool.getConnection(((ConnectionPool) iterator.next()).aInt,
                                         ((ConnectionPool) iterator.next()).mPool, name).abortConnection();
        }
    }
}

 

����� �� �� �ִ� �Ϳ� ����, iterator �� ������ �߸��� �ʵ��� ������ ���� �� ��� �þ�ϴ�.  ï¿½×·ï¿½ï¿½ï¿½, IDEA�� ����/����/���� ��������� �׷� ��츦 �ӽ� ������ ����ϰ� new Ű���带 ����Ͽ� ���������� ������ �ذ��� �� �ֽ��ϴ�.


���� ���

 
public class Processor{
    void detach(String name){
        new ConnectionPool().getConnection(name).abortConnection();
    }
}

 

�׸��� ���⿡ �����丵 ���� �ڵ尡 �ֽ��ϴ�.

 
public class Processor{
    void detach(String name){
        final ConnectionPool connectionPool = new ConnectionPool();
        ConnectionPool.getConnection(connectionPool.aInt, connectionPool.mPool, name).abortConnection();
    }
}


�ӽ� ������ �� ������ �ʵ忡 ���� ConnectionPool Ŭ������ �� ���� �ٸ� �ν��Ͻ��� ������ ���ϱ� ���� �����˴ϴ�