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:
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
has cow milking station
as a collaborator too).
Here is a database model for these cow related scenarios:
Table: Cows ๐ฎ
id | needs milking | milking station id |
---|---|---|
1 | true | 1 |
Table: Cow Milking Stations ๐ผ
id |
---|
1 |
๐ก 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...)
TypeError (no implicit conversion of Integer into String)
Misc
๐ 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 :Command
+ Shift
+ 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!ย โฉ
Top comments (1)
JavaScript awaits you with hungry eyes...