Created
April 29, 2020 11:22
-
-
Save ashishkarki/fe40e7b8c2b90ef9d841ddafa5c11bcf to your computer and use it in GitHub Desktop.
dart-mixin-example1.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:math'; | |
mixin Area { | |
double getSquareArea(double side) { | |
return side * side; | |
} | |
double getCircleArea(double radius) { | |
return pi * radius * radius; | |
} | |
} | |
class Shapes with Area { | |
final double side; | |
final double radius; | |
const Shapes({ | |
this.side, | |
this.radius, | |
}); | |
double get squareArea => getSquareArea(side); | |
double get circleArea => getCircleArea(radius); | |
} | |
void main() { | |
final myShapes = Shapes(side: 10.0, radius: 5.0); | |
print( | |
'area of square is ${myShapes.squareArea} and circle is ${myShapes.circleArea}'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment