{"id":38,"date":"2004-11-12T16:18:48","date_gmt":"2004-11-12T16:18:48","guid":{"rendered":"http:\/\/gaisan.com\/wordp\/?p=38"},"modified":"2004-11-12T16:18:48","modified_gmt":"2004-11-12T16:18:48","slug":"static-substitution-fowler-style","status":"publish","type":"post","link":"http:\/\/gaisan.com\/blogs\/?p=38","title":{"rendered":"Static substitution (Fowler Style)"},"content":{"rendered":"<p><a href=\"http:\/\/martinfowler.com\/\">Martin Fowler<\/a> has a neat little article on refactoring class statics using instance variables. Most languages can&#8217;t support polymorphism for static methods. e.g.<br \/>\n<code><br \/>\nclass A{<br \/>\npublic void doInitStuff() { \/*do stuff necessary for static init of B objects*\/};<br \/>\n} ...<br \/>\n}<br \/>\nclass B extends A{<br \/>\npublic void doInitStuff() { \/*do other stuff necessary for static init of B objects*\/};<br \/>\n} ...<br \/>\n}<br \/>\n...<br \/>\nA a = new B();<br \/>\nA.doInitStuff(); \/* but I'd quite like to polymorphically call B.doStuff(); Actually, could be trouble! *\/<br \/>\n<\/code><br \/>\nMartin&#8217;s <a href=\"http:\/\/martinfowler.com\/bliki\/StaticSubstitution.html\">solution is very elegant.<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Martin Fowler has a neat little article on refactoring class statics using instance variables. Most languages can&#8217;t support polymorphism for static methods. e.g. class A{ public void doInitStuff() { \/*do stuff necessary for static init of B objects*\/}; } &#8230; } class B extends A{ public void doInitStuff() { \/*do other stuff necessary for static [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"_links":{"self":[{"href":"http:\/\/gaisan.com\/blogs\/index.php?rest_route=\/wp\/v2\/posts\/38"}],"collection":[{"href":"http:\/\/gaisan.com\/blogs\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/gaisan.com\/blogs\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/gaisan.com\/blogs\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/gaisan.com\/blogs\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=38"}],"version-history":[{"count":0,"href":"http:\/\/gaisan.com\/blogs\/index.php?rest_route=\/wp\/v2\/posts\/38\/revisions"}],"wp:attachment":[{"href":"http:\/\/gaisan.com\/blogs\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=38"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/gaisan.com\/blogs\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=38"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/gaisan.com\/blogs\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=38"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}