开发者

FTP Design Pattern

I'm working on a project that needs to use multiple types of FTP connections (SFTP, FTPS, and regular old FTP currently). I'm using JSch for SFTP and Commons Net for FTPS and FTP.

The problem I'm running into deciding how to implement this in a way that will prevent other people from having to know about the libraries and also make updating and maintenance easy. Currently I have an FTP interface and classes that implement that for each type of connection. I can't shake the feeling that there must be a better way since this seems to just add a step between the production code an开发者_运维百科d the library.

Are there any design patterns that might suit this implementation better?


The way to go is indeed having a common interface for all of them, as well as adapters that implement it for each of the libraries.

Having a common interface you may be able to set the dependency from outside (read about dependency injection), and/or implement a factory that for some generic specification returns the right implementation.


Have you read this piece on Dependency Injection? http://martinfowler.com/articles/injection.html


Bridge Design Pattern is what you're after.

Since it's java, pay attention to this very flexible and scalable mechanism: META-INF/services

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜