{"id":150,"date":"2005-07-01T01:41:15","date_gmt":"2005-06-30T15:41:15","guid":{"rendered":"http:\/\/thekua.com\/rant\/?p=150"},"modified":"2005-07-01T01:44:52","modified_gmt":"2005-06-30T15:44:52","slug":"sometimes-you-need-to-make-a-class-less-detestable","status":"publish","type":"post","link":"https:\/\/thekua.com\/rant\/2005\/07\/sometimes-you-need-to-make-a-class-less-detestable\/","title":{"rendered":"Sometimes You Need To Make A Class Less Detestable"},"content":{"rendered":"<p>A long time ago (well before I was introduced to Test Driven Design [TDD]), I used to think that tests should not really affect the way that the code is written, but I&#8217;ve really changed my stance on that. It has got to a point where classes that were not driven by tests stick out like a sore thumb. I was recently working around our <code>ManagementAgent<\/code>, a singleton that obviously written to work only when deployed into a container (on instantiation, it would require configuration that would only be available from the <code>web.xml<\/code> file). <\/p>\n<p>I was in a situation where we wanted to add some more configurable attributes to a specific <code>ManagementBean<\/code> (which the <code>Management<\/code> agent would add to itself on instantiation) and I seriously saw the need to refactor some of its code. Of course without tests, I knew I could not refactor in safety. I was so revolted by the situation that I was in, that I knew it was time to make the class less <a href=\"http:\/\/www.martinfowler.com\/bliki\/Detestable.html\">detestable<\/a>.<\/p>\n<p>Since this class was a <a href=\"http:\/\/en.wikipedia.org\/wiki\/Singleton_pattern\">singleton<\/a> that only worked when deployed in the container, I knew it it was time its design changed. For starters, my pair and I decided to break its singleton pattern by providing a package protected constructor and an injectable configuration instead of a self-populating one. The introduction of the constructor allowed us to easily unit test it outside of the container, while the injectable configuration allowed us to more easily test the way the agent created and added a <code>Configuration MBean<\/code> that we were so desperate to refactor. <\/p>\n<p>Although it has much more work to be done to make it that much less detestable, it is one step closer to being more easily unit tested and therefore much more refactorable. On a side note, there was a huge smell that indicated the classes around the <code>ManagementAgent<\/code> were so detestable when I remembered that the package it was in had been excluded from the clover target which effectively boosted the code coverage numbers. Avoid detestable classes because it will increase the cost of future change!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A long time ago (well before I was introduced to Test Driven Design [TDD]), I used to think that tests should not really affect the way that the code is written, but I&#8217;ve really changed my stance on that. It has got to a point where classes that were not driven by tests stick out [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[39],"class_list":["post-150","post","type-post","status-publish","format-standard","hentry","category-technical","tag-work-related"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Sometimes You Need To Make A Class Less Detestable - thekua.com@rest<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/thekua.com\/rant\/2005\/07\/sometimes-you-need-to-make-a-class-less-detestable\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Sometimes You Need To Make A Class Less Detestable - thekua.com@rest\" \/>\n<meta property=\"og:description\" content=\"A long time ago (well before I was introduced to Test Driven Design [TDD]), I used to think that tests should not really affect the way that the code is written, but I&#8217;ve really changed my stance on that. It has got to a point where classes that were not driven by tests stick out [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/thekua.com\/rant\/2005\/07\/sometimes-you-need-to-make-a-class-less-detestable\/\" \/>\n<meta property=\"og:site_name\" content=\"thekua.com@rest\" \/>\n<meta property=\"article:published_time\" content=\"2005-06-30T15:41:15+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2005-06-30T15:44:52+00:00\" \/>\n<meta name=\"author\" content=\"Patrick\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Patrick\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/thekua.com\\\/rant\\\/2005\\\/07\\\/sometimes-you-need-to-make-a-class-less-detestable\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/thekua.com\\\/rant\\\/2005\\\/07\\\/sometimes-you-need-to-make-a-class-less-detestable\\\/\"},\"author\":{\"name\":\"Patrick\",\"@id\":\"https:\\\/\\\/thekua.com\\\/rant\\\/#\\\/schema\\\/person\\\/6de103b28f96be3f1f4dc25db357c6ae\"},\"headline\":\"Sometimes You Need To Make A Class Less Detestable\",\"datePublished\":\"2005-06-30T15:41:15+00:00\",\"dateModified\":\"2005-06-30T15:44:52+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/thekua.com\\\/rant\\\/2005\\\/07\\\/sometimes-you-need-to-make-a-class-less-detestable\\\/\"},\"wordCount\":351,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\\\/\\\/thekua.com\\\/rant\\\/#\\\/schema\\\/person\\\/6de103b28f96be3f1f4dc25db357c6ae\"},\"keywords\":[\"Work-Related\"],\"articleSection\":[\"Work Related\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/thekua.com\\\/rant\\\/2005\\\/07\\\/sometimes-you-need-to-make-a-class-less-detestable\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/thekua.com\\\/rant\\\/2005\\\/07\\\/sometimes-you-need-to-make-a-class-less-detestable\\\/\",\"url\":\"https:\\\/\\\/thekua.com\\\/rant\\\/2005\\\/07\\\/sometimes-you-need-to-make-a-class-less-detestable\\\/\",\"name\":\"Sometimes You Need To Make A Class Less Detestable - thekua.com@rest\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/thekua.com\\\/rant\\\/#website\"},\"datePublished\":\"2005-06-30T15:41:15+00:00\",\"dateModified\":\"2005-06-30T15:44:52+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/thekua.com\\\/rant\\\/2005\\\/07\\\/sometimes-you-need-to-make-a-class-less-detestable\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/thekua.com\\\/rant\\\/2005\\\/07\\\/sometimes-you-need-to-make-a-class-less-detestable\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/thekua.com\\\/rant\\\/2005\\\/07\\\/sometimes-you-need-to-make-a-class-less-detestable\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/thekua.com\\\/rant\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Sometimes You Need To Make A Class Less Detestable\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/thekua.com\\\/rant\\\/#website\",\"url\":\"https:\\\/\\\/thekua.com\\\/rant\\\/\",\"name\":\"thekua.com@rest\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\\\/\\\/thekua.com\\\/rant\\\/#\\\/schema\\\/person\\\/6de103b28f96be3f1f4dc25db357c6ae\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/thekua.com\\\/rant\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/thekua.com\\\/rant\\\/#\\\/schema\\\/person\\\/6de103b28f96be3f1f4dc25db357c6ae\",\"name\":\"Patrick\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/thekua.com\\\/rant\\\/wp-content\\\/uploads\\\/2025\\\/12\\\/pat-kua-head.png\",\"url\":\"https:\\\/\\\/thekua.com\\\/rant\\\/wp-content\\\/uploads\\\/2025\\\/12\\\/pat-kua-head.png\",\"contentUrl\":\"https:\\\/\\\/thekua.com\\\/rant\\\/wp-content\\\/uploads\\\/2025\\\/12\\\/pat-kua-head.png\",\"width\":400,\"height\":400,\"caption\":\"Patrick\"},\"logo\":{\"@id\":\"https:\\\/\\\/thekua.com\\\/rant\\\/wp-content\\\/uploads\\\/2025\\\/12\\\/pat-kua-head.png\"},\"sameAs\":[\"http:\\\/\\\/www.thekua.com\"],\"url\":\"https:\\\/\\\/thekua.com\\\/rant\\\/author\\\/patrick\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Sometimes You Need To Make A Class Less Detestable - thekua.com@rest","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/thekua.com\/rant\/2005\/07\/sometimes-you-need-to-make-a-class-less-detestable\/","og_locale":"en_US","og_type":"article","og_title":"Sometimes You Need To Make A Class Less Detestable - thekua.com@rest","og_description":"A long time ago (well before I was introduced to Test Driven Design [TDD]), I used to think that tests should not really affect the way that the code is written, but I&#8217;ve really changed my stance on that. It has got to a point where classes that were not driven by tests stick out [&hellip;]","og_url":"https:\/\/thekua.com\/rant\/2005\/07\/sometimes-you-need-to-make-a-class-less-detestable\/","og_site_name":"thekua.com@rest","article_published_time":"2005-06-30T15:41:15+00:00","article_modified_time":"2005-06-30T15:44:52+00:00","author":"Patrick","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Patrick","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/thekua.com\/rant\/2005\/07\/sometimes-you-need-to-make-a-class-less-detestable\/#article","isPartOf":{"@id":"https:\/\/thekua.com\/rant\/2005\/07\/sometimes-you-need-to-make-a-class-less-detestable\/"},"author":{"name":"Patrick","@id":"https:\/\/thekua.com\/rant\/#\/schema\/person\/6de103b28f96be3f1f4dc25db357c6ae"},"headline":"Sometimes You Need To Make A Class Less Detestable","datePublished":"2005-06-30T15:41:15+00:00","dateModified":"2005-06-30T15:44:52+00:00","mainEntityOfPage":{"@id":"https:\/\/thekua.com\/rant\/2005\/07\/sometimes-you-need-to-make-a-class-less-detestable\/"},"wordCount":351,"commentCount":2,"publisher":{"@id":"https:\/\/thekua.com\/rant\/#\/schema\/person\/6de103b28f96be3f1f4dc25db357c6ae"},"keywords":["Work-Related"],"articleSection":["Work Related"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/thekua.com\/rant\/2005\/07\/sometimes-you-need-to-make-a-class-less-detestable\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/thekua.com\/rant\/2005\/07\/sometimes-you-need-to-make-a-class-less-detestable\/","url":"https:\/\/thekua.com\/rant\/2005\/07\/sometimes-you-need-to-make-a-class-less-detestable\/","name":"Sometimes You Need To Make A Class Less Detestable - thekua.com@rest","isPartOf":{"@id":"https:\/\/thekua.com\/rant\/#website"},"datePublished":"2005-06-30T15:41:15+00:00","dateModified":"2005-06-30T15:44:52+00:00","breadcrumb":{"@id":"https:\/\/thekua.com\/rant\/2005\/07\/sometimes-you-need-to-make-a-class-less-detestable\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/thekua.com\/rant\/2005\/07\/sometimes-you-need-to-make-a-class-less-detestable\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/thekua.com\/rant\/2005\/07\/sometimes-you-need-to-make-a-class-less-detestable\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/thekua.com\/rant\/"},{"@type":"ListItem","position":2,"name":"Sometimes You Need To Make A Class Less Detestable"}]},{"@type":"WebSite","@id":"https:\/\/thekua.com\/rant\/#website","url":"https:\/\/thekua.com\/rant\/","name":"thekua.com@rest","description":"","publisher":{"@id":"https:\/\/thekua.com\/rant\/#\/schema\/person\/6de103b28f96be3f1f4dc25db357c6ae"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/thekua.com\/rant\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/thekua.com\/rant\/#\/schema\/person\/6de103b28f96be3f1f4dc25db357c6ae","name":"Patrick","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/thekua.com\/rant\/wp-content\/uploads\/2025\/12\/pat-kua-head.png","url":"https:\/\/thekua.com\/rant\/wp-content\/uploads\/2025\/12\/pat-kua-head.png","contentUrl":"https:\/\/thekua.com\/rant\/wp-content\/uploads\/2025\/12\/pat-kua-head.png","width":400,"height":400,"caption":"Patrick"},"logo":{"@id":"https:\/\/thekua.com\/rant\/wp-content\/uploads\/2025\/12\/pat-kua-head.png"},"sameAs":["http:\/\/www.thekua.com"],"url":"https:\/\/thekua.com\/rant\/author\/patrick\/"}]}},"_links":{"self":[{"href":"https:\/\/thekua.com\/rant\/wp-json\/wp\/v2\/posts\/150","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thekua.com\/rant\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thekua.com\/rant\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thekua.com\/rant\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/thekua.com\/rant\/wp-json\/wp\/v2\/comments?post=150"}],"version-history":[{"count":0,"href":"https:\/\/thekua.com\/rant\/wp-json\/wp\/v2\/posts\/150\/revisions"}],"wp:attachment":[{"href":"https:\/\/thekua.com\/rant\/wp-json\/wp\/v2\/media?parent=150"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thekua.com\/rant\/wp-json\/wp\/v2\/categories?post=150"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thekua.com\/rant\/wp-json\/wp\/v2\/tags?post=150"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}