Expressive data types¶
Learning objectives
- Practice to use classes for expression
- Practice to use classes for type safety
- Understand difference between composition and aggregation
- Practice to use composition for a 'has-a' relationship
What and why?¶
Data structure are 'ways to organize your data'.
- Bad way: put all in one
list
Good () data structures:
- Increase expressiveness
- Bundles data that belongs together
- Ensures correct state of the program
Increase expressiveness, in design¶
"A two-dimensional coordinate has a x and a y component"
classDiagram
class Particle{
-position
-velocity
}
Class diagram of a two-dimensional coordinate
Increase expressiveness, in code¶
Increase expressiveness, in code¶
Ah, it is a coordinat!
Exercise 1: design a struct (15 mins)¶
Learning objectives
- to convince design is trickier than one thinks
- to convince design has implications
- to grow appreciation of classes
What are their elements? Which do you guess are structures? Were they?
- A coordinate in 3 dimensions
- A velocity in two dimensions
- A circle
- A square