Getters and setters

If we assume that people are using this script to do work, but we want to improve upon it by adding new features, such as preventing a temperature less than absolute zero, we need to make it easy for our users to deal with the change.

This is where getter and setter methods come in. Normally, the direct access to temp would be hidden behind these methods, so that the only interface to interact with temp would require a method call, as shown in following screenshot:

Getter and setter methods

On line 90, we have rewritten the Fahrenheit class to include a getter and setter; these are the only ways to interact with the temp ...

Get Learn Programming in Python with Cody Jackson now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.