Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Classes #1

Open
ageorgou opened this issue May 26, 2022 · 0 comments
Open

Classes #1

ageorgou opened this issue May 26, 2022 · 0 comments

Comments

@ageorgou
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant