Skip to content

Data structures

Learning outcomes

  • Practice to use classes for expression
  • Practice to use classes for type safety
  • Practice to use composition for a 'has-a' relationship

Why?

You want to model the real world. The real world consists out of things. You need to convert those things into code.

You want to use data structures.

Good data structures

Good data structures:

Good example data structures are built-in data structures.

Discussion

  • Structures increase expressiveness of code
  • The design of data structures has implications
  • Structures are useful to bundle data
  • It is rare that structures match the real world

structure versus class

Parameter structure class
Python keyword class class
R object type S3 class S4, R5, R6
All states are valid Yes No
Maintains a valid state No Yes
Example A number for an x coordinate A string for a DNA sequence
Invalid when Never Sequence holds an invalid nucleotide letter