notesonly.in

One notebook for every subject — open it anywhere.

Log in

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.

← Back to topics for Engineering