What architecture can I use to handle a shopping cart where each product requries different attributes to be saved

后端 未结 4 2053
星月不相逢
星月不相逢 2021-02-06 15:25

I am building an application that is very similar to a shopping cart. The user selects a product from a list, and then based on that product, a few properties need to be set an

4条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-06 16:05

    You can have a Product class with a collection of product properties

        public class Product
        {
            private Dictionary properties;
    
            /// 
            /// Gets or sets the name.
            /// 
            /// The name.
            public string Name
            {
                get;
                set;
            }
    
            /// 
            /// Gets or sets the price.
            /// 
            /// The price.
            public double Price
            {
                get;
                set;
            }
    
            public Dictionary Properties
            {
                get;
            }
    
            public Product()
            {
                properties = new Dictionary();
            }
    
        }
    

    In the datasource you can have a table that defines the properties to each type of product. Then when you render the page you know what properties to show and the name to give in the dictionary.

提交回复
热议问题