-
Notifications
You must be signed in to change notification settings - Fork 2
/
prototype.dart
57 lines (44 loc) · 1.1 KB
/
prototype.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
abstract class Shape {
Shape clone();
void display();
}
class Circle implements Shape {
String color;
Circle({required this.color});
@override
Circle clone() {
return Circle(color: color);
}
@override
void display() {
print('Circle with color: $color');
}
}
class Square implements Shape {
String texture;
Square({required this.texture});
@override
Square clone() {
return Square(texture: texture);
}
@override
void display() {
print('Square with texture: $texture');
}
}
void main() {
// Create original objects
Circle circle = Circle(color: 'red');
Square square = Square(texture: 'brick');
// Display original objects
circle.display(); // Output: Circle with color: red
square.display(); // Output: Square with texture: brick
// Clone and modify objects
Circle circleClone = circle.clone();
circleClone.color = 'blue';
Square squareClone = square.clone();
squareClone.texture = 'wood';
// Display cloned objects
circleClone.display(); // Output: Circle with color: blue
squareClone.display(); // Output: Square with texture: wood
}