Design patterns: singleton, factory, observer
Software Engineering · Engineering
Study notes
Implement a logging singleton in Python: class Logger with _instance = None; getInstance() creates once, returns always. Every module calls Logger.getInstance(), sharing one log file. A factory creates shapes: ShapeFactory.create('circle') returns Circle(), hiding construction. An observer notifies: button.attach(display) then button.click() triggers display.update() automatically.