Wayfair L4(PM) role
I am writing this as very less information is available for wayfair karat assesment.
They are really particular about time. Each segment ends at given time whether you are done with your answer or not .
They have divided 1 hr in 3 category
20 min : about you and your project
20 min : System desgn questions
1) very large XML which cant fit in RAM, how to process
2) song streaming service , saves songs through a LB which uses consistent hashing. What need to be improved when users will stream songs
3) University social n/w based on university id, planning to role out internationally, what needs to be added\changed in backend
4) An app which takes a sports link , download article run machine learning to find any bias and reports back to user. running for 6 months, planning to expand what all the resources need to be added
20 min : codepad, coding or debugging
Review below code and point what can be changed from OOP and best practices perspective.
1class ShapesController {
2 private ObjectRepository<Shape> shapesRepo;
3 private DBConnection dbConnection;
4
5 public ShapesController() {
6 /* Database user is root with empty password */
7 dbC new DBConnection("root", "");
8
9 /* Used to retrieve shape objects */
10 shapesRepo = new ObjectRepository<Shape>("shapes");
11 }
12
13 /**
14 * Return the shape type as a string
15 *
16 * @route GET /shapes/:id/type
17 */
18 public Response type(Request req) {
19
20 Shape s = shapesRepo.find(req.id);
21
22 switch (s.type) {
23 case 1:
24 return new OkResponse("rectangle");
25 case 2:
26 return new OkResponse("circle");
27 case 3:
28 return new OkResponse("point");
29 default:
30 /* Invalid shape, fail */
31 return new BadRequestResponse();
32 }
33 }
34
35 /**
36 * Translate (move) a shape and return its new coordinates
37 *
38 * @route POST /shapes/:id/translate
39 */
40 public Response translate(Request req) {
41
42 Shape s = shapesRepo.find(req.id);
43 int xOffset = req.params.getInt("x-offset");
44 int yOffset = req.params.getInt("y-offset");
45
46 /* Translation */
47 s.setX(s.getX() + xOffset);
48 s.setY(s.getY() + yOffset);
49
50 /* Write the change to database */
51 dbConnection.update("UPDATE Shapes SET x=" + s.getX() + ",y=" + s.getY() + " WHERE id=" + req.id);
52 String shapeJson = "{\"x\":" + s.getX() + ",\"y\":" + s.getY() + "}";
53 return new OkResponse(shapeJson, "application/json");
54 }
55}
56
57
58class Shape {
59 public int type = 0;
60
61 /**
62 * Each shape has a corresponding bounding box that the rendering mechanism requires
63 * x and y refer to the location of the top left corner of the bounding box
64 * width and height are the width and height of the bounding box
65 */
66 protected int x, y, width, height;
67
68 public Shape(int x, int y, int width, int height) {
69 this.x = x;
70 this.y = y;
71 this.width = width;
72 this.height = height;
73 }
74
75 public int getX() {
76 return x;
77 }
78
79 public void setX(int x) {
80 this.x = x;
81 }
82
83 public int getY() {
84 return y;
85 }
86
87 public void setY(int y) {
88 this.y = y;
89 }
90
91 public int getWidth() {
92 return width;
93 }
94
95 public void setWidth(int width) {
96 this.width = width;
97 }
98
99 public int getHeight() {
100 return height;
101 }
102
103 public void setHeight(int height) {
104 this.height = height;
105 }
106
107 public double getArea() throws UnsupportedOperationException {
108 throw new UnsupportedOperationException("Computed by child classes");
109 }
110}
111
112
113class Rectangle extends Shape {
114 public Rectangle(int x, int y, int width, int height) {
115 super(x, y, width, height);
116 this.type = 1;
117 }
118
119 public double getArea() {
120 return width * height;
121 }
122}
123
124
125class Circle extends Shape {
126 public Circle(int x, int y, int width, int height) {
127 super(x, y, width, height);
128 this.type = 2;
129 }
130
131 public void setWidth(int width) {
132 /* Because circle is bound by a square */
133 this.width = width;
134 this.height = width;
135 }
136
137 public void setHeight(int height) {
138 /* Because circle is bound by a square */
139 this.height = height;
140 this.width = height;
141 }
142
143 public double getArea() {
144 /* Radius is width of bounding box / 2 */
145 return Math.PI * squareNum(width / 2);
146 }
147
148 public double squareNum(double x) {
149 return x * x;
150 }
151}
152
153
154class Point extends Shape {
155 /**
156 * Weight is used by the rendering mechanism to determine how large the
157 * point looks on the canvas
158 */
159 private int weight;
160
161 public Point(int x, int y, int weight) {
162 super(x, y, 0, 0);
163 this.type = 3;
164 this.weight = weight;
165 }
166
167 public double getArea() {
168 return 0;
169 }
170
171 public int getWeight() {
172 return weight;
173 }
174}