-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path01-bridge-pattern.py
More file actions
694 lines (515 loc) · 24.3 KB
/
01-bridge-pattern.py
File metadata and controls
694 lines (515 loc) · 24.3 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
"""Question: Implement the Bridge pattern to separate abstraction from implementation.
Create a drawing application where shapes (Circle, Rectangle) can be drawn
using different rendering engines (Vector, Raster) without tight coupling.
Requirements:
1. Create DrawingAPI interface for rendering implementations
2. Implement concrete drawing APIs (VectorRenderer, RasterRenderer)
3. Create abstract Shape class that uses DrawingAPI
4. Implement concrete shapes (Circle, Rectangle)
5. Demonstrate how shapes and renderers can vary independently
6. Show how new shapes or renderers can be added easily
Example usage:
vector_api = VectorRenderer()
circle = Circle(vector_api, 5, 10, 15)
circle.draw()
"""
# LEARNING CHALLENGE
#
# Before looking at any solution below, please try to solve this yourself first!
#
# Tips for success:
# - Read the question carefully
# - Think about what classes and methods you need
# - Start with a simple implementation
# - Test your code step by step
# - Don't worry if it's not perfect - learning is a process!
#
# Remember: The best way to learn programming is by doing, not by reading solutions!
#
# Take your time, experiment, and enjoy the learning process!
# Try to implement your solution here:
# (Write your code below this line)
# HINT SECTION (Only look if you're really stuck!)
#
# Think about:
# - What is the abstraction (shapes) and what is the implementation (renderers)?
# - How can you separate them so they can vary independently?
# - What interface do you need for the implementation side?
# - How does the abstraction use the implementation?
#
# Remember: Start simple and build up complexity gradually!
# ===============================================================================
# STEP-BY-STEP SOLUTION
# ===============================================================================
#
# CLASSROOM-STYLE WALKTHROUGH
#
# Let's solve this problem step by step, just like in a programming class!
# Each step builds upon the previous one, so you can follow along and understand
# the complete thought process.
#
# ===============================================================================
# Step 1: Import modules and create the implementation interface
# ===============================================================================
# Explanation:
# The Bridge pattern starts with defining the implementation interface.
# This interface will be used by different concrete implementations (renderers).
from abc import ABC, abstractmethod
class DrawingAPI(ABC):
"""Abstract interface for drawing implementations."""
@abstractmethod
def draw_circle(self, x: float, y: float, radius: float):
"""Draw a circle at given position with given radius."""
pass
@abstractmethod
def draw_rectangle(self, x: float, y: float, width: float, height: float):
"""Draw a rectangle at given position with given dimensions."""
pass
# What we accomplished in this step:
# - Created the implementation interface (DrawingAPI)
# - Defined abstract methods for drawing operations
# Step 2: Create concrete implementations (renderers)
# ===============================================================================
# Explanation:
# Concrete implementations provide specific ways to render shapes.
# Each renderer can have its own unique approach and features.
from abc import ABC, abstractmethod
class DrawingAPI(ABC):
"""Abstract interface for drawing implementations."""
@abstractmethod
def draw_circle(self, x: float, y: float, radius: float):
"""Draw a circle at given position with given radius."""
pass
@abstractmethod
def draw_rectangle(self, x: float, y: float, width: float, height: float):
"""Draw a rectangle at given position with given dimensions."""
pass
class VectorRenderer(DrawingAPI):
"""Vector-based rendering implementation."""
def draw_circle(self, x: float, y: float, radius: float):
"""Draw a circle using vector graphics."""
print(f"Vector: Drawing circle at ({x}, {y}) with radius {radius}")
print(f"Vector: Using smooth curves and scalable graphics")
def draw_rectangle(self, x: float, y: float, width: float, height: float):
"""Draw a rectangle using vector graphics."""
print(f"Vector: Drawing rectangle at ({x}, {y}) with size {width}x{height}")
print(f"Vector: Using crisp edges and infinite scalability")
class RasterRenderer(DrawingAPI):
"""Raster-based rendering implementation."""
def draw_circle(self, x: float, y: float, radius: float):
"""Draw a circle using raster graphics."""
print(f"Raster: Drawing circle at ({x}, {y}) with radius {radius}")
print(f"Raster: Using pixel-based rendering with anti-aliasing")
def draw_rectangle(self, x: float, y: float, width: float, height: float):
"""Draw a rectangle using raster graphics."""
print(f"Raster: Drawing rectangle at ({x}, {y}) with size {width}x{height}")
print(f"Raster: Using bitmap graphics with texture support")
# What we accomplished in this step:
# - Created VectorRenderer for vector-based graphics
# - Created RasterRenderer for pixel-based graphics
# - Each renderer has its own unique characteristics
# Step 3: Create the abstraction base class
# ===============================================================================
# Explanation:
# The abstraction defines the interface that clients use.
# It maintains a reference to an implementation object and delegates work to it.
from abc import ABC, abstractmethod
class DrawingAPI(ABC):
"""Abstract interface for drawing implementations."""
@abstractmethod
def draw_circle(self, x: float, y: float, radius: float):
"""Draw a circle at given position with given radius."""
pass
@abstractmethod
def draw_rectangle(self, x: float, y: float, width: float, height: float):
"""Draw a rectangle at given position with given dimensions."""
pass
class VectorRenderer(DrawingAPI):
"""Vector-based rendering implementation."""
def draw_circle(self, x: float, y: float, radius: float):
"""Draw a circle using vector graphics."""
print(f"Vector: Drawing circle at ({x}, {y}) with radius {radius}")
print(f"Vector: Using smooth curves and scalable graphics")
def draw_rectangle(self, x: float, y: float, width: float, height: float):
"""Draw a rectangle using vector graphics."""
print(f"Vector: Drawing rectangle at ({x}, {y}) with size {width}x{height}")
print(f"Vector: Using crisp edges and infinite scalability")
class RasterRenderer(DrawingAPI):
"""Raster-based rendering implementation."""
def draw_circle(self, x: float, y: float, radius: float):
"""Draw a circle using raster graphics."""
print(f"Raster: Drawing circle at ({x}, {y}) with radius {radius}")
print(f"Raster: Using pixel-based rendering with anti-aliasing")
def draw_rectangle(self, x: float, y: float, width: float, height: float):
"""Draw a rectangle using raster graphics."""
print(f"Raster: Drawing rectangle at ({x}, {y}) with size {width}x{height}")
print(f"Raster: Using bitmap graphics with texture support")
class Shape(ABC):
"""Abstract shape class that uses DrawingAPI."""
def __init__(self, drawing_api: DrawingAPI):
"""Initialize shape with a drawing API implementation."""
self.drawing_api = drawing_api
@abstractmethod
def draw(self):
"""Draw the shape using the drawing API."""
pass
@abstractmethod
def resize(self, factor: float):
"""Resize the shape by given factor."""
pass
# What we accomplished in this step:
# - Created abstract Shape class that holds a DrawingAPI reference
# - Defined abstract methods for shape operations
# - Established the bridge between abstraction and implementation
# Step 4: Create concrete shape implementations
# ===============================================================================
# Explanation:
# Concrete shapes implement the abstraction interface and use the
# implementation (DrawingAPI) to perform actual drawing operations.
from abc import ABC, abstractmethod
class DrawingAPI(ABC):
"""Abstract interface for drawing implementations."""
@abstractmethod
def draw_circle(self, x: float, y: float, radius: float):
"""Draw a circle at given position with given radius."""
pass
@abstractmethod
def draw_rectangle(self, x: float, y: float, width: float, height: float):
"""Draw a rectangle at given position with given dimensions."""
pass
class VectorRenderer(DrawingAPI):
"""Vector-based rendering implementation."""
def draw_circle(self, x: float, y: float, radius: float):
"""Draw a circle using vector graphics."""
print(f"Vector: Drawing circle at ({x}, {y}) with radius {radius}")
print(f"Vector: Using smooth curves and scalable graphics")
def draw_rectangle(self, x: float, y: float, width: float, height: float):
"""Draw a rectangle using vector graphics."""
print(f"Vector: Drawing rectangle at ({x}, {y}) with size {width}x{height}")
print(f"Vector: Using crisp edges and infinite scalability")
class RasterRenderer(DrawingAPI):
"""Raster-based rendering implementation."""
def draw_circle(self, x: float, y: float, radius: float):
"""Draw a circle using raster graphics."""
print(f"Raster: Drawing circle at ({x}, {y}) with radius {radius}")
print(f"Raster: Using pixel-based rendering with anti-aliasing")
def draw_rectangle(self, x: float, y: float, width: float, height: float):
"""Draw a rectangle using raster graphics."""
print(f"Raster: Drawing rectangle at ({x}, {y}) with size {width}x{height}")
print(f"Raster: Using bitmap graphics with texture support")
class Shape(ABC):
"""Abstract shape class that uses DrawingAPI."""
def __init__(self, drawing_api: DrawingAPI):
"""Initialize shape with a drawing API implementation."""
self.drawing_api = drawing_api
@abstractmethod
def draw(self):
"""Draw the shape using the drawing API."""
pass
@abstractmethod
def resize(self, factor: float):
"""Resize the shape by given factor."""
pass
class Circle(Shape):
"""Circle shape implementation."""
def __init__(self, drawing_api: DrawingAPI, x: float, y: float, radius: float):
"""Initialize circle with position and radius."""
super().__init__(drawing_api)
self.x = x
self.y = y
self.radius = radius
def draw(self):
"""Draw the circle using the drawing API."""
print(f"Circle: Preparing to draw at ({self.x}, {self.y}) with radius {self.radius}")
self.drawing_api.draw_circle(self.x, self.y, self.radius)
def resize(self, factor: float):
"""Resize the circle by changing its radius."""
self.radius *= factor
print(f"Circle: Resized to radius {self.radius}")
class Rectangle(Shape):
"""Rectangle shape implementation."""
def __init__(self, drawing_api: DrawingAPI, x: float, y: float, width: float, height: float):
"""Initialize rectangle with position and dimensions."""
super().__init__(drawing_api)
self.x = x
self.y = y
self.width = width
self.height = height
def draw(self):
"""Draw the rectangle using the drawing API."""
print(f"Rectangle: Preparing to draw at ({self.x}, {self.y}) with size {self.width}x{self.height}")
self.drawing_api.draw_rectangle(self.x, self.y, self.width, self.height)
def resize(self, factor: float):
"""Resize the rectangle by scaling its dimensions."""
self.width *= factor
self.height *= factor
print(f"Rectangle: Resized to {self.width}x{self.height}")
# What we accomplished in this step:
# - Created Circle class with position and radius
# - Created Rectangle class with position and dimensions
# - Both shapes use the DrawingAPI to perform actual rendering
# Step 5: Add advanced renderer with additional features
# ===============================================================================
# Explanation:
# Let's add a more advanced renderer to show how easily new implementations
# can be added without affecting existing shapes or other renderers.
from abc import ABC, abstractmethod
class DrawingAPI(ABC):
"""Abstract interface for drawing implementations."""
@abstractmethod
def draw_circle(self, x: float, y: float, radius: float):
"""Draw a circle at given position with given radius."""
pass
@abstractmethod
def draw_rectangle(self, x: float, y: float, width: float, height: float):
"""Draw a rectangle at given position with given dimensions."""
pass
class VectorRenderer(DrawingAPI):
"""Vector-based rendering implementation."""
def draw_circle(self, x: float, y: float, radius: float):
"""Draw a circle using vector graphics."""
print(f"Vector: Drawing circle at ({x}, {y}) with radius {radius}")
print(f"Vector: Using smooth curves and scalable graphics")
def draw_rectangle(self, x: float, y: float, width: float, height: float):
"""Draw a rectangle using vector graphics."""
print(f"Vector: Drawing rectangle at ({x}, {y}) with size {width}x{height}")
print(f"Vector: Using crisp edges and infinite scalability")
class RasterRenderer(DrawingAPI):
"""Raster-based rendering implementation."""
def draw_circle(self, x: float, y: float, radius: float):
"""Draw a circle using raster graphics."""
print(f"Raster: Drawing circle at ({x}, {y}) with radius {radius}")
print(f"Raster: Using pixel-based rendering with anti-aliasing")
def draw_rectangle(self, x: float, y: float, width: float, height: float):
"""Draw a rectangle using raster graphics."""
print(f"Raster: Drawing rectangle at ({x}, {y}) with size {width}x{height}")
print(f"Raster: Using bitmap graphics with texture support")
class OpenGLRenderer(DrawingAPI):
"""OpenGL-based 3D rendering implementation."""
def draw_circle(self, x: float, y: float, radius: float):
"""Draw a circle using OpenGL."""
print(f"OpenGL: Rendering 3D circle at ({x}, {y}) with radius {radius}")
print(f"OpenGL: Using hardware acceleration and shaders")
print(f"OpenGL: Applying lighting and shadow effects")
def draw_rectangle(self, x: float, y: float, width: float, height: float):
"""Draw a rectangle using OpenGL."""
print(f"OpenGL: Rendering 3D rectangle at ({x}, {y}) with size {width}x{height}")
print(f"OpenGL: Using GPU-accelerated rendering pipeline")
print(f"OpenGL: Applying advanced material properties")
class Shape(ABC):
"""Abstract shape class that uses DrawingAPI."""
def __init__(self, drawing_api: DrawingAPI):
"""Initialize shape with a drawing API implementation."""
self.drawing_api = drawing_api
@abstractmethod
def draw(self):
"""Draw the shape using the drawing API."""
pass
@abstractmethod
def resize(self, factor: float):
"""Resize the shape by given factor."""
pass
class Circle(Shape):
"""Circle shape implementation."""
def __init__(self, drawing_api: DrawingAPI, x: float, y: float, radius: float):
"""Initialize circle with position and radius."""
super().__init__(drawing_api)
self.x = x
self.y = y
self.radius = radius
def draw(self):
"""Draw the circle using the drawing API."""
print(f"Circle: Preparing to draw at ({self.x}, {self.y}) with radius {self.radius}")
self.drawing_api.draw_circle(self.x, self.y, self.radius)
def resize(self, factor: float):
"""Resize the circle by changing its radius."""
self.radius *= factor
print(f"Circle: Resized to radius {self.radius}")
class Rectangle(Shape):
"""Rectangle shape implementation."""
def __init__(self, drawing_api: DrawingAPI, x: float, y: float, width: float, height: float):
"""Initialize rectangle with position and dimensions."""
super().__init__(drawing_api)
self.x = x
self.y = y
self.width = width
self.height = height
def draw(self):
"""Draw the rectangle using the drawing API."""
print(f"Rectangle: Preparing to draw at ({self.x}, {self.y}) with size {self.width}x{self.height}")
self.drawing_api.draw_rectangle(self.x, self.y, self.width, self.height)
def resize(self, factor: float):
"""Resize the rectangle by scaling its dimensions."""
self.width *= factor
self.height *= factor
print(f"Rectangle: Resized to {self.width}x{self.height}")
# What we accomplished in this step:
# - Added OpenGLRenderer with advanced 3D capabilities
# - Showed how new implementations can be added easily
# - Existing shapes work with new renderer without modification
# Step 6: Test the complete Bridge pattern implementation
# ===============================================================================
# Explanation:
# Let's test our Bridge pattern implementation to show how shapes and
# renderers can vary independently and be combined in any way.
from abc import ABC, abstractmethod
class DrawingAPI(ABC):
"""Abstract interface for drawing implementations."""
@abstractmethod
def draw_circle(self, x: float, y: float, radius: float):
"""Draw a circle at given position with given radius."""
pass
@abstractmethod
def draw_rectangle(self, x: float, y: float, width: float, height: float):
"""Draw a rectangle at given position with given dimensions."""
pass
class VectorRenderer(DrawingAPI):
"""Vector-based rendering implementation."""
def draw_circle(self, x: float, y: float, radius: float):
"""Draw a circle using vector graphics."""
print(f"Vector: Drawing circle at ({x}, {y}) with radius {radius}")
print(f"Vector: Using smooth curves and scalable graphics")
def draw_rectangle(self, x: float, y: float, width: float, height: float):
"""Draw a rectangle using vector graphics."""
print(f"Vector: Drawing rectangle at ({x}, {y}) with size {width}x{height}")
print(f"Vector: Using crisp edges and infinite scalability")
class RasterRenderer(DrawingAPI):
"""Raster-based rendering implementation."""
def draw_circle(self, x: float, y: float, radius: float):
"""Draw a circle using raster graphics."""
print(f"Raster: Drawing circle at ({x}, {y}) with radius {radius}")
print(f"Raster: Using pixel-based rendering with anti-aliasing")
def draw_rectangle(self, x: float, y: float, width: float, height: float):
"""Draw a rectangle using raster graphics."""
print(f"Raster: Drawing rectangle at ({x}, {y}) with size {width}x{height}")
print(f"Raster: Using bitmap graphics with texture support")
class OpenGLRenderer(DrawingAPI):
"""OpenGL-based 3D rendering implementation."""
def draw_circle(self, x: float, y: float, radius: float):
"""Draw a circle using OpenGL."""
print(f"OpenGL: Rendering 3D circle at ({x}, {y}) with radius {radius}")
print(f"OpenGL: Using hardware acceleration and shaders")
print(f"OpenGL: Applying lighting and shadow effects")
def draw_rectangle(self, x: float, y: float, width: float, height: float):
"""Draw a rectangle using OpenGL."""
print(f"OpenGL: Rendering 3D rectangle at ({x}, {y}) with size {width}x{height}")
print(f"OpenGL: Using GPU-accelerated rendering pipeline")
print(f"OpenGL: Applying advanced material properties")
class Shape(ABC):
"""Abstract shape class that uses DrawingAPI."""
def __init__(self, drawing_api: DrawingAPI):
"""Initialize shape with a drawing API implementation."""
self.drawing_api = drawing_api
@abstractmethod
def draw(self):
"""Draw the shape using the drawing API."""
pass
@abstractmethod
def resize(self, factor: float):
"""Resize the shape by given factor."""
pass
class Circle(Shape):
"""Circle shape implementation."""
def __init__(self, drawing_api: DrawingAPI, x: float, y: float, radius: float):
"""Initialize circle with position and radius."""
super().__init__(drawing_api)
self.x = x
self.y = y
self.radius = radius
def draw(self):
"""Draw the circle using the drawing API."""
print(f"Circle: Preparing to draw at ({self.x}, {self.y}) with radius {self.radius}")
self.drawing_api.draw_circle(self.x, self.y, self.radius)
def resize(self, factor: float):
"""Resize the circle by changing its radius."""
self.radius *= factor
print(f"Circle: Resized to radius {self.radius}")
class Rectangle(Shape):
"""Rectangle shape implementation."""
def __init__(self, drawing_api: DrawingAPI, x: float, y: float, width: float, height: float):
"""Initialize rectangle with position and dimensions."""
super().__init__(drawing_api)
self.x = x
self.y = y
self.width = width
self.height = height
def draw(self):
"""Draw the rectangle using the drawing API."""
print(f"Rectangle: Preparing to draw at ({self.x}, {self.y}) with size {self.width}x{self.height}")
self.drawing_api.draw_rectangle(self.x, self.y, self.width, self.height)
def resize(self, factor: float):
"""Resize the rectangle by scaling its dimensions."""
self.width *= factor
self.height *= factor
print(f"Rectangle: Resized to {self.width}x{self.height}")
print("=== Testing Bridge Pattern ===\n")
# Create different renderers
vector_api = VectorRenderer()
raster_api = RasterRenderer()
opengl_api = OpenGLRenderer()
print("1. Circle with Vector Renderer:")
circle1 = Circle(vector_api, 10, 20, 5)
circle1.draw()
print()
print("2. Circle with Raster Renderer:")
circle2 = Circle(raster_api, 15, 25, 8)
circle2.draw()
print()
print("3. Rectangle with OpenGL Renderer:")
rect1 = Rectangle(opengl_api, 0, 0, 100, 50)
rect1.draw()
print()
print("4. Rectangle with Vector Renderer:")
rect2 = Rectangle(vector_api, 30, 40, 80, 60)
rect2.draw()
print()
print("5. Testing resize functionality:")
print("Before resize:")
circle1.draw()
print("\nAfter resize (factor 2.0):")
circle1.resize(2.0)
circle1.draw()
print()
print("6. Demonstrating independence - same shape, different renderers:")
shapes_with_different_renderers = [
Circle(vector_api, 50, 50, 10),
Circle(raster_api, 50, 50, 10),
Circle(opengl_api, 50, 50, 10)
]
for i, shape in enumerate(shapes_with_different_renderers, 1):
print(f"Same circle with renderer {i}:")
shape.draw()
print()
# What we accomplished in this step:
# - Tested all combinations of shapes and renderers
# - Demonstrated independent variation of abstractions and implementations
# - Showed how the same shape can use different renderers
# - Verified that resize functionality works correctly
# ===============================================================================
# CONGRATULATIONS!
#
# You've successfully completed the step-by-step Bridge pattern solution!
#
# Key concepts learned:
# - Bridge pattern structure and purpose
# - Separation of abstraction from implementation
# - Implementation interface (DrawingAPI) and concrete implementations
# - Abstract shape class and concrete shape implementations
# - Independent variation of abstractions and implementations
# - Easy extensibility for new shapes or renderers
#
# Benefits of the Bridge pattern:
# - Decouples abstraction from implementation
# - Both can vary independently
# - Easy to add new shapes or renderers
# - Promotes composition over inheritance
# - Reduces the number of classes needed
#
# Try it yourself:
# 1. Start with Step 1 and code along
# 2. Test each step before moving to the next
# 3. Understand WHY each step is necessary
# 4. Experiment with modifications (try adding a Triangle shape or SVG renderer!)
#
# Remember: The best way to learn is by doing!
# ===============================================================================