复杂的实体设计
假设您有一个“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
如果我试图解决的问题是 DataPackage
和 DataPackageManager
的“尽可能简单”实现,这是否是正常设计?代码>?我目前在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如何将 DataPackage 封装成两个不同的类,一个用于数据库相关的内容,另一个用于文件相关的操作。
How about encapsulating DataPackage into two different classes, one for database related stuff and other for File related operation.