Chapter 3. Abstraction and encapsulation
This chapter covers
- Understanding the value of abstraction in large systems
- Encapsulating related code into classes
- Using encapsulation, inheritance, and composition in Python
- Recognizing programming styles in Python
You’ve already seen that organizing your code into functions, classes, and modules is a great way to separate concerns, but you can also use these techniques to separate complexity in your code. Because it’s difficult to remember every detail about your software at all times, in this chapter you’ll learn to use abstraction and encapsulation to create levels of granularity in your code so you can worry about the details only when you need to.
When you hear the word abstract, what do you think of? Usually a Jackson Pollock painting or a Calder sculpture runs through my mind. Abstract art is marked by a freedom from concrete form, often only suggestive of a specific subject. Abstraction, then, would be the process of taking something concrete and stripping it of specifics. When speaking about abstraction in software, this is exactly right!