Software and abstraction
About this video
Software is a system of programs and data that reacts to events over time, so it involves far more complexity than a single script. Programmers manage that complexity with abstraction: functions abstract behavior, and classes and objects let us abstract data by bundling attributes and methods into custom types that mirror real-world things.
You'll be able to
- explain how software differs from a single program or script.
- define abstraction as hiding unnecessary details so we can focus on what matters.
- describe how classes bundle data (attributes) and behavior (methods).
Key words
- software
- A system of programs and data that work together over time.
- event
- Something that happens, like a button press or a timer running out, that software responds to.
- abstraction
- Hiding unnecessary details so we can focus on what matters.
- class
- A way to define our own custom data type that bundles data and behavior.
- attribute
- A piece of data that belongs to an object.
- method
- A behavior, or function, that belongs to an object.
Transcript
- [Trainer] Most of the code we've written comes in the form of programs and scripts, meaning they're sets of instructions that perform a specific job, but most of the technology we interact with comes in the form of software. Instead of a single program, software is a system of programs and data that work together over time.
For example, video editing software doesn't perform just one job. It performs many, like smoothing the audio, overlaying text, or adding transitions in between clips. The code that makes up a piece of software doesn't all execute at the same time. Instead, software reacts to events.
For example, when you open up a game, it doesn't just run through every possible thing that could happen in the game from start to finish, but rather it executes specific pieces of code in response to specific events. Like when the user presses a button, the game may change the character's direction.
Or when the character runs into an item, the game may enable a power up. Or when a timer runs out, the game may toggle the current mode. Ultimately, this means a piece of software has thousands of lines of code that manage tons of data and tons of functionality together.
As a programmer, then, how do we keep track of all that complexity in our heads? The answer is we don't. We use abstraction. In programming, abstraction is the process of hiding unnecessary details so we can focus on what matters. A function, for example, is a form of abstraction.
If I want to perform this task, I can just call this function. Assuming I trust the people I work with, I don't need to understand how this code works in order to use it. Functions, however, just let us abstract behavior. But in software, we also need to abstract data.
To make our code more intuitive to work with, we want our software to think about things the same way that humans do. So say I'm building the school management software. That software needs to represent real things like students, teachers, classrooms, assignments.
I can create a bunch of different data structures that group different bits of data, and I can create a bunch of modules that group a bunch of functions that perform a bunch of tasks. Does this work? Yes. But it's pretty challenging to work with as the size of our software grows.
Why not organize our code in a way that better mirrors the real world? Like a student has their own data, like their name, their email address, their course schedule, their grades, and each student can take actions, like enroll in a class or submit an assignment.
As we build out the rest of our school software, then, we can work with these higher-level concepts. We can think in terms of students, teachers, assignments, and classrooms, instead of arbitrary functions and variables. To achieve that abstraction in our code, we bundle data and behavior together using something called classes and objects.
This lets us define our own custom data types that come with their own data or attributes and behaviors or methods. To get started, we just need to learn how to write a class definition.
Video © Khan Academy, used under CC BY-NC-SA. Watch on Khan Academy. Puzzicle is not affiliated with Khan Academy.