【问题标题】:Store products management店铺产品管理
【发布时间】:2021-06-06 21:45:24
【问题描述】:

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

我知道,随着时间的推移,使用该应用程序的用户将需要输入新产品和新的“价格组”(表格的“销售价格……”列)。

我正在使用面向对象的语言 (Dart)。组织代码的最佳方式是什么?我应该创建哪些类?

如果您需要更多详细信息,请告诉我。非常感谢!

【问题讨论】:

    标签: oop dart architecture


    【解决方案1】:

    你可能只需要一节课Product:

    class Product {
      final String name;
      final double cost; // Or int
      final List<int> sellingPrice;
    
      const Product(this.name, this.cost, this.sellingPrice);
    }
    

    然后你可以getadd将价格卖到对象里面的列表中。

    这假设售价只是一个数字。例如,如果您还想跟踪销售价格的时间戳,那么您将需要另一个类:

    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);
    }
    

    很大程度上取决于您计划如何与对象交互。可能会有更高效的结构或不同的组织(例如,不使用List,而是使用Set)。

    【讨论】:

    • 非常感谢您的回复!使用List 时遇到的问题是我没有销售价格列的标识符(和助记符帮助)。我可以使用Map&lt;String, double&gt;,但是,如何确保为所有产品分配与每个“售价……”列对应的价格?
    猜你喜欢
    • 1970-01-01
    • 2018-12-08
    • 1970-01-01
    • 2020-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-18
    • 1970-01-01
    相关资源
    最近更新 更多