Ensure a class has only one instance, and provide a global point of access to it. All of the Watson’s services has only a single instance, instantiated in service.js, which handles each user query as the request handler is wrapped in a Lambda.
The pattern relates to the design of Web applications. It provides a centralised entry point for handling requests. The chatbot front-end calls the same REST API that handles requests for all user queries and will receive varied JSON responses depending on the intent of the user.
Avoid coupling the sender of a request to its receiver by giving more than one object a chance to handle the request. Chain the receiving objects and pass the request along the chain until an object handles it. This pattern is incorporated in the the Lambda execution when hosted on the API Gateway on AWS.
Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation. A Java iterator pattern is used in the scripting of entity value generation. An iterator is applied over a linked list, which contains the entity values, to be appended onto the CSV output file.
Only execute an action on an object when the object is in a particular state. The chatbot service checks if the USER is correct (temporary implementation) before proceeding to call the Watson services. Also, the language of the user query is verified. If it is in German/French/Chinese, then it will not proceed with calling the Conversation service, otherwise will proceed to do so.