With String.format , there seems to be a big discovery for a software error that was not found at compile time. This can make correction errors more complex and / or take longer. This was a problem for me when I decided to fix it (or crack the solution). I came close, but I'm not close enough. For this problem, it is certainly overly designed. I understand that, but I just want to find a good compilation solution.
Further information can be found here. My question regarding
Main program
2 calculators. 1 Logical base. May be expanded to include other simple calculators.
I need 1 class to work with all operations ( listeners ) for any such simple calculator.
I decided to abstract the format string using Enums due to this reasoning - stack overflow.site/questions/86293 / .... Each expression will have a certain number of βdivisionsβ, and it will be in a more readable and reliable form.
Onclicklistener
I have a listener that needs to deal only with the logic of getting numbers from the user interface, doing the calculation and setting the result to the user interface. He does not need to know the format of the results. The solution must allow errors detected using compile time rather than runtime.
Now my implementation seems to be meeting some of these
@Override public void onClick(View v) { // Get number 1 and number 2. Perform operation via Strategy Pattern { // ISSUE This seems to be fine if I only cared about THIS class only dealing with one expression, but I want it to handle both (not at the same time though) // These seem too coupled right now. I just have both Expression and // DogeExpression here for now. But I do kind of like the the execution Expression.Number1.update(num1); // Enum Expression Expression.Number2.update(num2); Expression.Operator.update(operator.getSign()); Expression.Result.update(total); DogeExpression.Total.update(total); // Enum DogoExpression } UI.setResult(Expression.Update.print()); // UI.setResult(DogeExpression.Update.print()); // Switch to this for DogeExpression }
Problem
With OperationClick , I think this is only a problem related to how I created the project. I wanted to have several user interfaces that look, have slightly different controls, and act a little differently ...
- MainActivity : displays an enum expression string
- MainActivityDoge : displays the DogeExpression account assignment line
- MainActivity_X : displays an X_Expression enumeration bar, for example ... each user interface has the same buttons and each one is associated with an OperationClick
btnAdd.setOnClickListener(new OperationClick(Add).listenerOn(this)); btnSub.setOnClickListener(new OperationClick(Subtract).listenerOn(this)); btnMul.setOnClickListener(new OperationClick(Multiply).listenerOn(this)); btnDiv.setOnClickListener(new OperationClick(Divide).listenerOn(this));
My OperationClick class has my onClick(View v) code, and I don't want to duplicate it. I distracted the math logic using a strategy template. This class should only take care of how to perform mathematical operations. He does not have to care about how it will be displayed in the user interface, but he needs to assign / update an expression.
How can I achieve the above?
java enums string.format abstraction
Christopher rucinski
source share