Weeknotes - 04 Makers
Tags: bootcamp, beginners, database, sql
Published: 2019-06-24 06:21:09

---
title: Weeknotes - 04 Makers
published: true
description: Reflections on the past week at Makers Academy
tags: bootcamp, beginners, database, sql
series: Makers weeknotes
---

# Weeknotes - 04 Makers

This week was about demonstrating full control over database content, and expanding our webapp knowledge to include data storage.  Normally, if you want to store data you'd use a database where your data persists beyond shut-down and restart.  The data persisted so strongly that I was dreaming about databases.

## Class Responsibilty Collaborator Cards (CRCs)

CRCs are an aim to help programmers brainstorm the design of their software.  In a workshop, we were given a user story, interpreted the objects into cards with responsibilties listed on the left and collaborator classes listed on the right.  As we were given more user stories for the project we created more cards/responsbilities/collaborations.
 
>As a milk maid(?!)
>So that I can sell milk
>I want to see if a cow is ready to be milked

>...I want to dock a cow in the milking station

>...I want to milk a cow 

>...I want to know how many cows I have

Here are these user stories represented as CRC cards:

![](https://thepracticaldev.s3.amazonaws.com/i/0caplt3tyffbxuxn1esi.png)
![](https://thepracticaldev.s3.amazonaws.com/i/qdi7h85z2y2iz41ybfdr.png)

The links made explicit in CRC cards are helpful for designing database tables and avoiding [many-to-many](https://en.wikipedia.org/wiki/Many-to-many_(data_model)) relationships when modelling your data (avoid co-dependent cards, ie. if `cow milking station` has `cow` as collaborator, and `cow` has `cow milking station` as a collaborator too).

Here is a database model for these cow related scenarios:

#### Table: Cows :cow:
| id | needs milking | milking station id |
|-----|-----|-----|
| 1 | true | 1 |

#### Table: Cow Milking Stations :baby_bottle:
| id | 
|-----|
| 1 |

> :bulb: Where you have a many-to-many relationship, use a junction table to create a join between two one-to-many relationships instead.

Keeping CRC cards small (think index cards) helps you keep class responsbilities small and curb over-designing.

## Testing Relationships

One of the coaches shared with me a couple of clues to spot when to seperate responsibilities (and use dependency injection).
 - If you describe a method or a class using the word "and" that's a clue there's more than one responsibility
 - Another is if you notice a method or class managing more than one state.  For example Ruby's `String` class has many methods to change it's characters, but always with string characters. Adding a fixnum to a string `"sting" + 2` would be handling more than one state (and if you try that in the repl you'll get an error...)

 ```shell
 TypeError (no implicit conversion of Integer into String)
```


## Misc

:trophy: I had my first stack overflow error!
:ocean: How do you pronounce SQL: s-q-l or sequel? When someone suggested 'sea gull' I couldn't stop laughing![^*]
:corn: Fascinating to hear from Sainsbury's about their digital team: what they do with data, power generation, and cabbage tracking.
:warning:I keep forgetting how to run VSC from the command line when I restart the terminal :`Command` + `Shift` + `P` then select `Shell Command : Install 'code' in PATH`
:memo: everything comes back to hashes of arrays or arrays of hashes...

[^*]: sequel or s-q-l are both _totally_ fine!