elect
elect

Reputation: 7190

Java, hiding methods of super super class

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:

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

Answers (2)

Rob Audenaerde
Rob Audenaerde

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

Ferrybig
Ferrybig

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

Related Questions