Consider the following classes:
Of course, HTML has many more different elements. In the elements above, there is some duplication (in particular, the parent, x and y instance variables). Also, we'd like to be able to compute the position of any type of element, not just divs and be able to combine different elements in a tree.
Refactor the class hierarchy by introducing an abstract base class HTMLElement that divs, buttons, and spans are
subclasses of. Minimize code duplication and make sure that each element is
able to compute its position on the screen.
In order to get started more quickly, download the code for this exercise above (but don't look at the solution yet!).
Can you use a protocol class just as easily instead of an abstract base class? What would need to be changed in the code for this to work?
Compatible Python Versions: 3.10+