Graph.py - Patch67/Graphics GitHub Wiki

Compound design pattern.

An abstract Graph class is defined from which all other concrete classes derive. There are many cgraphics classes; line, circle, rectangle, text already implemented. In the future I want to add Polyline - but this is a trivial matter.

The important feature here is the Group class. This essentially contains a list of graphics classes. In practice the entire drawing is a group called main.

So to display the entire model you could simply call main.show(). Job done!

MVC

There is a strong temptation to start putting display code in here, i.e. show but according to [MVC](Model View Controller) display stuff goes into the View part not the Model part. You can put the save stuff here but not the display stuff.

abc

I have used abc (Abstract Base Class) here. PyCharm actually picks up that the show method is an abstract method and isn't implemented in all derived classes.