Bienvenue à la Bibliothèque Alo de l'Université Shalom de Bunia
A partir de cette page vous pouvez :
Retourner au premier écran avec les dernières notices... | Votre compte |
Titre : | Design Patterns in Ruby |
Auteurs : | Russ Olsen |
Type de document : | document électronique |
Editeur : | [S.l.] : Addison-Wesley Professional, 2007 |
ISBN/ISSN/EAN : | 978-0-321-49045-2 |
Résumé : |
Praise for ** *Design Patterns in Ruby* ** "** *Design Patterns in Ruby* ** documents smart ways to resolve many problems that Ruby developers commonly encounter. Russ Olsen has done a great job of selecting classic patterns and augmenting these with newer patterns that have special relevance for Ruby. He clearly explains each idea, making a wealth of experience available to Ruby developers for their own daily work." ÔÇöSteve Metsker, Managing Consultant with Dominion Digital, Inc. "This book provides a great demonstration of the key 'Gang of Four' design patterns without resorting to overly technical explanations. Written in a precise, yet almost informal style, this book covers enough ground that even those without prior exposure to design patterns will soon feel confident applying them using Ruby. Olsen has done a great job to make a book about a classically 'dry' subject into such an engaging and even occasionally humorous read." ÔÇöPeter Cooper "This book renewed my interest in understanding patterns after a decade of good intentions. Russ picked the most useful patterns for Ruby and introduced them in a straightforward and logical manner, going beyond the GoF's patterns. This book has improved my use of Ruby, and encouraged me to blow off the dust covering the GoF book." ÔÇöMike Stok "* **Design Patterns in Ruby** * is a great way for programmers from statically typed objectoriented languages to learn how design patterns appear in a more dynamic, flexible language like Ruby." ÔÇöRob Sanheim, Ruby Ninja, Relevance Most design pattern books are based on C++ and Java. But Ruby is differentÔÇöand the language's unique qualities make design patterns easier to implement and use. In this book, Russ Olsen demonstrates how to combine Ruby's power and elegance with patterns, and write more sophisticated, effective software with far fewer lines of code. After reviewing the history, concepts, and goals of design patterns, Olsen offers a quick tour of the Ruby languageÔÇöenough to allow any experienced software developer to immediately utilize patterns with Ruby. The book especially calls attention to Ruby features that simplify the use of patterns, including dynamic typing, code closures, and "mixins" for easier code reuse. Fourteen of the classic "Gang of Four" patterns are considered from the Ruby point of view, explaining what problems each pattern solves, discussing whether traditional implementations make sense in the Ruby environment, and introducing Ruby-specific improvements. You'll discover opportunities to implement patterns in just one or two lines of code, instead of the endlessly repeated boilerplate that conventional languages often require. ** *Design Patterns in Ruby* ** also identifies innovative new patterns that have emerged from the Ruby community. These include ways to create custom objects with metaprogramming, as well as the ambitious Rails-based "Convention Over Configuration" pattern, designed to help integrate entire applications and frameworks. Engaging, practical, and accessible, * **Design Patterns in Ruby** * will help you build better software while making your Ruby programming experience more rewarding. ### About the Author **Russ Olsen** has been building software for more than twenty-five years. He has led projects through several generations of programming technologies, from FORTRAN to C to C++ to Java, and now Ruby. He has been using and teaching Ruby since 2002. Olsen writes the popular technology blog Technology As If People Mattered (http://www.russolsen.com). ### Excerpt. ┬® Reprinted by permission. All rights reserved. A former colleague of mine used to say that thick books about design patterns were evidence of an inadequate programming language. What he meant was that, since design patterns are the common idioms of code, a good programming language should make them very easy to implement. An ideal language would so thoroughly integrate the patterns that they would almost disappear from sight. To take an extreme example, in the late 80's I worked on a project that produced object oriented code in C. Yes, C, not C++. We pulled this off by having each "object" (actually a C structure) point off to a table of function pointers. We operated on our "objects" by chasing the pointer to the table and calling functions out of the table, thereby simulating a method call on an object. It was awkward and messy, but it worked. Had we thought of it, we might have called this technique the "object oriented" pattern. Of course with the advent of C++ and then Java, our object oriented pattern disappeared, absorbed so thoroughly into the language that it vanished from sight. Today, we don't usually think of object orientation as a patternÔÇöit is too easy. But many things are still not easy enough. The justly famous Gang of Four book, (*Design Patterns: Elements of Reusable Object-Oriented Software* by Gamma, Helm, Johnson, and Vlissides) is required reading for every software engineer today. But actually implementing many of the patterns described in Design Patterns with the languages in widespread use today, Java and C++ and perhaps C#, looks and feels a lot like my 1980s vintage handcrafted object system. Too painful. Too verbose. Too prone to bugs. The Ruby programming language takes us a step closer to my old friend's ideal, a language that makes implementing patterns easy, so easy that sometimes they fade into the background. Building patterns in Ruby is easier for a number of reasons: * Ruby is dynamically typed. By dispensing with static typing, Ruby dramatically reduces the code overhead of building most programs, including those that implement patterns. * Ruby has code closures. Ruby allows us to pass around chunks of code and associated scope without having to laboriously construct entire classes and objects that do nothing else. * Ruby classes are real objects. Since a class in Ruby is just another object, we can do any of the usual runtime things to a Ruby class that we can do to any object. At runtime we can create totally new classes. We can also modify existing classes by adding or deleting methods. We can even clone a class and change the copy, leaving the original alone. * Ruby has an elegant system of code reuse. In addition to garden variety inheritance, Ruby provides also allows us to define mixins, which are a simple but flexible way to write code that can be shared among several classes. All of this makes code in Ruby compressible: In Ruby, like Java and C++, you can implement very sophisticated ideas, but with Ruby it is possible to hide the details of your implementations much more effectively. As you will see on the pages that follow, many of the design patterns that require many lines of endlessly repeated boiler plate code in traditional static languages require only one or two lines in Ruby. You can make a class into a singleton with a simple include Singleton. You can delegate as easily as you can inherit. Since Ruby enables you to say more interesting things in each line of code, you end up with less code. This is not just a question of keyboard laziness, it is an application of the DRY (Don't Repeat Yourself) principal. I don't think anyone today would mourn the passing of my old object oriented pattern in CÔÇöit worked for me, but it made me work for it, too. In the same way, the traditional implementations of many design patterns work, but they make you work too. Ruby is a real step forward to be able to do that work only once and compress it out of the bulk of our code. In short, Ruby allows us to concentrate on the real problems that we are trying to solve instead of the plumbing. I hope that this book will help you see how. ### Who Is This Book For? Simply put, this book is for developers who want to know how to build significant software in Ruby. I assume that you are familiar with object oriented programming, but you don't really need any knowledge of design patterns ÔÇöyou can pick that up as you go through the book. You also don't need a lot of Ruby knowledge to read this book profitably: you can find a quick introduction to the language in Chapter 2 and I do try to explain any Ruby specific language issues as we go. ### How Is This Book Organized? This book is divided into three parts. First there are a couple of introductory chapters, starting with the briefest outline of the history and background of the whole Design Patterns movement and ending with a quick tour of the Ruby language, at the "just enough to be dangerous" level. The second section, which takes up the bulk of these pages, looks at a number of the original Gang of Four patterns from a Ruby point of view. What problem is this pattern trying to solve? What does the traditional implementation of the pattern, the implementation given by the Gang of Four look like in Ruby? Does the traditional implementation make sense in Ruby? Does Ruby provide us with any alternatives that will make solving the problem easier? The final section of this book looks at a three patterns that have emerged from the Ruby. ### A Word of Warning I cannot sign my name to a book about design patterns without repeating the mantra that I have been muttering for many years now: design patterns are little spring loaded solutions to common programming problems. Ideally, when the appropriate kind of problem comes along, you should trigger the design pattern and the problem is solved. It is that first part, the bit about waiting for the appropriate problem to come along, that some engineers have trouble with. You cannot say that you are correctly applying a design pattern unless you are confronting the problem that the pattern is supposed to solve. The reckless use of every design pattern on the menu to solve nonexistent problems has given design patterns a bad na |