A caller is code that asks a function or object to do something. An interface is what that caller can rely on: names, accepted inputs, results, state changes and expected failures. It need not be a special Python class. A short method name alone is not a complete interface.
Consider a counter used to track seats still available. reserve accepts a positive integer, removes that many seats when possible, and returns the remaining count. An invalid or excessive request raises ValueError without changing the count.
class Seats:
def __init__(self, available):
self._available = available
def reserve(self, count):
if type(count) is not int or count <= 0:
raise ValueError("count must be a positive integer")
if count > self._available:
raise ValueError("not enough seats")
self._available -= count
return self._available
seats = Seats(4)
print(seats.reserve(2))
try:
seats.reserve(3)
except ValueError as error:
print(error)
print(seats.reserve(1))
Output:
2
not enough seats
1
The first call leaves two seats. The second is rejected before subtraction; the final call therefore leaves one. The constructor in this example assumes a nonnegative integer; a reusable implementation should validate that assumption too. The exact type check deliberately excludes booleans, even though bool is a subclass of int in Python.
Abstraction selects the useful view: the caller requests a reservation rather than managing the subtraction. Encapsulation groups the state and operations and marks _available as internal. A leading underscore is a convention, not access control or security. These ideas reinforce each other, but describing the operation and organizing the state are distinct decisions. Changing the storage is safe for callers only if the promised behavior remains intact.