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
Pythonfrom 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"))Explore class relationships in the OOP Playground