{"id":69,"date":"2016-01-25T13:29:25","date_gmt":"2016-01-25T13:29:25","guid":{"rendered":"http:\/\/windows.emacslisp.com\/?p=69"},"modified":"2016-01-25T13:30:32","modified_gmt":"2016-01-25T13:30:32","slug":"pet-shop-4-0-abstract-factory-pattern","status":"publish","type":"post","link":"http:\/\/windows.emacslisp.com\/index.php\/2016\/01\/25\/pet-shop-4-0-abstract-factory-pattern\/","title":{"rendered":"Pet Shop 4.0 &#8211; Abstract Factory Pattern"},"content":{"rendered":"<p>This is the last article about Pet Shop 4.0 source code. some other code such as singleton pattern will be too simple to explain.<\/p>\n<p>When BLL Layer to get data from database, Pet Shop 4.0 uses &#8220;Abstract factory pattern&#8221;.<br \/>\nThis pattern is classic in nowaday development and It is right example in real project.<\/p>\n<pre lang=\"csharp\" line=\"1\">\r\n     Category category = new Category();\r\n     \/\/ Category from PetShop.BLL.\r\n     \/\/ Check following code.  It has \"dal\" factory, which is created by DataAccess Object.\r\n<\/pre>\n<pre lang=\"csharp\" line=\"1\">\r\nnamespace PetShop.BLL {\r\n\r\n    public class Category {\r\n\r\n        private static readonly ICategory dal = PetShop.DALFactory.DataAccess.CreateCategory();\r\n    }\r\n}\r\n<\/pre>\n<p>DataAccess Loads DLL and creates new class Category in namespace &#8220;PetShop.SQLServerDAL&#8221;.<br \/>\nNow &#8220;dal&#8221; inside class &#8220;PetShop.BLL.Category&#8221; point to &#8220;PetShop.SQLServerDAL.Category&#8221;<br \/>\nAny Interface Method &#8220;dal&#8221; calls will be executed by &#8220;PetShop.SQLServerDAL.Category&#8221;.<\/p>\n<p>check the following code.<\/p>\n<pre lang=\"csharp\" line=\"1\">\r\nnamespace PetShop.DALFactory {\r\npublic sealed class DataAccess {\r\n\r\n\tpublic static PetShop.IDAL.ICategory CreateCategory() {\r\n            string className = path + \".Category\";\r\n            return (PetShop.IDAL.ICategory)Assembly.Load(path).CreateInstance(className);\r\n        }\r\n   }\r\n}\r\n<\/pre>\n<pre lang=\"csharp\" line=\"1\">\r\nnamespace PetShop.SQLServerDAL {\r\n\r\n    public class Category : ICategory {\r\n\r\n\tpublic IList<CategoryInfo> GetCategories() {}\r\n\r\n\r\n\tpublic CategoryInfo GetCategory(string categoryId) {}\r\n    }\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This is the last article about Pet Shop 4.0 source code. some other code such as singleton pattern will be too simple to explain. When BLL Layer to get data from database, Pet Shop 4.0 uses &#8220;Abstract factory pattern&#8221;. This &hellip; <a href=\"http:\/\/windows.emacslisp.com\/index.php\/2016\/01\/25\/pet-shop-4-0-abstract-factory-pattern\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"_links":{"self":[{"href":"http:\/\/windows.emacslisp.com\/index.php\/wp-json\/wp\/v2\/posts\/69"}],"collection":[{"href":"http:\/\/windows.emacslisp.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/windows.emacslisp.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/windows.emacslisp.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/windows.emacslisp.com\/index.php\/wp-json\/wp\/v2\/comments?post=69"}],"version-history":[{"count":3,"href":"http:\/\/windows.emacslisp.com\/index.php\/wp-json\/wp\/v2\/posts\/69\/revisions"}],"predecessor-version":[{"id":72,"href":"http:\/\/windows.emacslisp.com\/index.php\/wp-json\/wp\/v2\/posts\/69\/revisions\/72"}],"wp:attachment":[{"href":"http:\/\/windows.emacslisp.com\/index.php\/wp-json\/wp\/v2\/media?parent=69"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/windows.emacslisp.com\/index.php\/wp-json\/wp\/v2\/categories?post=69"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/windows.emacslisp.com\/index.php\/wp-json\/wp\/v2\/tags?post=69"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}