{"id":362,"date":"2020-07-01T11:00:00","date_gmt":"2020-07-01T18:00:00","guid":{"rendered":"https:\/\/www.tizianasellitto.it\/blog\/?p=362"},"modified":"2020-06-29T17:51:43","modified_gmt":"2020-06-30T00:51:43","slug":"helper-and-utility-classes-in-java","status":"publish","type":"post","link":"https:\/\/www.tizianasellitto.it\/blog\/?p=362","title":{"rendered":"Helper and Utility Classes in Java"},"content":{"rendered":"\n<p class=\"has-text-align-justify\">In an object oriented programming model we can define a <em><strong>helper class <\/strong><\/em>as a way to provide some functionality that aren&#8217;t the main goal of the application or class in which they are used.  A helper class can have instance variables and multiple instances as well. A <em><strong>utility class<\/strong><\/em> is a special case of helper class where all methods are <em>static<\/em>.<\/p>\n\n\n\n<p class=\"has-text-align-justify\">Usually Utility and Helper Class are used to do basic functions help so that developers don&#8217;t have to implement it multiple time. A general rule could be:<\/p>\n\n\n\n<ul class=\"has-text-align-justify\"><li>Utility Class: static class that can be easily accessed and imported everywhere.  In order to prevent instantiation of a Utility class a common practice is to make the class final and create a private constructor.<\/li><li>Helper Class: class helping another class. Can have multiple instances and instances variables.<\/li><\/ul>\n\n\n\n<p class=\"has-text-align-justify\">One thing to notice is that using a class in a Static way means no class instantiation and use of Stack memory instead of Heap Memory. This will bring a slightly less overhead because of compile time binding. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>In an object oriented programming model we can define a helper class as a way to provide some functionality that aren&#8217;t the main goal of the application or class in which they are used. A helper class can have instance variables and multiple instances as well. A utility class is a special case of helper [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[19],"tags":[32,40],"_links":{"self":[{"href":"https:\/\/www.tizianasellitto.it\/blog\/index.php?rest_route=\/wp\/v2\/posts\/362"}],"collection":[{"href":"https:\/\/www.tizianasellitto.it\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tizianasellitto.it\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tizianasellitto.it\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tizianasellitto.it\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=362"}],"version-history":[{"count":5,"href":"https:\/\/www.tizianasellitto.it\/blog\/index.php?rest_route=\/wp\/v2\/posts\/362\/revisions"}],"predecessor-version":[{"id":367,"href":"https:\/\/www.tizianasellitto.it\/blog\/index.php?rest_route=\/wp\/v2\/posts\/362\/revisions\/367"}],"wp:attachment":[{"href":"https:\/\/www.tizianasellitto.it\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=362"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tizianasellitto.it\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=362"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tizianasellitto.it\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=362"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}