Advertisement

02.05.2008 at 11:32AM PST, ID: 23139100
[x]
Attachment Details

Should a class contain ONLY a constructor method?

Asked by BrianMc1958 in Java Programming Language

Dear Experts,

I'm looking for general advice on this.

Generally, for small-but-not-quite-trivial tasks, I make a new class, rather than sticking a new method into my (ever-growing) "utility" class.  I often then find that everything that is needed for such a small class is contained within the constructor.  But in that case, instantiating the class seems very odd--because once it's done instantiating, it's outlived it's usefulness already.

For instance, I just made a class that simply adds foreign keys to a table.  In the constructor, I pass it a connection,  two tables names,  and two lists of keys.  It generates the SQL, runs it, and then it's done.  There's no separate "go run the SQL" method, for instance.  There's really no need for any method other than the constructor.

Can you folks tell me, in general, what am I missing in my design here?  Instantiating a class and then immediately setting it to null seems crazy.  Should I be doing something with static?

Thanks again.
--BrianMc1958Start Free Trial
 
Loading Advertisement...
 
[+][-]02.05.2008 at 11:40AM PST, ID: 20826095

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]02.05.2008 at 11:51AM PST, ID: 20826179

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.05.2008 at 11:56AM PST, ID: 20826232

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]02.05.2008 at 12:30PM PST, ID: 20826577

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.05.2008 at 05:48PM PST, ID: 20828872

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Java Programming Language
Sign Up Now!
Solution Provided By: objects
Participating Experts: 5
Solution Grade: A
 
 
[+][-]02.05.2008 at 11:33PM PST, ID: 20830188

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]02.06.2008 at 01:39AM PST, ID: 20830630

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.06.2008 at 06:26AM PST, ID: 20832115

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.06.2008 at 12:41PM PST, ID: 20835526

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628