�� ������ Extract Interface �����丵 ������ ��ſ��� �������� overview�� how �� �����丵�� IntelliJ IDEA���� ���� �� �ִ°��� �����մϴ�.
Extract Interface �����丵�� ���Ҿ� ����� �� �ɼ��� �����ϴ�. ù ��°(Extract Interface) �� Ŭ������ �޼ҵ带 ���ʷ� �ϴ� �������̽��� �����ϵ��� ����մϴ�.
�� ��° (Rename
original class and use interface where possible) �� ������ Ŭ������ �̸��� �����ϰ� ���Ӱ� ������ �������̽��� �����մϴ�. �׷� ���, �����ϸ� IDEA�� �׶� �������̽��� ����ϱ� ���� ��� ������ Ŭ���� ����� �ٲߴϴ� (�׸��� �װ��� ���� ���� ������ �װ͵��� �������� ���� ���Դϴ�).
����, ������ Ŭ�������� ����� ������ �������� �ʵ�� �������̽��� �̵��� �� �ֽ��ϴ�. �� ���, �������̽��� Ư���� �޼ҵ�� �ʵ带 ï¿½ï¿½ï¿½ï¿½ï¿½Ï¸é¼ ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ ���Դϴ�. �� ������, ���ǵ� Ŭ���� �޼ҵ�� �����ϴ� �������̽� �޼ҵ��� ������ �˴ϴ�.
Extract Interface �ɼ��� ���� ���� �ڵ�:
�츮�� ������ Ŭ������ �����ϴ�:
class AClass { public static final double CONSTANT=3.14; public void publicMethod() {//some code here} public void secretMethod() {//some code here} }
�����丵 ����, ���ο� �������̽��� ������ ���Դϴ�:
public interface AnInterface { double CONSTANT=3.14; void publicMethod(); }
�ҽ� Ŭ������ �������̽��� ������ ���Դϴ�:
class AClass implements AnInterface { public void publicMethod() {//some code here} public void secretMethod() {//some code here} }
���� Rename
original class and use interface where possible �ɼ��� ���õǸ� �ڵ带 �����Ͻʽÿ�:
public class FormerAClass implements AClass {
public void publicMethod() {//some code here }
public void secretMethod() {//some code here}
}
�׸��� ������ Ŭ������ �̸��� ������ ���Ӱ� ������ �������̽�:
public interface AClass {
double CONSTANT=3.14;
void publicMethod();
}
����� �� �ٸ� �������̽��� �̹� �����ϴ� Ŭ�����κ��� �������̽��� ������ �� �ֽ��ϴ�. AnInterface �� �����ϴ� Ŭ�����κ��� extract
interface�� �մϴ� . �츮�� AnotherInterface( ����� �޼ҵ� ) �� AnInterface (������ ��)�� Ȯ��DZ⸦ ���ϴ��� �Ǵ� �׵��� ������ �ҽ� AClass �� �츮�� ���ϴ��� �� ���� �츮�� ������ �ڵ带 ��� �� ���Դϴ�.
Extracted Interface extends the existing one Source
class:
class AClass implements AnotherInterface { public void publicMethod() { //some code here } public void secretMethod() { //some code here } }
Extracted
Interface:
public interface AnotherInterface extends AnInterface { }
Source
class implements both interfaces
Source class:
class AClass implements AnInterface, AnotherInterface { public void publicMethod() { //some code here } public void secretMethod() { //some code here } }
Extracted
Interface:
public interface AnotherInterface { }
�������̽��� ����Ǿ������, IDEA�� Ŭ������ ����� �˻��ϰ�, �������̽��� ������� �׵��� �����ϸ� ��ü�� ���� ������ ���Դϴ�. ����� IDEA�� �� ������ �ڵ������� �����ϰ� �� �� �ְų�, ����� �߰ߵǰ�, �׵��� ��ü�� �����ϴ� ���� ������ ��� ���� �� �ֽ��ϴ�.
���� �ڵ�:
class AClass implements AnInterface { public void publicMethod() {//some code here} public void secretMethod() {//some code here} } ... ... //This usage can be modified by changing the //parameter type from 'AClass' to 'AnInterface' void foo (AClass aClass){ aClass.publicMethod(); } ...
...
//This usage will not be suggested for //refactoring because it is not specified in the interface void bar (AClass aClass){ aClass.secretMethod(); }
�������̽� ����
|
Ŭ�����κ��� �������̽��� �����ϱ� ���� ������ �մϴ�:
1. Project ���⿡�� Ŭ������ �����ϰų� ���� �����⿡�� Ŭ���� ������ ij���� ��� ���� ��ġ�Ͻʽÿ�, �׸��� Extract
Interface �� �˾� �޴��κ��� �Ǵ� Refactor �޴��κ��� �����ʽÿ�.

|
����� ���� Ŭ������ Structure, Commander, Source ��� ���� �ٸ� ���⿡�� ���� �� �ֽ��ϴ�.
|
2. �� �Ŀ�, ���� ������� �����丵 �Ű� ������ �����ϱ� ���� ��Ÿ�� ���Դϴ�:

ù ��°��, �� �ɼ�(Extract Interface �Ǵ� Rename
original class and use interface where possible ) ��ư ���� �� ���� �����Ͻʽÿ�. �׸��� ���� Interface name �Ǵ� Rename
original class to �ؽ�Ʈ �ʵ忡�� �������̽��� ���� �̸� �Ǵ� ���� Ŭ������ ���� ���ο� �̸��� �����Ͻʽÿ�.
Members
to Form Interface �гο���, ����� �������̽��� ���ԵDZ⸦ ���ϴ� �޼ҵ�� �ʵ带 �����Ͻʽÿ�.

|
����� Ŭ������ �� �ٸ� �������̽��� �̹� �����߽��ϴ�. �� ���, �� �������̽��� Members
to Form Interface ��Ͽ��� ��Ÿ�� ���Դϴ�. ���� ����� ������ �������̽��� ���� �ϳ��� Ȯ���ϱ⸦ ���ϸ�, ����� ��Ͽ��� �װ��� �����ؾ߸� �մϴ�. ���� �׷��� �ʴٸ�, �� �������̽��� ���õ��� �ʰ� �Ͻʽÿ�. �׷��� Ŭ������ �����ϰ� ���� �������̽��� ������ ���Դϴ�.
|
JavaDoc �׷쿡��, ���ο� �������̽��� ������ �� Javadoc�� �ٷ�����߸� �ϴ� �ɼ� ��ư�� �����Ͻʽÿ�.
As is
|
???
|
Copy
|
???
|
Move
|
???
|
|
3. OK �� Ŭ���Ͻʽÿ�, �׸��� ���ο� �������̽��� ������ ���Դϴ�.
4. �� ��, ���� ����� Extract Interface �ɼ� ��ư�� �����ϸ�, ���� �����찡 ��Ÿ�� ���Դϴ�:

���� ����� IDEA�� Ŭ������ ����� �м��ϰ�, �����ϸ� �������̽��� ������� �׵��� ��ü�ϱ� �ٶ��, Yes �� Ŭ���Ͻʽÿ�, �׷��� �ʴٸ� No�� Ŭ���Ͻʽÿ�. ���� ���� �̸� ���⸦ ���ʽÿ�.
Preview usages to be changed üũ �ڽ��� üũ�ϸ� ��ſ��� ����� �߰ߵǰ�, �׵��� ��ü�� �����ϴ� ������ ��� ��� ���� ����մϴ�. üũ���� ���� ��, IDEA�� ��ü�� �ڵ������� �����մϴ�.

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