|
Extract Interface
Refactoring |
|
|
|
|
|
이 섹션은 Extract Interface 리팩토링 위에서 당신에게 포괄적인 overview와 how 이 리팩토링이 IntelliJ IDEA에서 사용될 수 있는가를 제공합니다.
두 번째 (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 옵션이 선택되면 코드를 예시하십시오:
그리고 이전의 클래스의 이름을 가지는 새롭게 생성된 인터페이스:
당신은 또 다른 인터페이스를 이미 실행하는 클래스로부터 인터페이스를 추출할 수 있습니다.
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 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 interfacevoid bar (AClass aClass){ aClass.secretMethod();}
Members
to Form Interface 패널에서, 당신이 인터페이스에 포함되기를 원하는 메소드와 필드를 선택하십시오.
|