Reputation: 7190
I am porting some OpenGL Nvidia C samples to jogl and I have the following (init
is one of the abstract methods required by GLEventListener
:
public abstract class NvAppBase implements GLEventListener {
@Override
public void init(GLAutoDrawable drawable) {
initRendering(gl4);
}
public void initRendering(GL4 gl4) {
}
}
public abstract class NvSampleApp extends NvAppBase {
@Override
public void init(GLAutoDrawable drawable) {
baseInitRendering(gl4);
}
protected void baseInitRendering(GL4 gl4) {
initRendering(gl4);
}
@Override
public void initRendering(GL4 gl4) {
}
}
public class BindlessApp extends NvSampleApp{
@Override
public void initRendering(GL4 gl4) {
}
}
Given that:
NvAppBase
is not used at all, all the samples (such as BindlessApp
) always extend NvSampleApp
NvSampleApp
to being able to see (and overwrite) only the initRendering
and not also the init
Is there a better way than just having NvSampleApp
simply as a variable inside BindlessApp
, like this for example?
public class BindlessApp {
private NvSampleApp sampleApp;
}
Upvotes: 1
Views: 192
Reputation: 20029
Is there a better way than just having NvSampleApp simply as a variable inside BindlessApp, like this for example?
Although it seems like more work, encapsulation is a great tool to help isolate parts of your code an decrease coupling.
I think in your case it might even be the better solution :)
See for more detail this answer: https://stackoverflow.com/a/18301036/461499
Upvotes: 1
Reputation: 18834
You can use the keyword final
for this purpose.
Writing Final Classes and Methods on Oracle java tutorial.
You can declare some or all of a class's methods final. You use the final keyword in a method declaration to indicate that the method cannot be overridden by subclasses. The Object class does this—a number of its methods are final.
Upvotes: 3