Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
Это был пример нетривиального, многошагового рефакторинга.
public static MyRequest createPostRequest() {
return createRequest("POST");
}
public static MyRequest createGetRequest() {
return createRequest("Get");
}
private static MyRequest createRequest(String method) {
MyRequest request = new MyRequest();
request.setMethod(method);
request.setContentType("application/x-www-form-urlencoded");
return request;
}public class MyServerException extends RuntimeException {
// ...
}
public interface PhotoInfo {
// ...
}
public interface MyServerSession {
void login(String username, char[] password) throws MyServerException;
boolean isLoggedIn();
List<PhotoInfo> getUserPhotos(int userId) throws MyServerException;
void uploadPhoto(Bitmap photo, int userId) throws MyServerException;
}
class MyServerSessionImpl implements MyServerSession {
MyServerSessionImpl(String serverUrl) {
}
// ...
}
Основы борьбы с неявным дублированием кода