Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Robert Richardson   on Aug 07 In Java Category.

  
Question Answered By: Johnathan Nelson   on Aug 07

if the formula  has already been generated and validated, you need a parser not an interpreter to do the calculation. this pattern  only interprets the expression, you need another process to actually perform the operation / calculation on the interpreted expression. (this is arguable as both can be implemented under the same pattern)



the expression  could be parsed by a composite process to generate a binary tree (class hierarchy) like:



addition node |--- right= base salary

|--- operation = +

|--- left = multiplication node |--- right = EdutationFactor

|--- op = *

|--- left = 2.5 (literal / value)



but if this is only to validate the expression, it is the correct pattern to use, however is not going to fully do the job.



to briefly answer your questions:



1) possibly yes, you have the condition  and the expression(formula) that is generated from it

2) the context  could carry the rules such as the mapping between education factor and education that is coming from condition and so on

and also the client  can be the builder process/pattern that takes the condition and generates the expression

3) I have seen that something similar to the coefficient has been wrapped in a literal expression

4) I didn't get this question



to complete the calculation you need to generate the class hierarchy from your expression (start of my email)



others might argue that you could find alternative patterns for simplicity (spc composite pattern) which could be a valid point but I'd like to mention that your approach resembles how the OCL mathematical expressions are interpreted and mapped to rule engines but in a very very simpler way of course

Share: 

 

This Question has 3 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Problem with interpreter Pattern Or get search suggestion and latest updates.


Tagged: