T
T
Tarasov Konstantin2014-07-09 23:34:43
Java
Tarasov Konstantin, 2014-07-09 23:34:43

How would it be more correct to separate the stages of parsing commands entered from the console?

There are two classes - parser and controller. I think everyone understands the scheme - the parser parses the string and, depending on this, tells the controller what to do. But the problem is this - the controller has a certain number of different methods, say method1, method2, and so on. And actually the question is - at what stage would it be more correct to determine which of the methods to call? If we completely entrust this work to the parser, then we will have to create as many rules as we have methods. Or, entrust this work to the controller and pass it the string name of the method, in which case we will have to organize a huge switch, but the code as a whole will turn out to be shorter. How to proceed?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey, 2014-07-09
Protko @Fesor

in a good way, the controller should decide what to do based on what the parser tells it to do, and delegate the work to the workers rather than doing it themselves. And yes, the parser should not know anything about how this or that state will be processed.

C
Calc, 2014-07-10
@Calc

The parser must return the data structure "necessary" to the controller, but the controller can decide what to do.
Look towards the State pattern if you don't like the big switch
en.wikipedia.org/wiki/%D0%A1%D0%BE%D1%81%D1%82%D0%...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question