The Recognizable interface is to be implemented in classes of recognizable shapes such as triangles or squares.
It contains two methods to be defined in those classes:
- public Recognizable recognize() to implement the specific shape recognition algorithm ;
- public void action() to trigger a specific action to the class.
Both can be used as you want. In this demo, I have chosen to call action() directly in the recognize() method, but you can call it later in your code too (that's why the recognize() method return a Recognizable object).
Moreover, with this duality of the recognition and action, you can customize a same recognition algorithm with different actions.
As this library is mainly done for video games, you can attack a character with a weapon by drawing a line pressing the Ctrl key. Yet, the same line can be used to use magic if you press the Alt key!
Using IF/ELSE statements is not a good approach in OOP. An excellent one is to decline a class (with the recognition algorithm implementation) into two subclasses : one for physical attacks, the other for magical attacks.
Another good point with this interface is that you can more easily maintain your shape recognition algorithms this way.
Home page (en)