/* My example of the Abstract Factory design pattern. Abstract Factory : automobile factory Concrete factories: Honda, Ford, etc ... Abstract Products: compact, midsize, SUV Concrete products: civic, accord, taurus, explorer, etc ... Abstract factories make abstract products. */ using System; using System.Collections; // needed to use ArrayList //// Products hiearchy: interface automobile // my addition to the pattern - super abstract product { int horsepower(); double price(); int compareprice(automobile other); // "interaction" method } abstract class compact : automobile { ArrayList Options; public virtual int horsepower() { return 100; } public virtual double price() { return 15000; } public int compareprice(automobile other) { return (int)(price() - other.price()); } // returns difference in price } abstract class midsize : automobile { ArrayList Options; public virtual int horsepower() { return 150; } public virtual double price() { return 20000; } public int compareprice(automobile other) { return (int)(price() - other.price()); } } abstract class suv : automobile { ArrayList Options; public virtual int horsepower() { return 200; } public virtual double price() { return 25000; } public int compareprice(automobile other) { return (int)(price() - other.price()); } } // Concrete products class civic : compact { public override int horsepower() {return 110;} // data made up public override double price() {return 16000;} } class focus : compact { // everything inherited } class accord : midsize { public override int horsepower() {return 170;} public override double price() {return 24000;} } class taurus : midsize { public override double price() {return 17000;} } class explorer : suv { public override int horsepower() {return 190;} } class pilot : suv { public override double price() {return 30000;} } //// Factories hierarchy interface carfactory // abstract factory { compact makecompact(); midsize makemidsize(); suv makesuv(); } // concrete factories: class hondafactory : carfactory { public compact makecompact() { return new civic(); } public midsize makemidsize() { return new accord(); } public suv makesuv() { return new pilot(); } } class fordfactory : carfactory { public compact makecompact() { return new focus(); } public midsize makemidsize() { return new taurus(); } public suv makesuv() { return new explorer(); } } public class absfactory // application class { public static void Main() { carfactory michiganfactory = new fordfactory(); carfactory japanfactory = new hondafactory(); compact c1 = michiganfactory.makecompact(); midsize m1 = japanfactory.makemidsize(); Console.WriteLine( c1.compareprice(m1) ); } } // Question: how can you improve on this design?