최종 사용자가 OAuth2 소비자 키와 소비자 비밀 값을 사용하는 속성 파일을 처리하는 클래스가 있습니다.값이 다를 필요가 있지만 메서드가 아닌 메서드에서 코드 복제
이 클래스에서나는이 같은 방법을 가지고 :
// Get the consumer key or secret value
public String getConsumerKeyOrSecret(String keyOrSecret)
{
String value = properties.getProperty(keyOrSecret);
if (value == null || value.isEmpty())
{
value = null;
}
return value;
}
이이를 구현하는 가장 좋은 방법이 있나요? 제 생각에는 다른 클래스에서이 값을 얻을 수있는 더 편리한 방법은 다음과 같이 구현 두 개의 당신이 필요로하는 주요 방법과 방법을 호출하는 것입니다 :
public String getConsumerKey()
{
String consumerKey = properties.getProperty("consumer_key");
if (consumerKey == null || consumerKey.isEmpty())
{
consumerKey = null;
}
return consumerKey;
}
public String getConsumerSecret()
{
String consumerSecret = properties.getProperty("consumer_secret");
if (consumerSecret == null || consumerSecret.isEmpty())
{
consumerSecret = null;
}
return consumerSecret;
}
을하지만 이것은 코드 중복으로 간주되지 않을 것이다? 이것을 접근하는 가장 좋은 방법은 무엇입니까?
이 유형의 검사 (예 :'== null '등)를 수행하는 개인 메소드를 작성한 후 진행하기 전에이 검사가 필요한 다른 모든 장소에서 개인 메소드를 호출하십시오. – ochi