The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
December 2000

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

class design problem

Posted by manish on December 01, 2000 at 7:30 AM

I am having a problem related to the design of classes using java as prog. language.The class heirarchy is like this:
GroupExpression (Parent class)

Min Max Avg Sum Count (Child classes)
These sub classes do the comparison of input parameters
depending on the class called(e.g Sum class will add the parameters,Count will count the params like that).
Parent class has Create(arg) and compute(arg1,arg2)methods.Child class will have the compute(arg1,arg2) method.
Caller will have refernce of Parent class and it will call its create()method to create an instance of reqd sub class.Then it will call the compute() method .

Now Problem is input parameters can be of type
int,float,long,double and accordingly the return type.

Now the code to check for the parameter type and accordingly select the return type or given that if return type is being passed then also the code becomes dirty.
Tried taking input to compute() method as an object having parameter type and parameter value as its attributes.But this again becomes clumsy.
Can you suggest me a neat way to overcome the problem.
Thanks and Regards,
Manish Dhall



Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us