Quantcast
Channel: hajimezhao
Viewing all articles
Browse latest Browse all 6

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

$
0
0

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. http://hajimezhao.files.wordpress.com/2012/10/design-pattern-in-ruby.jpg?w=480 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

http://hajimezhao.files.wordpress.com/2012/10/rails-route-rest-summary.png?w=480



Viewing all articles
Browse latest Browse all 6

Latest Images

Trending Articles





Latest Images