Bumper Sticker Factory
A Real World Class
January 2, 2015
While driving home for the holidays, I spotted a bumper sticker I'd never seen before. It was in the cab of a small size pick-up strategically placed behind the driver's seat. Here's what it said: "Being a nice person is a good idea". The Highway 5 rally has always provided time and space to think. Since I've been given over to thinking of classes and objects these days, I had a puzzle over how to model Person and Idea correctly for this ethical and politely proselytizing driver. While classes can represent abstract concepts such as person and idea and allow for attributes such as 'good' and methods such as 'be nice', I thought of building something about the bumper sticker itself.
Here's a scratch list for ruby classes in general and for our bumper sticker class in particular.
- Figure out if the class can be included in a larger class. For example, if our bumper stickers are coming from the print shop they might descend from PrintProduct.
- Capitalize the first letters of the words in the class, no spaces, no hyphens. Ergo BumperSticker.
- When you have a whole list of variables for the class, give it an options hash so that your fellow rubyists do not need to read the class declaration to populate the variables to create a new BumperSticker.
- Initialize all variables with an optional value when that makes sense. For example, width for bumper stickers should be 10" and height should be 3". For visibility at a safe following distance, let's make our default font color white and our default background black. Slogans will be provided every time, so the slogan will not have an optional value.
- For cataloging slogans, we can use a class variable in the initialization statement as well as a self.add_slogan method to append the new slogan to the array of slogans when it doesn't already exist.
- When interacting with other classes, you can create an instance of the helper class and pass in the instance to the create statement of your class. For example, we might want to create a car first and then pass it to our bumper sticker to record which cars take which bumper stickers.
And remember.. Ham and eggs - A day's work for a chicken; A lifetime commitment for a pig.


