Challenge: Singleton Pattern

In this challenge, you have to implement the singleton pattern to solve the given problem.

Problem statement

In this challenge, you have to implement a configuration that uses the singleton pattern. You are given a class ConfigureVals. Define it as follows:

  • It should have a constructor that defines the properties xpoint, ypoint, and shape.

  • The constructor should initialize xpoint, ypoint, and shape to 0, 0, and null if the values for these properties are not passed to the constructor.

  • Make sure that only a single instance of the class can be made by defining the function getConfiguration.

Input

The getConfiguration method invoked

Output

The instance created after the getConfiguration function is invoked

Sample input

getConfiguration({ xpoint: 8, ypoint : 9, shape : rectangle }); //first call

getConfiguration({ xpoint : 2, ypoint : 4, shape : circle }); //second call

Sample output

ConfigureVals { xpoint: 8, ypoint: 9, shape: 'rectangle' }

ConfigureVals { xpoint: 8, ypoint: 9, shape: 'rectangle' }

Challenge

Take a close look, and design a step-by-step solution before jumping on to the implementation. This problem is designed for your practice, so try to solve it on your own first. If you get stuck, you can always refer to the solution provided. Good Luck!

class ConfigureVals{
//write your code here
}

Let’s look at the solution in the next lesson.