Design: Modular Online Bookstore
Focus on backend code design applying SOLID principles. UI and database implementation details are out of scope.
Functional Requirements
Non-Functional Requirements
+-------------------+ +---------------------+ +---------------------+
| Book Catalog |<----->| Shopping Cart |<----->| Order Processing |
| Service | | Service | | Service |
+-------------------+ +---------------------+ +---------------------+
^ ^ ^
| | |
| | |
+-------------------+ +---------------------+ +---------------------+
| Payment Interface |<----->| Payment Implementations| | Notification Interface|
+-------------------+ +---------------------+ +---------------------+
^ ^
| |
+----------------+ +----------------+
| EmailNotifier | | SMSNotifier |
+----------------+ +----------------+interface Shape { double area(); }
class Rectangle implements Shape {
double width, height;
Rectangle(double w, double h) { width = w; height = h; }
public double area() { return width * height; }
}
class Circle implements Shape {
double radius;
Circle(double r) { radius = r; }
public double area() { return 3.14 * radius * radius; }
}
class AreaCalculator {
double totalArea(Shape[] shapes) {
double total = 0;
for (Shape s : shapes) total += s.area();
return total;
}
}
public class Main {
public static void main(String[] args) {
Shape[] shapes = { new Rectangle(2,3), new Circle(1) };
System.out.println(new AreaCalculator().totalArea(shapes));
}
}class Report {
void printReport(String type) {
if (type.equals("PDF")) { System.out.println("Printing PDF"); }
else if (type.equals("HTML")) { System.out.println("Printing HTML"); }
}
}Pass the test and this pattern moves unknown