ITKokka
Lesson 1 ยท Note 5

Abstraction

๐Ÿ“Œ The Short Note

Download

๐Ÿ“– Explanation

Abstraction

Abstraction means hiding unnecessary internal complexity, and showing only what is needed to use something.

  • Hide the complexity
  • Show simple controls

Real World Example: TV and Remote

Example: TV and Remote

A TV does complex things inside: process signals, control display pixels, manage audio circuits, decode video data. As a user, you don't ask:

  • How are pixels controlled?
  • How is video decoded?
  • How do audio circuits work?

Instead, you just get simple controls: turnOn(), changeChannel(), increaseVolume(). Press a button on the remote, and the complex internal steps run on their own.

Abstraction in Java

Code Example
class TV {
    public void turnOn() {
        // turn on TV
    }
    public void changeChannel(int ch) {
        // change channel
    }
    private void updateDisplay() {
        // complex internal operation
    }
}

Public vs Private

  • public: accessible from outside the class. Shows simple actions to the user, this is what turnOn() and changeChannel() are for.
  • private: only accessible inside the class. Hides internal complexity, this is where updateDisplay() and other internal steps live.

Class Diagram

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚              TV               โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ + turnOn(): void              โ”‚
โ”‚ + changeChannel(ch): void     โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ - updateDisplay(): void       โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

+ marks the public methods a user can call. - marks the private methods hidden inside the class, doing the complex work behind the scenes.

Key Idea: Abstraction = Hide Complexity + Show Essentials.

Exam Focus Points

  • Abstraction hides implementation details, exposing only what the user needs to interact with an object.
  • Public methods form the simple interface; private methods carry out the hidden internal work.
  • Abstraction and Encapsulation are related but different: Encapsulation protects data, Abstraction hides complexity.

Summary

  • Abstraction hides unnecessary internal complexity from the user.
  • Simple, public actions (turnOn(), changeChannel()) are exposed; complex internal steps stay private.
  • The user only needs to know what an action does, not how it works internally.
  • Abstraction = Hide Complexity + Show Essentials.
Share:
โ† EncapsulationInheritance โ†’