Browse OOP reference
Objects and behaviour

What is abstraction?

On this page

An abstraction specifies the properties a caller may rely on while omitting details irrelevant to that task. A byte stream supports reading successive bytes from a socket or a file. Adding seek() to the general contract would exclude live streams that cannot rewind.

Worked example

Python
from io import BytesIO

def has_header(stream):
    return stream.read(3) == b"OBJ"

assert has_header(BytesIO(b"OBJ-file"))
assert not has_header(BytesIO(b"NO"))

PEP 544 on structural subtyping

Explore class relationships in the OOP Playground

What is duck typing?What are interfaces?What is object identity?

All OOP questions

Search ObjectFAQ