• Share
  • ?
  • Profiles ▼
  • Communities ▼
  • Apps ▼

Blogs

  • My Blogs
  • Public Blogs
  • My Updates

This community can have members from outside your organization. Linux Boy

  • Log in to participate

▼ Tags

▼ Similar Entries

How to Identify Clas...

Blog: Application I...
MicheleCalcavecchia 270000HCF1
Updated
0 people like thisLikes 0
No CommentsComments 0

How to ensure that a...

Blog: CSE-Sterling ...
Paul Barrie 270003JP87
Updated
0 people like thisLikes 0
No CommentsComments 0

z/TPF rules engine d...

Blog: TPF Blog
Chris Filachek 270007S5UM
Updated
0 people like thisLikes 0
No CommentsComments 0

Updates to z/TPF sup...

Blog: TPF Blog
lemie 060000M2N6
Updated
3 people like thisLikes 3
No CommentsComments 0

IBM ITSM Netcool Ope...

Blog: Network and S...
Murali-Pa 270002P65C
Updated
3 people like thisLikes 3
No CommentsComments 0

▼ Archive

  • May 2012
  • March 2012

▼ Blog Authors

Linux Boy

View All Entries
Clicking the button causes a full page refresh. The user could go to the "Entry list" region to view the new content.) Entry list

Abstract versus Utility Classes

AaronCohen 120000FG50 | | Tags:  java object oriented ‎ | 5,240 Views
Recently I was in a discussion with a coworker on the benefits of using Utility classes over putting common functions in an Abstract class. These classes usually contain static methods that perform common functions.  The major argument I gave was it allowed me to add functions later on without being concerned about all the classes that inherited from it.  The vast amount of my coding style is a functional/Object oriented hybrid.  Objects classes which call Utility classes. After that discussion I wondered what was the performance implications. So I wrote a Calculator app using both approaches and ran each 500,000 times to get an average performance. Here is what I found: 
  • Classes that inherit code from Abstract classes are around 30% slower to initialize.
  • Classes that inherit code from Abstract classes are around 4% slower in execution of all their inherited methods versus calling all the methods from a Utility class.
  • Classes that inherit code from Abstract classes are around 1.3% larger in compiled size.
  • After examining the heap dump I found memory usage is indistinguishable between the two. 
Frankly the compiled size and execution speed fall under standard error. However initialization time is indeed a performance differentiator. Ultimately I believe this is why many of the classes in Java use static Utility classes from the java.util package. Now this is not to say that abstract classes don't have their time and place. On the contrary, they can become very useful and save you a good amount of code. However unless you are inheriting a data modal then I suggest you leave common functions to Utility classes. 
 
If you have any thought or advice, please leave them in the comments below. 
  • Add a Comment Add a Comment
  • Edit
  • More Actions v
  • Quarantine this Entry
Notify Other People
notification

Send Email Notification

+

Quarantine this entry

deleteEntry
duplicateEntry

Mark as Duplicate

  • Previous Entry
  • Main
  • Next Entry
Feed for Blog Entries | Feed for Blog Comments | Feed for Comments for this Entry