Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Instructions Create a simple server that uses simple design patterns Singleton: Wrap your main server instance as a singleton class Factory: Your server should parse

Instructions

Create a simple server that uses simple design patterns

  • Singleton: Wrap your main server instance as a singleton class

  • Factory: Your server should parse the routes and create a new Processor class depending on the route

  • Builder: The process method of your Processor should use the Builder pattern to create a response.

  • Lazy Loading: Lazy load users data on the first fetch.

Final response should be converted to Json

First parse url, then use factory to instantiate correct Processor class.

Processor Class

  • Has a process() method that returns a Response object

  • Add a subclass per endpoint

  • Takes a hashmap of key value args

  • User a factory to create these, based on the endpoint

Response Class

  • This class gets stringified

  • Needs a ResponseBuilder helper

  • Needs Date

  • Needs Params Map (String, String)

  • Needs response (Object, use Integer for ints)

  • Needs Response Code (String)

Server Class

  • Wrap simple server as a singleton, and give it a method

    • getInstance()

    • then run() to start

Endpoints

  • /math/add?a=&b=

    • return a + b

  • /math/add?a=

    • return a + 1

  • /posts?userid=

    • Single post

  • /users?userid=

    • Single userId

  • All others return the string ERROR as the response code.

Return Format

You will need a response class that looks like this before passing to JSON.

"{

"date": "2019-02-10T20:40:59.257Z", // time that this was generated

"params": {

"a": 2

},

responseCode: OK

"response": 3,

}"

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Students also viewed these Databases questions

Question

1. Which position would you take?

Answered: 1 week ago