horos11@gmail.com wrote in news:3d5780fe-671e-4f46-94f9-
eceadbbfdacc@g22g2000pra.googlegroups.com:
All,
I'm trying to overcome the following problem. I'd like to have an
abstract class contain common functionality for subclasses, but I
don't want to be limited by the representations of them. For example:
abstract class a
{
String calculate() { return this.put(this.my_func()); }
}
class b extends a
{
Set<Integer> myset;
Integer my_func() { return (1); }
void put(Integer myint) { myset.put(myint); }
}
class c extends a
{
Set<Float> myset;
Float my_func() { return(1.0); }
void put(Float myfloat) { myset.put(myfloat); }
}
As it stands, if I put the return types, etc. in the abstract class it
gets exceedingly ugly because implementation details are seeping into
the abstract class and it would need to be updated with new function
signatures each time a new subclass is created. I need to find a way
to say that any given method is *purely* abstract, ie: that it will be
defined solely in the subclass.
Is there a way to do this, or am I pretty much stuck reimplementing
lots of functionality in each subclass?
thanks much..
abstract class a
{
protected Set<Object> myset = new java.util.HashSet<Object>();
// how put returns a String is beyond me ???
String calculate() { this.put(this.myfunc()); return "barf"; }
abstract Object my_func() ;
}
class b extends a
{
@Override
Object my_func() { return new Integer(1); }
void put(Integer myint) { myset.put(myint); }
}
class b extends a
{
@Override
Object my_func() { return new Float(1); }
void put(Float myfloat) { myset.put(myfloat); }
}
I cancelled this. It has no point, the original sample is beyond any clue
and no point in refining it.