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.
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:
The links made explicit in CRC cards are helpful for designing database tables and avoiding many-to-many relationships when modelling your data (avoid co-dependent cards, ie. if
cow milking station has
cow as collaborator, and
cow milking station as a collaborator too).
Here is a database model for these cow related scenarios:
|id||needs milking||milking station id|
💡 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.
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
Stringclass has many methods to change it's characters, but always with string characters. Adding a fixnum to a string
"sting" + 2would be handling more than one state (and if you try that in the repl you'll get an error...)
TypeError (no implicit conversion of Integer into String)
🏆 I had my first stack overflow error!
🌊 How do you pronounce SQL: s-q-l or sequel? When someone suggested 'sea gull' I couldn't stop laughing!1
🌽 Fascinating to hear from Sainsbury's about their digital team: what they do with data, power generation, and cabbage tracking.
⚠️I keep forgetting how to run VSC from the command line when I restart the terminal :
P then select
Shell Command : Install 'code' in PATH
📝 everything comes back to hashes of arrays or arrays of hashes...
sequel or s-q-l are both totally fine! ↩