Back to list
Views:   0
Replies:  0
Archived
,
Reply 1
I've a simple pattern I like to use in cases such as these.  I call it the comparator pattern.  Here's a simple Console app that can be used to describe a possible solution.

I hope this helps


class Program
    {
        static void Main(string[] args)
        {
            var productA = new Product("Red", "Shoes", "10", "Rubber");
            var productB = new Product("Red", "Shoes", "10", "Rubber");
            var productC = new Product("Green", "Shoes", "8", "Plastic");

            if (productA.IsEqualTo(productB)){Console.WriteLine("Product A and Product B are the same");}
            if (!productB.IsEqualTo(productC)){Console.WriteLine("Product B and Product C are NOT the same"); }

            Console.ReadLine();
        }

        
    }

    public class Product
    {
        private readonly string color, name, size, material;

        public Product(string color, string name, string size, string material)
        {
            this.color = color;
            this.name = name;
            this.size = size;
            this.material = material;
        }

        public bool IsEqualTo(Product product)
        {       
            return (product.color == color && product.name == name) && product.material == material;
        }
    }

 
Sameer Lamba, Apr 18, 2012
Thats a good point and one possible answer. I think thats why singleton class can be used for state mangement in stateless scenarios like shopping cart scenario,
Apr 17, 2012
Stay Inspired!
Join other developers and designers who have already signed up for our mailing list.
Terms     Privacy     Licensing       EULA       Sitemap      
© Data & Object Factory, LLC.
Made with    in Austin, Texas