我很好奇什么才是在以下实现中使用的最佳设计模式:我创建了一个小型应用程序,用于从网站下载图像并将其设置为我的背景。如何从业务逻辑中分离远程数据访问(通过http)逻辑?
我想与网站进行接口以下载XML Background.xml
文件,并下载另一个文件(Background.bmp
),该文件位于此远程服务器上。该文件是位图,XML是关于位图的元数据。我下载文件后,我想将其设置为我的背景。我想从背景设置代码中分离出文件下载代码,但我不确定我会使用哪种设计模式。
这似乎是一个典型的演示/数据/业务应用程序,其中Form是表示层,背景设置器/ XML分析器是业务层,下载器是数据层。但我不确定哪种设计模式可用于实际数据访问,因为它来自网站而不是数据库(所以DAO可能不适合这样做)。我也购买了Wikipedia的设计模式,但没有什么看起来不错。这是我可以使用MVC的东西吗?
数据层
public class DataLayer {
public void DownloadFile() {
// download the file from http
}
public void GetXmlMetaData() { }
}
业务层
public class BusinessLayer {
private static BusinessLayer m_instance = new BusinessLayer();
public static Instance BusinessLayer { get { return m_instance; }
private BusinessLayer() { }
public void SetNewWallpaper() {
// download the file from data layer
// set it as the background
}
public String GetWallpaperInfo() { return String.Empty; }
}
表示层
public class PresentationLayer {
public void HandleButtonClick(Object sender, EventArgs e) {
BusinessLayer.Instance.SetNewWallpaper();
}
}
何我会将数据访问部分与背景设置逻辑分开吗?