File tree 1 file changed +9
-4
lines changed
1 file changed +9
-4
lines changed Original file line number Diff line number Diff line change 1
1
# Chapter 7: Adapter and Facade design patterns
2
2
3
- I find myself using the adapter and facade patterns a lot when refactoring existing code. I know how I want it to work
4
- and I know how it works now, but I don't have time _ right now_ to fix it, so I add an adapter or facade to give it a clean
5
- interface and I only change the underlying code if I need to make significant changes to the underlying implementation.
6
-
7
3
> ** Adapter** : Converts the interface of a class into another interface the clients expect. Adapter lets classes work
8
4
> together that couldn't otherwise because of incompatible interfaces.
9
5
10
6
Compiled C modules in Python could be seen as examples of the adapter pattern: the Python implementation provides an
11
7
interface for python code to work with the incompatible underlying C code.
12
8
9
+ I find the adapter pattern useful when using external libraries like skipy spatial to support my own code.
10
+ I want features from the external library but I want to use it with my own objects and the library api doesnt
11
+ exactly fit my own. I write a small adapter to make the external library feel right and work well with my own
12
+ objects.
13
+
13
14
> ** Facade** : Provides a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level
14
15
> interface that makes the subsystem easier to use.
15
16
17
+ I also find myself using the adapter and facade patterns a lot when refactoring existing code. I know how I want it to work
18
+ and I know how it works now, but I don't have time _ right now_ to fix it, so I add an adapter or facade to give it a clean
19
+ interface and I make a plan to change the underlying code when it suits me.
20
+
16
21
The [ pathlib] ( https://github.com/python/cpython/blob/main/Lib/pathlib.py ) Python library provides a simplified
17
22
high-level cross-platform interface to methods and attributes from the ` os ` , ` sys ` , ` io ` and other modules.
18
23
You can’t perform that action at this time.
0 commit comments