Motivation
- Organising code, grouping together relevant functionality
- "Encapsulation": having data and its behaviour/logic together
- example: simulation class, all parameters together rather than reading from global state
- Abstraction: Hide the implementation details so other parts of the code don't need to change
- Possibly have two examples showing different benefits (Could be
Person class from Loveleen's lecture)
Syntax
- Use one of the examples above.
- Start by showing usage (constructing and accessing attributes).
- Show syntax: class keyword, constructor
- Show syntax and usage: methods
Homework
Show an example of a run_simulation function. Create a class that collects the simulation parameters and has a run() method.
Motivation
Personclass from Loveleen's lecture)Syntax
Homework
Show an example of a
run_simulationfunction. Create a class that collects the simulation parameters and has arun()method.