Skip to content

Instantly share code, notes, and snippets.

@meowpunch
Created January 10, 2022 17:49
Show Gist options
  • Save meowpunch/52440fa59072c44e3dd6ccb60241f14e to your computer and use it in GitHub Desktop.
Save meowpunch/52440fa59072c44e3dd6ccb60241f14e to your computer and use it in GitHub Desktop.
Polymorphic Shape, Chapter 6: Objects and Data Structures, Clean Code, Robert C Martin
public class Square implements Shape {
private Point topLeft;
private double side;
public double area() {
return side * side;
}
}
public class Rectangle implements Shape {
private Point topLeft;
private double height;
private double width;
public double area() {
return height * width;
}
}
public class Circle implements Shape {
private Point center;
private double radius;
public final double PI = 3.141592653589793;
public double area() {
return PI * radius * radius;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment