The question of architecture is more. There is an entity Order, it has a status - fulfilled, collected, created, etc. There is an entity Order Status. Both of these entities are represented by tables in the database. How can I better organize the work in the code with order statuses? I don’t want to use hardcoded constants, but I’d have to do selections by status, for example, in 1s.

    2 answers 2

    The question is, in what framework do you want to discuss the architecture? As part of the OOP paradigm? Or within the framework of the relational database architecture? If the first, then you can jot down for example the following code:

    public class DeliveredOrderCollectionTest { private DataContext storage; [SetUp] public void setUp() { this.storage = new DataStorage(); } [Test] public void Get_Order_collection_test() { IEnumerable<Order> orders = this.storage.Get<IEnumerable<Order>>(); Assert.IsNotNull(orders); Assert.AreEqual(0, orders.Count()); } [Test] public void Get_FormedOrder_collection_test() { IEnumerable<FormedOrder> formedOrders = this.storage.Get<IEnumerable<FormedOrder>>(); Assert.IsNotNull(formedOrders); Assert.AreEqual(0, formedOrders.Count()); } [Test] public void Get_DeliveredOrder_collection_test() { IEnumerable<DeliveredOrder> deliveredOrders = this.storage.Get<IEnumerable<DeliveredOrder>>(); Assert.IsNotNull(deliveredOrders); Assert.AreEqual(0, deliveredOrders.Count()); } } 

    And if to argue from the point of view of business logic (using primary accounting documents), the order status can be clearly compared with the appearance of these most primary documents, as the order is processed:

    • The client sketched goods in the basket and clicked checkout - "decorated"
    • In the bank statement there is an entry about the payment of the order by the client - “paid”
    • The warehouse transferred the goods, according to the waybill in the delivery - "formed"
    • Delivery delivered the order according to the waybill to the courier - "sent"
    • The courier returned the bill of lading signed by the customer - "delivered"

    Accordingly, we have in the system (database) there are records of these primary documents, associated with the original order.

      I decided to do this: hide the work with order statuses behind the methods that change them.

       class Order // change status reject() toDelivery() toPay() // read status isPaid() isDelivered()