课程: Python: Design Patterns (2021)
今天就学习课程吧!
今天就开通帐号,24,700 门业界名师课程任您挑!
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 one drawing a circle at coordinate X and Y with radius. There is another implementation-specific class we need to define, DrawingAPITwo. We'll start with the method by typing D-E-F. The name of the method is draw_circle. It's 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 one, we'll say API two. 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…