Why use interpreter mode?
In some cases, we need to explain the class content. For example, we need to set "What day of the week ?" Translation into English, Japanese, and Thai respectively. The Interpreter mode is required.
What is interpreter mode?
Explains the content of a class and has multiple classes.
How to Use interpreter Mode
UML
Code:
Translate. Class
Public abstract class translate {public abstract void translate (context );}
Japan. Class
Public class Japanese extends translate {@ overridepublic void translate (context) {// todo auto-generated method stubsystem. out. println ("put" + context. getstr () + "translated into Japanese. ");}}
English. Class
Public class English extends translate {@ overridepublic void translate (context) {// todo auto-generated method stubsystem. out. println ("put" + context. getstr () + "translated into English. ");}}
Thai. Class
Public class Thai extends translate {@ overridepublic void translate (context) {// todo auto-generated method stubsystem. out. println ("put" + context. getstr () + "translated into Thai. ");}}
Context. Class
Public class context {private string STR; public context (string Str) {This. setstr (STR);} Public String getstr () {return STR;} public void setstr (string Str) {This. STR = STR ;}}
Client. Class
Public class client {public static void main (string [] ARGs) {context = new context ("what is today's day of the week? "); Translate = new Japanese (); translate. translate (context); translate = new English (); translate. translate (context); translate = new Thai (); translate. translate (context );}}
Final running result:
What day is today? Translated into Japanese.
What day is today? Translated into English.
What day is today? Translated into Thai.