Design Patterns in Ruby (Adobe Reader)

Specificaties
E-book, blz. | Engels
Pearson Education | e druk, 2007
ISBN13: 9780321539267
Rubricering
Juridisch :
Pearson Education e druk, 2007 9780321539267
Verwachte levertijd ongeveer 9 werkdagen

Samenvatting

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.

Specificaties

ISBN13:9780321539267
Taal:Engels
Bindwijze:e-book

Inhoudsopgave

<h4>Foreword xvii</h4> <h4>Preface xix</h4> <h4>Acknowledgments xxv</h4> <h4>About the Author xxvii</h4> <h2>PART I: Patterns and Ruby 1 </h2> <h3>Chapter 1: Building Better Programs with Patterns 3 </h3> <p>The Gang of Four 4 </p> <p>Patterns for Patterns 4 </p> <p>Separate Out the Things That Change from Those That Stay the Same 5</p> <p>Program to an Interface, Not an Implementation 5</p> <p>Prefer Composition over Inheritance 7 </p> <p>Delegate, Delegate, Delegate 12</p> <p>You Ain't Gonna Need It 13</p> <p>Fourteen Out of Twenty-Three 15 </p> <p>Patterns in Ruby? 17 </p> <h3>Chapter 2: Getting Started with Ruby 19 </h3> <p>Interactive Ruby 20</p> <p>Saying Hello World 20</p> <p>Variables 23</p> <p>Fixnums and Bignums 24</p> <p>Floats 26</p> <p>There Are No Primitives Here 26</p> <p>But Sometimes There Is No Object 27</p> <p>Truth, Lies, and nil 28</p> <p>Decisions, Decisions 30</p> <p>Loops 32</p> <p>More about Strings 34</p> <p>Symbols 37</p> <p>Arrays 38</p> <p>Hashes 40</p> <p>Regular Expressions 40</p> <p>A Class of Your Own 41</p> <p>Getting at the Instance Variables 43</p> <p>An Object Asks: Who Am I? 46</p> <p>Inheritance, Subclasses, and Superclasses 46</p> <p>Argument Options 47</p> <p>Modules 49</p> <p>Exceptions 52</p> <p>Threads 53</p> <p>Managing Separate Source Files 54</p> <p>Wrapping Up 55</p> <h2>PART II: Patterns in Ruby 57 </h2> <h3>Chapter 3: Varying the Algorithm with the Template Method 59 </h3> <p>Keeping Up with What Life Throws at You 60</p> <p>Separate the Things That Stay the Same 61</p> <p>Discovering the Template Method Pattern 65</p> <p>Hook Methods 66</p> <p>But Where Are All the Declarations? 68</p> <p>Types, Safety, and Flexibility 69</p> <p>Unit Tests Are Not Optional 71</p> <p>Using and Abusing the Template Method Pattern 73</p> <p>Templates in the Wild 74</p> <p>Wrapping Up 75</p> <h3>Chapter 4: Replacing the Algorithm with the Strategy 77 </h3> <p>Delegate, Delegate, and Delegate Again 78</p> <p>Sharing Data between the Context and the Strategy 80</p> <p>Duck Typing Yet Again 82</p> <p>Procs and Blocks 84</p> <p>Quick-and-Dirty Strategies 88</p> <p>Using and Abusing the Strategy Pattern 90</p> <p>The Strategy Pattern in the Wild 90</p> <p>Wrapping Up 92</p> <h3>Chapter 5: Keeping Up with the Times with the Observer 95 </h3> <p>Staying Informed 95</p> <p>A Better Way to Stay Informed 97</p> <p>Factoring Out the Observable Support 100</p> <p>Code Blocks as Observers 104</p> <p>Variations on the Observer Pattern 105</p> <p>Using and Abusing the Observer Pattern 106</p> <p>Observers in the Wild 108</p> <p>Wrapping Up 109</p> <h3>Chapter 6: Assembling the Whole from the Parts with the Composite 111 </h3> <p>The Whole and the Parts 112</p> <p>Creating Composites 114</p> <p>Sprucing Up the Composite with Operators 118</p> <p>An Array as a Composite? 119</p> <p>An Inconvenient Difference 120</p> <p>Pointers This Way and That 120</p> <p>Using and Abusing the Composite Pattern 122</p> <p>Composites in the Wild 123</p> <p>Wrapping Up 125</p> <h3>Chapter 7: Reaching into a Collection with the Iterator 127 </h3> <p>External Iterators 127</p> <p>Internal Iterators 130</p> <p>Internal Iterators versus External Iterators 131</p> <p>The Inimitable Enumerable 133</p> <p>Using and Abusing the Iterator Pattern 134</p> <p>Iterators in the Wild 136</p> <p>Wrapping Up 140</p> <h3>Chapter 8: Getting Things Done with Commands 143 </h3> <p>An Explosion of Subclasses 144</p> <p>An Easier Way 145</p> <p>Code Blocks as Commands 147</p> <p>Commands That Record 148</p> <p>Being Undone by a Command 151</p> <p>Queuing Up Commands 154</p> <p>Using and Abusing the Command Pattern 154</p> <p>The Command Pattern in the Wild 155</p> <p>ActiveRecord Migrations 155</p> <p>Madeleine 156</p> <p>Wrapping Up 160</p> <h3>Chapter 9: Filling in the Gaps with the Adapter 163 </h3> <p>Software Adapters 164</p> <p>The Near Misses 167</p> <p>An Adaptive Alternative? 168</p> <p>Modifying a Single Instance 170</p> <p>Adapt or Modify? 172</p> <p>Using and Abusing the Adapter Pattern 173</p> <p>Adapters in the Wild 173</p> <p>Wrapping Up 174</p> <h3>Chapter 10: Getting in Front of Your Object with a Proxy 175 </h3> <p>Proxies to the Rescue 176</p> <p>The Protection Proxy 178</p> <p>Remote Proxies 179</p> <p>Virtual Proxies Make You Lazy 180</p> <p>Eliminating That Proxy Drudgery 182</p> <p>Message Passing and Methods 183</p> <p>The method_missing Method 184</p> <p>Sending Messages 185</p> <p>Proxies without the Tears 185</p> <p>Using and Abusing Proxies 189</p> <p>Proxies in the Wild 190</p> <p>Wrapping Up 192</p> <h3>Chapter 11: Improving Your Objects with a Decorator 193 </h3> <p>Decorators: The Cure for Ugly Code 193</p> <p>Formal Decoration 200</p> <p>Easing the Delegation Blues 200</p> <p>Dynamic Alternatives to the Decorator Pattern 201</p> <p>Wrapping Methods 202</p> <p>Decorating with Modules 202</p> <p>Using and Abusing the Decorator Pattern 204</p> <p>Decorators in the Wild 205</p> <p>Wrapping Up 206</p> <h3>Chapter 12: Making Sure There Is Only One with the Singleton 207 </h3> <p>One Object, Global Access 207</p> <p>Class Variables and Methods 208</p> <p>Class Variables 208</p> <p>Class Methods 209</p> <p>A First Try at a Ruby Singleton 211</p> <p>Managing the Single Instance 212</p> <p>Making Sure There Is Only One 213</p> <p>The Singleton Module 214</p> <p>Lazy and Eager Singletons 214</p> <p>Alternatives to the Classic Singleton 215</p> <p>Global Variables as Singletons 215</p> <p>Classes as Singletons 216</p> <p>Modules as Singletons 218</p> <p>A Safety Harness or a Straitjacket? 219</p> <p>Using and Abusing the Singleton Pattern 220</p> <p>They Are Really Just Global Variables, Right? 220</p> <p>Just How Many of These Singletons Do You Have? 221</p> <p>Singletons on a Need-to-Know Basis 221</p> <p>Curing the Testing Blues 223</p> <p>Singletons in the Wild 224</p> <p>Wrapping Up 225</p> <h3>Chapter 13: Picking the Right Class with a Factory 227 </h3> <p>A Different Kind of Duck Typing 228</p> <p>The Template Method Strikes Again 231</p> <p>Parameterized Factory Methods 233</p> <p>Classes Are Just Objects, Too 236</p> <p>Bad News: Your Program Hits the Big Time 237</p> <p>Bundles of Object Creation 239</p> <p>Classes Are Just Objects (Again) 241</p> <p>Leveraging the Name 242</p> <p>Using and Abusing the Factory Patterns 244</p> <p>Factory Patterns in the Wild 244</p> <p>Wrapping Up 246</p> <h3>Chapter 14: Easier Object Construction with the Builder 249 </h3> <p>Building Computers 250</p> <p>Polymorphic Builders 253</p> <p>Builders Can Ensure Sane Objects 256</p> <p>Reusable Builders 257</p> <p>Better Builders with Magic Methods 258</p> <p>Using and Abusing the Builder Pattern 259</p> <p>Builders in the Wild 259</p> <p>Wrapping Up 260</p> <h3>Chapter 15: Assembling Your System with the Interpreter 263 </h3> <p>The Right Language for the Job 264</p> <p>Building an Interpreter 264</p> <p>A File-Finding Interpreter 267</p> <p>Finding All the Files 267</p> <p>Finding Files by Name 268</p> <p>Big Files and Writable Files 269</p> <p>More Complex Searches with Not, And, and Or 270</p> <p>Creating the AST 272</p> <p>A Simple Parser 272</p> <p>A Parser-less Interpreter? 274</p> <p>Let XML or YAML Do the Parsing? 276</p> <p>Racc for More Complex Parsers 277</p> <p>Let Ruby Do the Parsing? 277</p> <p>Using and Abusing the Interpreter Pattern 277</p> <p>Interpreters in the Wild 278</p> <p>Wrapping Up 279</p> <h2>PART III: Patterns for Ruby 281 </h2> <h3>Chapter 16: Opening Up Your System with Domain-Specific Languages 283 </h3> <p>The Domain of Specific Languages 283</p> <p>A File Backup DSL 284</p> <p>It's a Data File--No, It's a Program! 285</p> <p>Building PackRat 287</p> <p>Pulling Our DSL Together 288</p> <p>Taking Stock of PackRat 289</p> <p>Improving PackRat 290</p> <p>Using and Abusing Internal DSLs 293</p> <p>Internal DSLs in the Wild 294</p> <p>Wrapping Up 295</p> <h3>Chapter 17: Creating Custom Objects with Meta-programming 297 </h3> <p>Custom-Tailored Objects, Method by Method 298</p> <p>Custom Objects, Module by Module 300</p> <p>Conjuring Up Brand-New Methods 301</p> <p>An Object's Gaze Turns Inward 306</p> <p>Using and Abusing Meta-programming 306</p> <p>Meta-programming in the Wild 308</p> <p>Wrapping Up 311</p> <h3>Chapter 18: Convention Over Configuration 313 </h3> <p>A Good User Interface--for Developers 315</p> <p>Anticipate Needs 315</p> <p>Let Them Say It Once 316</p> <p>Provide a Template 316</p> <p>A Message Gateway 317</p> <p>Picking an Adapter 319</p> <p>Loading the Classes 320</p> <p>Adding Some Security 323</p> <p>Getting the User Started 325</p> <p>Taking Stock of the Message Gateway 326</p> <p>Using and Abusing the Convention Over Configuration Pattern 327</p> <p>Convention Over Configuration in the Wild 328</p> <p>Wrapping Up 328</p> <h3>Chapter 19: Conclusion 331 </h3> <h3>Appendix A: Getting Hold of Ruby 333</h3> <h3>Appendix B: Digging Deeper 335 </h3> <h4>Index 339 </h4>

Net verschenen

Rubrieken

Populaire producten

    Personen

      Trefwoorden

        Design Patterns in Ruby (Adobe Reader)