Quotes and lessons from the book “Design Pattern in Ruby, Russ Olsen”

October 28, 2012 § Leave a comment

Quotes and lessons from the book “Design Pattern in Ruby, Russ Olsen”

Patterns of patterns

The GoF did two things for us. First, they introduced most of the software engineering world to the idea of design pattern, where each pattern is a prepackaged solution to a common design problem. We should look around, they wrote, and identify common solutions to common problems. We should give each solution a name, and we should talk about what solution is good for, when to use it, and when to reach for something else. https://hajimezhao.files.wordpress.com/2012/10/design-pattern-in-ruby.jpg A set of general principles for GoF patterns is given as:

  • separate out things that change from those that stay the same: identify and separate static and dynamic parts
  • program to an interface, not an implementation: define the program behavior first, not how to achieve it
  • prefer composition over inheritance: we try to avoid saying that an object is a kind of something, and instead say that is has something. Because the relation is a kind of sth is ambiguous in some contexts, and cause troubles of translating real world concepts into OOP objects
  • delegate, delegate, delegate: delegate responsibility to multiple layers to reduce system complexity
  • You Ain’t Gonna Need It (YAGNI): (a new added principle) it says we should not implement features, or design in flexibility, that we don’t need right now. Because changes are, you ain’t gonna need it later.

Patterns in Ruby

The characteristics of Ruby language leads to open other 3 patterns:

  • The Internal Domain-Specific Language (DSL), a very dynamic twist on building specialized little languages
  • Meta-programming, a technique for creating just the classes and objects that you need, dynamically at runtime
  • Convention Over Configuration: the main motive behind this pattern is to lighten the configuration burdens which cost extra efforts. An example is to compare the HTTP request handling of Java servlet and Rails.
    • In Java, servlet is an elegant little Java class that knows how to handle HTTP request coming into one or more URL. But writing a Java class that extends javax.servlet.HttpServlet is not enough, you also need to configure the things, via the web.xml configuration file
    • In Rails, convention defines which methods handle which URL request neatly – see Rails RESTful cheatsheet

https://hajimezhao.files.wordpress.com/2012/10/rails-route-rest-summary.png

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

What’s this?

You are currently reading Quotes and lessons from the book “Design Pattern in Ruby, Russ Olsen” at hajimezhao.

meta

%d bloggers like this: