Topic 3.1 Notes – Abstraction and Program Design
What Abstraction Is
Abstraction means reducing complexity by focusing on the important idea and hiding unnecessary details.
In Java, you use abstraction when:
- You create a class to represent a real-world idea
- You define attributes to store data
- You write methods to represent behaviors
The goal is simple: someone should be able to use your class knowing what it does, not how it does it.
There are two major types you need to know:
- Data abstraction → organizing and naming information
- Procedural abstraction → organizing and naming processes
These work together inside classes.
Data Abstraction
Data abstraction separates what a piece of data represents from how it is stored internally.
When you declare variables in a class, you’re creating abstractions for data.
Attributes
An attribute is a variable declared in a class outside any constructor or method. It represents the state of an object.
There are two kinds.
Instance Variables vs Class Variables
| Instance Variable | Class Variable | |
|---|---|---|
| Keyword | No static |
Uses static |
| Ownership | Each object has its own copy | One copy shared by all objects |
| Purpose | Stores data unique to each object | Stores data common to all objects |
| Example | private int score; |
private static int totalPlayers; |
If you create three Player objects:
- Each has its own
score - All share the same
totalPlayers
Picture three separate Player objects, each with its own score, all connected to one shared totalPlayers variable in the class:
Instance vs. static variables in a Player class
On tests, students mix these up. If the value should be different per object, it must be an instance variable.
Why Data Abstraction Matters
- Fields are usually
privateso outside code cannot directly change them. - You can change how data is stored later without breaking other code.
- It prevents accidental misuse of internal data.
If you make fields public, you’re breaking abstraction because outside code can mess with your internal state.
Procedural Abstraction
Procedural abstraction gives a name to a process. In Java, that process is a method.
When you call a method, you rely on:
- The method name
- Its parameters
- Its return type
- What it promises to do
You do not need to know how it works inside.
Method Decomposition
Large behaviors should be broken into smaller methods.
Instead of one long method that:
- calculates
- formats
- prints
- updates data
You split it into smaller pieces:
- Calculate result
- Format result
- Display result
Each method has one clear job. This is called method decomposition.
On the FRQ, graders reward this. A giant 40-line method usually signals poor abstraction.
Parameters and Generalization
Parameters allow a method to work with different inputs.
Without parameters:
- You repeat similar code over and over.
With parameters:
- One method handles many cases.
For example, a method like:
public double applyDiscount(double price, double rate)
works for any price and any discount rate.
This increases code reuse, which reduces complexity.
Changing Internals Safely
If a method’s signature and behavior stay the same, you can rewrite its internal code without affecting the rest of the program.
That’s the power of procedural abstraction. The outside world depends on what the method does, not how.
Designing a Class Using Abstraction
Before writing code, you should design the class clearly.
You must be able to represent the design:
- In natural language
- Or in a diagram showing:
- Class name
- Attributes
- Methods
Here’s what a simple design diagram looks like for a Book class:

Simple class diagram for Book
This diagram separates the private instance variables from the public methods. That visual structure reinforces one of the core ideas of abstraction: data is hidden, behavior is exposed.
When designing a class:
- Identify the main object (the class).
- Decide what data it must store.
- Decide what behaviors it must perform.
- Keep attributes private.
- Provide public methods to interact with the object.
Good abstraction means:
- Everything in the class belongs together.
- Each method has one clear purpose.
- Internal details stay hidden.
If someone can correctly use your class without seeing the code inside, you designed it well.