Java implementation Interpreter (interpreter) mode

Source: Internet
Author: User

/** * Declares an abstract interpretation operation * @author stone * */public interface Interpreter {public void interpret (context context);  In practice, you can have a returned type that defines the data object that is interpreted}
public class Xmlsaxinterpreter implements interpreter {@Overridepublic void interpret (context context) { SYSTEM.OUT.PRINTLN ("XML SAX Interpreter:" + context.getdata ());}}
public class Xmldominterpreter implements interpreter {@Overridepublic void interpret (context context) { SYSTEM.OUT.PRINTLN ("XML DOM Interpreter:" + context.getdata ());}}
/** * Contains some information outside of the interpreter * @author Stone * */public class Context {private string Data;public string GetData () {return data;} public void SetData (String data) {this.data = data;}}

/* Interpreter (Interpreter) mode * Given a language, define a representation of its grammar and define an interpreter that uses that representation to interpret sentences in the language. is a behavioral pattern * application, such as compiler, regular expression, language specification ... * interpreter mode is used very little in actual system development because it can cause problems such as efficiency, performance, and maintenance, */public class Test {public static void main (string[] args) {Context context = new context (); Context.setdata ("XML data"); new Xmlsaxinterpreter (). interpret (context); new Xmldominterpreter (). interpret (context);}}



Java implementation Interpreter (interpreter) mode

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.