{"id":5444,"date":"2014-03-30T22:00:41","date_gmt":"2014-03-30T22:00:41","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/problem-about-abstract-factory-collection-of-common-programming-errors\/"},"modified":"2014-03-30T22:00:41","modified_gmt":"2014-03-30T22:00:41","slug":"problem-about-abstract-factory-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/problem-about-abstract-factory-collection-of-common-programming-errors\/","title":{"rendered":"problem about abstract-factory-Collection of common programming errors"},"content":{"rendered":"<ul>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/43c3b9a4088ec931fd9981649dd42e4c?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nChristian Metzler<br \/>\ndependency-injection abstract-factory<br \/>\nGiven the following class hierarchyClassA needs ClassB ClassB needs ClassCwe get a dependency graph like this:ClassA &#8211;&gt; ClassB &#8211;&gt; ClassCso if we use DI we inject ClassC into ClassB and ClassB into ClassA.But now let&#8217;s say ClassC is a runtime dependency (for example some kind of strategy). The proposed way to inject a runtime dependency is to introduce an abstract factory like a ClassCFactoryNow we can inject ClassCFactory into ClassB and get the following graphClassA &#8211;&gt; ClassB &#8211;&gt;<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/583749009d7899073ba6ada223f68e8a?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nbibs<br \/>\njava dynamic-typing abstract-factory<br \/>\nI am using an abstract factory to return instances of concrete subclasses.I would like to instantiate the subclasses at runtime given a String of the concrete class name. I also need to pass a parameter to the constructors. The class structure is as follows:abstract class Parent {private static HashMap&lt;String, Child&gt; instances = new HashMap&lt;String,Child&gt;()private Object constructorParameter; public static Child factory(String childName, Object constructorParam){if(instances.keyExist<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/b81db221127979fbf254c4ffba7ba286?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nAggelos Biboudis<br \/>\nc++ covariance abstract-factory<br \/>\nHaving in mind the abstract factory pattern, imagine that you have a class hierarchy where concrete factories override a createButton*s* virtual method, needing to return a wider array of buttons. What could be an elegant workaround to resolve this, as C++ supports only covariant return types? dynamic_cast?A modified version of GoF&#8217;s example to fit my requirement:class Button { public:virtual void paint() = 0;virtual ~Button(){} };class WinButton: public Button { public:void paint() {cout &lt;&amp;l<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/8b2d39a59a961ef26440e9c1453d1939?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nDon<br \/>\njava design-patterns abstract-factory<br \/>\nI&#8217;ve implemented an abstract factory like thispublic abstract class AbstractFactory {private static final Map FACTORIES = new HashMap(); AbstractFactory(FactoryType type) {FACTORIES.put(type, this);} public abstract A getA();public abstract B getB();public static AbstractCatalogFactory getFactory(FactoryType type) {return (AbstractCatalogFactory) FACTORIES.get(type);} }A concrete factory must call this abstract factories constructor, causing each concrete implementation to be registered in<\/li>\n<\/ul>\n<p>Web site is in building<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Christian Metzler dependency-injection abstract-factory Given the following class hierarchyClassA needs ClassB ClassB needs ClassCwe get a dependency graph like this:ClassA &#8211;&gt; ClassB &#8211;&gt; ClassCso if we use DI we inject ClassC into ClassB and ClassB into ClassA.But now let&#8217;s say ClassC is a runtime dependency (for example some kind of strategy). The proposed way to [&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-5444","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5444","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=5444"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5444\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=5444"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=5444"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=5444"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}