门面图案,这样可以吗?
我有两台服务器,我将从一个客户端连接到这两台服务器。对于每个服务器,我将执行 ftp“put”和“rm”。
我应该构建一个外观,并有一个像这样的界面:
void putFileOnServer1(String file)
void putFileOnServer2(String file)
void removeFromServer1(String file)
void removeFromServer2(String file)
并且,外观应该处理所有连接的建立和断开连接吗? 如果是这样,是否应该使用工厂来这样做?
I have two servers that I will be connecting to from one client. For each server, I will be doing an ftp "put" and a "rm".
Should I build one facade, and have an interface like this:
void putFileOnServer1(String file)
void putFileOnServer2(String file)
void removeFromServer1(String file)
void removeFromServer2(String file)
And, should the facade handle all the establishing of the connections and disconnecting?
If so, should it use a factory to do so?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您有两种方法:PutFileOnServer 和RemoveFromServer。您要放置或删除的服务器应该是抽象的一部分。
You have two methods, PutFileOnServer and RemoveFromServer. Which server you are putting or removing from should be part of the abstraction.
FTP 服务器有不同的接口吗?或者他们都理解您想要使用的同一组命令吗?
如果是这样,则只需创建一个接受连接信息的
FtpServer
类。并创建一个接受多个服务器的FtpClient
类,例如您可以通过某个键进行选择。 (至少在某种程度上,这可能是我会做的事情)。如果没有,并且您已经为每个单独的实现都有一个类,它们的接口有所不同,例如:
...您应该查看适配器模式:
如果您还没有针对不同 FTP 服务器的单独类,那么您只需实现相同的接口(或继承一个抽象类)为每个 ftp 服务器实现并使用相同的FtpClient 类的类型与上面相同。
虽然这里并不真正涉及外观模式。
Do the ftp servers have different interfaces? Or do they all understand the same set of commands you want to utilize already?
If so, then simply create one
FtpServer
class that accepts connection info. And create aFtpClient
class that accepts multiple servers, that you can select by some key for instance. (At least this, to some extent, would probably be something I would do).If not, and you have a class for each individual implementation already, that differ by their interfaces, for instance like:
... you should look into the Adapter Pattern:
If you don't have individual classes for differing FTP servers yet, then you can just implement the same interface (or inherit an abstract class) for each ftp server implementation and use the same type of FtpClient class as the one above again.
Not really a facade pattern involved here though.
您通常使用外观来降低多种对象类型之间的复杂性。但在这种情况下,您似乎只想使用一种功能“类型”,即“FTPServer”。那么,在大多数情况下,您应该只有此类型的两个实例,并且此类型将具有“放置”和“删除”方法。
当你添加不必要的功能点时,实际上增加了维护的复杂性。例如,如果您需要向函数添加新参数(可能是访问限制或其他),您不仅需要针对每个使用位置进行更改,而且现在还必须添加每个外观方法。抽象应该减少这种类型的耦合,而不是增加它。
You typically use facades to decrease complexity among multiple object types. In this case, though, it appears you want to use only one functional "type", a "FTPServer". For the most part, then, you should just have two instances of this type, and this type will have a "put" and "remove" method.
When you add needless function points, you actually increase the complexity of maintenance. For instance, if you need to add a new parameter to your functions (maybe access restrictions or whatever), you not only have to change for each place of use, but now have to add in each facade method. Abstraction should reduce this type of coupling, not increase it.