Factory method pattern implementation in .net framework
Posted

Factory method pattern also called as Virtual Constructor (less known), defines an interface for creating objects, but defer the instantiation to sub-classes.
Read more about the pattern: Wikipedia, dofactory, Sourcemaking, oodesign, etc.
I can safely state, that: A well designed library cannot exist without implementing factory method pattern.
We can see .net framework implementing this pattern extensively, few examples:
System.Activator.CreateInstance(Type type)System.Net.WebRequest.Create(string requestUriString)based on the url scheme, if url starts with http://, aSystem.Net.HttpWebRequestinstance will be returned. For ftp:// aSystem.Net.FtpWebRequest.System.Convert.ToInt32,System.Convert.ToBoolean, etc.System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, string controllerName)based oncontrollerNameparameter, this method returns instance specified.