API와 구현의 두 가지 구성 요소로 기능을 분할해야합니다. 첫 번째 인터페이스는 인터페이스를 포함하고 두 번째 인터페이스는 구현을 포함합니다. 웹 응용 프로그램 컨트롤러에 인터페이스를 전달하고 Spring 또는 다른 Dependency Injection 프레임 워크를 통해 구현을 주입합니다. 예를 컴포넌트로 구현에서 웹 응용 프로그램을 분리하는 인터페이스를 정의
@Component
public class UserController {
private FileManager fileManager;
@Autowired
public UserController(FileManager fileManager) {
this.fileManager = fileManager;
}
@GET("/user/{userId}/file/{fileId}")
public File getUserFile(long userId, long fileId) {
fileManager.getUserFile(userId, fileId);
}
}
파일 MGT-API를 클라이언트와 대리인의 요청을 처리
웹 응용 프로그램, UserController를 들어
public interface FileManager {
File getUserFile(long userId, long fileId);
}
file-mgt-impl 여기서 요청 된 파일을 얻는 방법에 대한 모든 세부 정보
@Component
public class FileManagerImpl implements FileManager {
@Override
public File getUserFile(long userId, long fileId) {
// get file by id from DB
// verify that provided user is the file owner
// do other useful stuff
// return the file or throw exception if something wrong
}
}
그룹, 프로필 관리 및 기타 기능에 대해 동일한 작업을 수행하십시오. 그 후에는 단일 jar 파일을 대체하여 구현을 쉽게 바꿀 수 있습니다. 귀하의 웹 응용 프로그램은 완벽하게 분리되어 구현 세부 사항에 대해 아무것도 모릅니다. 인터페이스에만 의존합니다.
유용한 답변을 찾았습니까? 당신은 [답변 수락] (http://stackoverflow.com/help/someone-answers) 또는/및 [vote it up] (http://stackoverflow.com/help/why-vote)하실 수 있습니다. – retroq