FilenameFilter has an accept method that I can implement to tell system how I want to filter files. I want to implement something this similar. Here is my scenario:
I am writing a generic API that run on top of iText that adding Barcode to pdf documents. I have a generic custom Barcode.
public class MyCustomBarcode{
/**
* This variable holds the type of barcode
* com.itextpdf.text.pdf.Barcode
*/
private Barcode barcode;
/**
* The X position of the barcode. (0, 0) is at the bottom left
*/
private float x;
/**
* The Y position of the barcode. (0, 0) is at the bottom left
*/
private float y;
/**
*
*/
private int rotation;
...
}
So when the user use this API, they just need pass in a List<MyCustomBarcode> to a method from my API, then API will insert barcode on to every pdf page. The problem is every barcode has different code format. For example, BarcodeInter25 might use code like 000001, 000002 ... where Barcode39 might use something else. So I want to allow the user to write their own implementation of how to generate the value of the barcode. Something like this
MyCustomBarcode barcode = new MyCustomBarcode(x, y, z){
public String getSeqNum(int i){
//The user own implementation of how they want integer i to look like.
//E.g if i==1, I might return 000001
}
);
And since I allow user to have multiples type of barcode, I want to allow them to write their own implementation for every barcode that they have.
In the parent class, make the method
abstract, and then have each subclass provide their own concrete implementation.Example
Parent class
Subclass