复杂的实体设计

发布于 2024-12-09 13:32:07 字数 1215 浏览 0 评论 0原文

假设您有一个“DataPackage”的概念,它实际上是一个 zip 存档。您需要实现一个系统来管理数据包,典型的场景是“导入新的”,“删除现有的”等。您无法将这些文件存储在数据库中是有原因的。

问题是 - 如何将“DataPackage”的概念划分为分别与其“数据方面”(与数据库相关的内容)和“文件系统方面”(与文件相关的内容)一起工作的类?

我正在考虑以下问题:

// data package concept
interface DataPackage {
  string GetFileName();
  DataTime GetDateTimeImported();
}

// data package manager concept
interface DataPackageManager {
  DataPackage[] GetAllDataPackages();
  DataPackage ImportDataPackage(string sourceFileName);
  void DeleteDataPackage(DataPackage dataPackage);
}

// data package database aspect
interface DataPackageData {
  int GetId();
  void SetFileName(string fileName);
  string GetFileName();
}

// data package database manager
interface DataPackageDataManager {
  DataPackageData[] GetAllDataPackagesDatas();
  DataPackageData CreateDataPackageData();
  void DeleteDataPackageData(DataPackageData data);
}

// also, similar 2 classes for DataPackage's filesystem aspect
// these would be responsible for copying files, removing files, etc

如果我试图解决的问题是 DataPackageDataPackageManager 的“尽可能简单”实现,这是否是正常设计?代码>?我目前在 DataPackage 和 DataPackageManager 中实现了所有这些内容,并思考我在这里提出的内容是否比我现有的更好。

Let's say you have a concept of "DataPackage" which is physically a zip archive. You need to implement a system to manage data packages, typical scenarios are "import new one", "remove existing", etc. There are reasons you can't store these file in the database.

The question is - how do I divide the concept of "DataPackage" into classes that work separately with its "data aspect" (DB-related stuff) and "file system aspect" (file-related stuff)?

I'm thinking of the following:

// data package concept
interface DataPackage {
  string GetFileName();
  DataTime GetDateTimeImported();
}

// data package manager concept
interface DataPackageManager {
  DataPackage[] GetAllDataPackages();
  DataPackage ImportDataPackage(string sourceFileName);
  void DeleteDataPackage(DataPackage dataPackage);
}

// data package database aspect
interface DataPackageData {
  int GetId();
  void SetFileName(string fileName);
  string GetFileName();
}

// data package database manager
interface DataPackageDataManager {
  DataPackageData[] GetAllDataPackagesDatas();
  DataPackageData CreateDataPackageData();
  void DeleteDataPackageData(DataPackageData data);
}

// also, similar 2 classes for DataPackage's filesystem aspect
// these would be responsible for copying files, removing files, etc

Is it normal design in case the problem I'm trying to solve is "as-simple-as-possible" implementations for both DataPackage and DataPackageManager? I currently have all this stuff implemented in DataPackage and DataPackageManager and thinking whether what I'm proposing here is better than what I have.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

始于初秋 2024-12-16 13:32:07

如何将 DataPackage 封装成两个不同的类,一个用于数据库相关的内容,另一个用于文件相关的操作。

DBDataPackageManager {
DataPackage dataPackage;
//get, set, remove, modify etc etc
}

FileDataPackageManager {
//file operations on DataPackage object.
}

How about encapsulating DataPackage into two different classes, one for database related stuff and other for File related operation.

DBDataPackageManager {
DataPackage dataPackage;
//get, set, remove, modify etc etc
}

FileDataPackageManager {
//file operations on DataPackage object.
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文