I have this abstract class named as RenderableEntity .
I have a public method render()
that has some logic wrapped around abstract protected render()
method. How should I name this abstract render()
method. Is there some kind of convention eg. doRender()
, makeRender()
for protected method render()
?
public abstract class RenderableEntity extends Entity {
private boolean visible;
public void render(){
if(visible){
render();
}
}
protected abstract void render();
}
Edit: I know this snippet does not compile. I was just wondering how to name this abstract method since I can't have methods with same name and same parameters.
First: Only consider special naming for methods like these if they are for exclusive use by the template method. In addition, you should comment these methods stating that they are used by the template method and any modifications should be made with that usage in mind.
The methods that make up replaceable steps in a template method are often called "hook" methods. You'll sometimes see them named with "Hook" at the end.
In your example, you may want to call it renderHook()
, though if you can get more specific on the task that it is performing within the template method render()
that would be more descriptive.
I have seen doXXX()
used, though it's primarily when there is a one-to-one template-to-hook relationship.
A possible suggestion. For a template method stuff()
:
If stuff()
is primarily simple control logic around a single hook, name the hook doStuff()
(This seems to be the case in your example above)
If stuff()
orchestrates several hooks, name them independently with Hook
suffixes, and do not name any of them the same as the template (in this case, there should be no stuffHook()
method.
There is no convention about it. But I would prefer to see more meaningfull name. E.g. forceRender
, renderNow
, renderImmideately
or something similar which tells the fact it renders somehow differently than just render
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With