C
c_kernel
This may seem like an odd question, but please bear with me... Consider
the common scenario where you have an interface, an abstract base class
that implements some (but not all) of that interface, and a concrete
derived class that implements the rest. In Java, unlike in C#, it is
perfectly ok to omit some of the interface methods from the abstract
base class declaration. They are considered to be implicitly declared
"abstract" there. For example:
interface IFoo
{
void bar();
}
abstract class FooBase implements IFoo
{
public abstract void baz();
// This doesn't actually need to be here.
// public abstract void bar();
public final void goo()
{
System.out.println( "FooBase.goo()" );
}
}
class Foo extends FooBase
{
public void baz()
{
System.out.println( "Foo.baz()" );
}
public void bar()
{
System.out.println( "Foo.bar()" );
}
}
In this example, bar() doesn't need to be declared in FooBase. I have
tried this out in a little test app both with and without the redundant
declaration of bar(). Having it there doesn't seem to hurt anything,
and it makes the class declaration more explicit.
My question is twofold: 1.) Does the extra declaration in the abstract
class hurt anything (performance maybe...? Although I can't see how...)
2.) If not, which is preferred from a style point of view? Would it be
considered very strange to have the redundant declaration there?
Thanks!
the common scenario where you have an interface, an abstract base class
that implements some (but not all) of that interface, and a concrete
derived class that implements the rest. In Java, unlike in C#, it is
perfectly ok to omit some of the interface methods from the abstract
base class declaration. They are considered to be implicitly declared
"abstract" there. For example:
interface IFoo
{
void bar();
}
abstract class FooBase implements IFoo
{
public abstract void baz();
// This doesn't actually need to be here.
// public abstract void bar();
public final void goo()
{
System.out.println( "FooBase.goo()" );
}
}
class Foo extends FooBase
{
public void baz()
{
System.out.println( "Foo.baz()" );
}
public void bar()
{
System.out.println( "Foo.bar()" );
}
}
In this example, bar() doesn't need to be declared in FooBase. I have
tried this out in a little test app both with and without the redundant
declaration of bar(). Having it there doesn't seem to hurt anything,
and it makes the class declaration more explicit.
My question is twofold: 1.) Does the extra declaration in the abstract
class hurt anything (performance maybe...? Although I can't see how...)
2.) If not, which is preferred from a style point of view? Would it be
considered very strange to have the redundant declaration there?
Thanks!