Dev Academy: Week 7 – Object-Oriented Design in Ruby

This week was focusing on Object Oriented Design. We had 5 challenges to do:

  1. Drawer Debugger
  2. Pez Dispenser
  3. Bingo Board Part Two
  4. Refactoring for Code Readability – on previous weeks challenge Validate a Credit Card Number
  5. Virus Predictor.

And I have just realised as I have started writing this post that Object Oriented Design hasn’t actually be explained to us. So, as I have been doing a lot in the last 7 weeks, I have googled what OOD is. Some definitions and links:

Object-oriented design is a programming paradigm that began in the late 60’s as software programs became more and more complex. The idea behind the approach was to build software systems by modeling them based on the real-world objects that they were trying to represent. For example, banking systems would likely contain customer objects, account objects, etc. Today, object-oriented design has been widely adopted by businesses around the world. When done properly, the approach leads to simpler, concrete, robust, flexible and modular software. When done badly, the results can be disastrous.

Object-oriented design is the process of planning a system of interacting objects for the purpose of solving a software problem. It is one approach to software design. Wikipedia,

It’s a process of planning a software system where objects will interact with each other to solve specific problems. The saying goes, “Proper Object oriented design makes a developer’s life easy, whereas bad design makes it a disaster.”

A link to a possibly useful book on the subject:

Practical Object-Oriented Design in Ruby (POODR) is a programmers tale about how to write object-oriented code.


Another book with an interesting title:

The Bastards Book of Ruby: A Programming Primer for Counting and Other Unconventional Tasks

Object-Oriented Concepts – A primer on object-oriented design and using it to organize your code.

In a nutshell, object-oriented programming sees the world as data, modeled in code by “objects.” In OOP, the programmer focuses on the content of that object and how that object behaves (i.e. methods).

So it’s worth becoming acquainted with OOP because it is a design pattern especially suited for programming with data. The practical benefit is that it can vastly reduce the amount of code you have to write and the number of errors of inconsistency to debug.

I guess I have a bit of an idea now and in the Treehouse tutorials we did make a bank account class, so can see the link to the first definition above. Do you have a good definition or explanation of what OOD is? And any good examples?

What have I learnt / done this week? Well, I feel more confident with writing methods, classes and how the methods interact with each other. I am starting to become more comfortable with breaking a problem down into more than one or two methods. I can see the relevance of doing this. I have learn about user stories:

… and used them in solving a problem and wrote some nice code, I think.

Screen Shot 2015-04-17 at 5.10.31 pm

Still not sure about what attr_reader, attr_writer and attr_accessor do, as it seems I can either have them in or not and my file still works?! For example in the above code having attr_accessor :flavours just above the initalize method, it will work. Anyone got a good explanation of what it a attr does and when it is used?? Perhaps I am just doing something fundamentally wrong in my code?

I have enjoyed solving the problems this week. Two were ones we did last week that we built on or refactored and the other three weren’t too difficult, although did do some work on the Virus Predictor challenge with another person from my cohort.

Another member of my cohort shared a link at this book – the (Poignant) Guide to Ruby –  and link to PDF. Even though this seems to have bee written by someone who is all over the place (the cartoons and long rambling paragraphs), the core part of the book explains what Ruby code is doing in a very simple way. For example:

Screen Shot 2015-04-17 at 5.52.32 pm

Two weeks left until the start of Phase 1 and the nine weeks of bootcamp. It will be coding from 9am till 6pm Monday to Friday plus probably lots of evenings and lots of weekends. I expect I will be very antisocial over this time. What will be good is that I will be based in at Enspiral Dev Academy in Cuba St and there will be lots of people around that I can get help from. Also, I hope I will be able to help some people as well, even though I have a big dose of the imposter syndrome – post on that shortly.

Ending question, what resources do you use, recommended for learning everything Ruby?


2 thoughts on “Dev Academy: Week 7 – Object-Oriented Design in Ruby

  1. Hey been thinking about this for a few days and in the meantime someone’s probably answered this for you. From what I can tell attr_reader, attr_writer and attr_accessor are just more efficient ways of doing exactly what you’re doing (but at the end of the day have pretty much identical functionality).

    What you’re writing are “mutator” methods, aka “getter” and “setter” methods because they literally get and set variables within objects. It seems that Ruby gives you a handy way to do this easily (and safely?) with attr_

    • Hey, thanks. No, no one else has commented. Yeah it does have to do with getter and setters, I think when you are putting arguments through. Once I have my head around it will post again!

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s