-
Book Overview & Buying
-
Table Of Contents
Python Object-Oriented Programming - Fifth Edition
By :
Almost all the examples so far have included type hints. We’ve used them for argument values in class methods. We’ve used them for return types of methods, too.
Consider a class model like the one in Figure 7.1:
We’ve defined an abstract class, Polygon, and several concrete classes, Point, Rectangle, Square, and Field. We’ve referred to two built-in classes, list and float.
It’s possible, using UML, to carefully annotate the diagram with enough graphic details to make the attribute definitions redundant. Doing this can clutter the diagram with boxes and text, making it difficult to interpret.
It seems much more clear to capture the essential relationships with Python type hints than visual cues. Text such as points: list[Point] seems clear enough to help understand what a Polygon is. The...