Results 1 to 3 of 3
Thread: Design question
- 05-26-2010, 02:33 PM #1
Design question
Suppose that you have 2 classes you deal with, class A and class B.
Both classes work with Collections and need to make sure that certain data structure contains no duplicates.
Both classes contain methods (slightly different) that take care of it. Method is 1 line long (take blah, return set)
While working fine, from design perspective, i wonder if such an approach is acceptable. Should there perhaps be a class C which contains those methods? The only concern i have- is how prudent it is to create an object of class C inside both A and B for such a small task as gaining access to one method?
Second part of the question extends the scenario a bit. Suppose you have 10 classes A-J, each of which at different times needs to sort, get unique set, format a string ... blah blah blah .. do stuff that does not have anything to do with the main purpose of that class.
Is it acceptable from design perspective to perhaps have a common utils class which in tuen will take care of all of these requests?
Again, in this example object of that class will be created 10 times and called G-d knows how many times. Is this economical?
Thank you.
- 05-26-2010, 02:41 PM #2
Senior Member
- Join Date
- Feb 2010
- Location
- Ljubljana, Slovenia
- Posts
- 470
- Rep Power
- 4
Utility classes usually have static methods, just so you can avoid creating an instance of that class every time you need a small snippet of it's functionallity. So, instead of this:
you can take the static aproach:Java Code:public class Something { ArrayUtils au; public void someMethod() { au.doSomething(someParameter); } }
So, no istantiation needed. For an example of this, take a look at the Integers parseInt() method. Why would you create an instance of integer, just to get the int value of a String?Java Code:public class Something { public void someMethod() { ArrayUtils.doSomething(someParameter); } }Ever seen a dog chase its tail? Now that's an infinite loop.
- 05-26-2010, 02:48 PM #3
Similar Threads
-
Question mark colon operator question
By orchid in forum Advanced JavaReplies: 9Last Post: 12-19-2010, 08:49 AM -
JSP Design.
By makpandian in forum NetBeansReplies: 0Last Post: 04-20-2009, 01:21 PM -
question on j2ee design pattern
By Minu in forum Advanced JavaReplies: 1Last Post: 01-06-2009, 07:50 PM -
Design question
By kfunk in forum New To JavaReplies: 4Last Post: 10-10-2008, 03:33 AM -
design question comments wanted - essential class init()
By Nicholas Jordan in forum Advanced JavaReplies: 0Last Post: 07-22-2008, 09:41 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks