The Power of Object-Oriented Design

Chapter 1 Notes from Practical Object-Oriented Design in Ruby by Sandi Metz

While Ruby is an object-oriented language, little time is spent in the documentation on what OO truly means or how it should direct the way we build programs. Here Metz brings it to the fore, covering most of the key principles of OO development and design in an engaging, easy-to-understand manner. This is a must for any respectable Ruby bookshelf. ~ Peter Cooper, editor, Ruby Weekly

So good, I couldn't put it down! This is a must-read for anyone wanting to do object-oriented programming in any language, not to mention it has completely changed the way I approach testing. ~ Charles Max Wood, video and audio show host, TeachMeToCode.com

One of the core truism of software development is that as your code grows and requirements for the system that you are building change, additional logic will be added that is not yet present in the current system. In almost all cases, maintainability over the life of the code is more important than optimizing its present state. ~ Obie Fernandez, Series Editor (Addison Wesley Professional Ruby Series)

  • It's important to write code that brings you joy; meaning a code that is useful for the present time and can adapt to next month and next year.

Chapter 1: Object-Oriented Design

The problem with poorly designed small applications is that if they are successful they grow up to be poorly designed big applications. They gradually become tar pits in which you fear to tread lest you sink without a trace. Changes that should be simple may cascade around the application, breaking code everywhere and requiring extensive rewriting. Tests are caught in the crossfire and begin to feel like a hindrance rather than a help.

  • Design is the art of arranging code. There are two tools for object-oriented design; design principles and patterns.
  • Design principles like SOLID (Single Responsibility, Open-Closed, Liskov Substitution, Interface Segregation, and Dependency Inversion). Also, the principles of DRY (Don't Repeat Yourself) and LoD (the Law of Demeter) are tools to improve our code.
  • Design patterns are solutions to some common problems related to design.

This book is not about patterns; however, it will prepare you to understand them and give you the knowledge to choose and use them appropriately.

  • You should build software in tiny increments.

If Agile is correct, two other things are also true. First, there is absolutely no point in doing a Big Up Front Design (BUFD) (because it cannot possibly be correct), and second, no one can predict when the application will be done (because you don't know in advance what it will eventually do). OOD is concerned with a much narrower domain. It is about arranging what code you have so that it will be easy to change.

  • Don't judge a code by SLOC (source lines of code) or by how many lines the developer wrote while you could add the same feature with much fewer lines. This metric alters the reward structure in ways that harm quality. Judge the OO design with an OO metric; there is usually a gem for doing so.
  • Technical debt is like borrowing time from the future to compromise.

Class-based OO languages like Ruby allow you to define a class that provides a blueprint for the construction of similar objects. A class defines methods (definitions of behavior) and attributes (definitions of variables). Methods get invoked in response to messages.

  • In Ruby, there are some predefined classes like String and Fixnum. Each class itself is an object; it's an instance of the Class class.

Final Thoughts

In this chapter, we've been on a quick tour of the object-oriented paradigm.

We've seen how important design principles and patterns are in building software.

Here, the author debriefs that learning objected-oriented design is step #1 before going deep into design patterns.

See you in chapter 2 notes!

Get Practical Object-Oriented Design in Ruby now! (if you haven't already)

or this second edition

Practical Object-Oriented Design in Ruby by Sandi Metz
By the author

Credit

Disclosure: The Amazon link for the book (in this section) is a paid link so if you buy the book, I will have a small commission

Get the next FREE ebook 'Disciplined' once released and more exclusive offers in your inbox

Published on medium

Join the conversation

Get FREE coupons and discounts
on my upcoming courses
when you subscribe!

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.