{"id":4393,"date":"2014-03-30T10:28:07","date_gmt":"2014-03-30T10:28:07","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/how-to-allow-a-user-of-the-class-x-to-choose-an-implementation-of-the-interface-the-class-x-is-using-collection-of-common-programming-errors\/"},"modified":"2014-03-30T10:28:07","modified_gmt":"2014-03-30T10:28:07","slug":"how-to-allow-a-user-of-the-class-x-to-choose-an-implementation-of-the-interface-the-class-x-is-using-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/how-to-allow-a-user-of-the-class-x-to-choose-an-implementation-of-the-interface-the-class-x-is-using-collection-of-common-programming-errors\/","title":{"rendered":"How to allow a user of the class X to choose an implementation of the interface the class X is using?-Collection of common programming errors"},"content":{"rendered":"<p>Your solution (the public IPriorityQueue property) is commonly seen when using &#8220;Dependency Injection&#8221; (or &#8220;Inversion of Control&#8221;) frameworks and is known as &#8220;setter injection&#8221;.<\/p>\n<p>Another option would be &#8220;Constructor Injection&#8221;, where the interface&#8217;s implementation is provided as a constructor parameter.<\/p>\n<p>There are many of these frameworks to choose from: .Net has Unity, Spring.Net, StructureMap Castle Windsor and others. Java has Spring and probably others as well.<\/p>\n<p>These frameworks allow the user to specify the implementation he wants to use in an XML configuration file, or by providing a configuration at runtime to the Dependency Injection container.<\/p>\n<p>When objects instances are created using such a framework, it takes care of creating\/retrieving the dependency and providing them to the dependent object.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Your solution (the public IPriorityQueue property) is commonly seen when using &#8220;Dependency Injection&#8221; (or &#8220;Inversion of Control&#8221;) frameworks and is known as &#8220;setter injection&#8221;. Another option would be &#8220;Constructor Injection&#8221;, where the interface&#8217;s implementation is provided as a constructor parameter. There are many of these frameworks to choose from: .Net has Unity, Spring.Net, StructureMap Castle [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4393","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4393","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=4393"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4393\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4393"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4393"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4393"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}