From the course: Python: Design Patterns
Unlock this course with a free trial
Join today to access over 24,600 courses taught by industry experts.
Bridge example - Python Tutorial
From the course: Python: Design Patterns
Bridge example
- [Instructor] Let's first define our implementation-specific classes. The first one is DrawingAPIOne, it has a method called draw_circle, and accepts three arguments, x-coordinate, y-coordinate, and radius. It prints a message saying, "API 1 drawing a circle at coordinate x and y with radius." There's another implementation-specific class we need to define, DrawingAPITwo. We'll start with the method by typing def. The name of the method is draw_circle. Its arguments are self, x, y, and radius. The interface is the same, but the implementation will be different. Type print. We'll Copy, Paste. The difference in the implementation lies in the message to be printed. So instead of API 1, we'll say API 2. Now let's define our implementation-independent class Circle. How to draw a circle is implementation-dependent, but some things are implementation-independent when defining a Circle. The very first part of the Circle class definition is initializing its attributes. We have x-coordinate…
Contents
-
-
-
-
-
(Locked)
Decorator1m 5s
-
(Locked)
Decorator example4m 43s
-
(Locked)
Solution: Decorator1m 55s
-
Proxy1m 22s
-
(Locked)
Proxy example5m 23s
-
(Locked)
Adapter48s
-
(Locked)
Adapter example6m 16s
-
(Locked)
Composite1m 21s
-
(Locked)
Composite example5m 25s
-
Solution: Composite1m 44s
-
(Locked)
Bridge1m 14s
-
(Locked)
Bridge example5m 31s
-
(Locked)
-
-
-