Some notes about the code
This is, of course a very elaborate design for a very simple assignment, and it is not optimal (Shape
assumes that all you need is @texture
and @size
, which might not be true to a lot of other shapes, and hold very little merit on its own - but I wanted to show some inheritance).
Note though that each method does only what it is supposed to do: create_shape
just creates a shape - it does not prompt the user, and it does not print anything; draw
only draws the relevant shape, etc. This makes the code more readable and maintainable.
Note also, that the class I don't want anyone to instantiate, I wrote as a module
rather than a class
. A module
cannot be instantiated, but can be included
or extended
in other classes. Also, its class methods (the ones starting with self.
) can be called like class methods in classes, so it is an easy way to create singleton methods.