Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save OsamaAldawoody/3cec55ba7435c691580bd0081111806d to your computer and use it in GitHub Desktop.
Save OsamaAldawoody/3cec55ba7435c691580bd0081111806d to your computer and use it in GitHub Desktop.
procedural || data structure - clean code book
void main() {
Square s = Square();
s.width = 10;
s.topLeft = Point(0,0);
print(Geometery.area(s));
print(Geometery.perimeter(s));
}
class Point{
int x,y;
Point(this.x,this.y);
}
class Square{
Point topLeft;
double width;
}
class Rectangle{
Point topLeft;
double width;
double height;
}
class EquilateralTriangle{
Point topHead;
double side;
double height;
}
class Circle{
Point centerPoint;
double radius;
}
class Geometery{
static final double PI = 3.1465165465;
static double area(Object shape){
if(shape is Square){
return shape.width * shape.width;
}else if(shape is Rectangle){
return shape.width * shape.height;
}else if(shape is Circle){
return PI * shape.radius * shape.radius;
}else if(shape is EquilateralTriangle){
return .5 * shape.side * shape.height;
}
throw Exception();
}
static double perimeter(Object shape){
if(shape is Square){
return shape.width * 4;
}else if(shape is Rectangle){
return (shape.width + shape.height) * 2;
}else if(shape is Circle){
return 2 * PI * shape.radius;
}else if(shape is EquilateralTriangle){
return shape.side * 3;
}
throw Exception();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment