This small Java project with only one (master) class is a proof-of-concept of an over simplified java program to deliver maximum feature in a minimum number lines of code, and WITHOUT dependencies out of the JDK itself (but only for test purpose, using JUnit and Cucumber). (Note: subclasses were dispatch into package since july 2022)
Here is the opportunity to refactor the Render engine to support extensibility throught Entity nature, declaring a specialized RenderPlugin for each derived type of Entity, allowing new way to implement rendering pipeline.
Render will be renamed to Renderer, and will propose a Map of RenderPlugin implementation according to the Entity class.
public class Renderer{
Map<Class<? extends Entity>, RenderPlugin> plugins = new ConcurrentHashMap<>();
public Renderer(Application app){
this.app = app;
this.renderers.put(Entity.class,new EntityRenderPlugin());
}
public draw(){
renderingPipeline.values().stream.foreach(e->{
plugins.get(e.getClass()).draw(this, g,e);
});
}
}
The RenderPlugin interface
Any derived entity implmentation will have its corresponding implementation of the RenderPlugin interface.
Refactor the Render with plugin
Here is the opportunity to refactor the
Render
engine to support extensibility throughtEntity
nature, declaring a specializedRenderPlugin
for each derived type ofEntity
, allowing new way to implement rendering pipeline.Render
will be renamed toRenderer
, and will propose a Map ofRenderPlugin
implementation according to theEntity
class.The RenderPlugin interface
Any derived entity implmentation will have its corresponding implementation of the RenderPlugin interface.
Interface
Default Implementation