Week 2 – the Oyster and the Mega-Class

Dear Week Two,

It’s hard for me to comprehend the path our relationship has taken. It started out so well, so bright. Two young hearts RSpec-in’ one another. How did it all turn so stormy, so terminal? It was a tempest. A tumultuous ride to the last.

I guess I’m supposed to say it’s me and not you. But it was so totally you. I hope you step on lego.

And in the words of Guybrush Threepwood, pirate heartthrob extraordinaire: you’re as repulsive as a monkey in a negligee.

Warmest regards,

Abigail

So this week’s project was a toughie. Our coach did warn us that many students look back on this week as containing some of their hardest days and boy am I hoping that’s true.

On first glance, the project brief didn’t sound too difficult – to design and build a program that emulated an Oystercard system. Users of ‘Oystercard’ needed to be able to touch in at a station, touch out at another station, update and check their balance, and view their journey history. On touching in/out the correct fare needed to be deducted.

Oh and then there was the fact that penalty fares needed to be applied if a touch in/out event had not occurred in the correct order. And min/max balances. And CSV files with station zone information needing to be formatted and referenced. And all of the edge cases. And all of the RSpec testing.

Ok, so maybe the project brief does sound a little tricky when I write it out like that. Scarily though, this is not what caused our cohort the most trouble. Dastardly as they are, the folks at Makers Academy requested that we cram all this multi-faceted functionality into one single ‘Oystercard’ class.

Now, looking back a couple of months, I probably wouldn’t have even flinched at this. One omniscient, omnipotent, omnipresent OMNITASTIC MEGA-CLASS? Yes please, thank you very much, that sounds terrific.

Two weeks into the course, this now sounds utterly terrifying. However, begrudgingly I must admit – there was some method to their madness:

  1. Trick us into committing this crime now (where it’s reasonably forgiving/lawless).
  2. Drag us kicking, screaming, wimpering through the brutal process of class extraction.
  3. Watch us re-emerge as scarred gnarled creatures, never to make the same mistake again.
  4. Like, ever.

Having experienced the trauma of trying to prize apart all the different concerns into separate classes with tests intact, I will never ever write code like I wrote code this week. I will remodel myself as a shining beacon of clarity and sense. For tonight and forever, Matthew, I’m going to be… the Single Responsibility Principle.

And I’m going to leave you hanging there! Turns out SRP is a PBD (pretty big deal) and featured heavily in our weekend challenge, so I’ll be discussing this (along with the ever-fabulous dependency injection) in my next Code Review post.

I know, I know. CONTAIN YOSELF.

giphy.gif

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s