I’ve developed a simple POS system that gets the list of products & buttons from the DB. The table holding all the buttons provides all the information we need to draw the button (i.e.: size, position, label, colour and which SKU it relates to).
In the original version, all the ‘function’ buttons have been hard coded (i.e.: numbers 1-9, pay, change price levels, end shift etc) but I want to move to a more customisable design, so that function buttons can also be stored in the database.
I was looking at doing this with something reflection based. I have a class to act as an interface, containing all the methods that will appear in the DB, which will then call on any of the necessary methods within the system. But I’m not sure how to map this to the DB.
I’m pretty certain that every method will take 0, 1 or 2 parameters which have a mixture of boolean, int, double and char.
I’ve come up with a notation for the DB that I can parse to determine all the information I need to call the method, for example to pay off a sale I would put something like
paySale[]
in the database, but if the customer gave me a $50 and I wanted to use a ‘quick cash’ button, then the method call would be
paySale[d 50]
or something a little more complex, like paying with a cheque
paySale[i 3, d 50]
where the int is the payment method type (in this case would be cheque) and double is the total.
My issue is that when I try to fetch the method using getMethod() I can’t figure out how to define which parameters to look for, such as double.class and int.class
There will be several different methods that will need to be called, to handle things like price level changes, end of shift, paying to accounts / tabs etc so if there is an easier way to do this, then I’m open to it!
Thanks again guys!
Use something like
class.getMethod(int.class, double.class, String.class)etc. If your method is not public usegetDeclaredMethod()instead.But honestly your solution sounds strange. As far as I understand you actually save in DB kind of script and then run it. If so use ready-to-use scripting engine. For example java 1.6 and higher has built-in JavaScript interpreter (see ScriptEngineManager). You can generate javascripts and then run them. It is much easier than create very limited script interpreter yourself.