我正在创建一个用于管理商店的应用程序。我需要管理与每个产品相关的以下数据:名称、购买成本和销售价格(这取决于哪个零售商在销售产品)。在下图中,我在表格中表示了需要保存和管理的数据。

我知道,随着时间的推移,那些使用该应用程序的人将需要输入新产品和新的“价格组”(“销售价格…”表的列)。
我使用的是一种面向对象语言(Dart)。组织代码的最佳方式是什么?我应该创建什么类?
如果你需要更多的细节,请让我知道。非常感谢!
发布于 2021-03-09 15:36:21
您可能只需要一个类Product
class Product {
final String name;
final double cost; // Or int
final List<int> sellingPrice;
const Product(this.name, this.cost, this.sellingPrice);
}这假设销售价格只是一个数字。例如,如果您还想跟踪销售价格的时间戳,那么您将需要另一个类:
class SellingPrice {
final double price;
final DateTime timestamp;
const SellingPrice(this.price, this.timestamp);
}
class Product {
final String name;
final double cost; // Or int
final List<SellingPrice> sellingPrice;
const Product(this.name, this.cost, this.sellingPrice);
}https://stackoverflow.com/questions/66539513
复制相似问题