- ホーム
- > 洋書
- > 英文書
- > Computer / General
Full Description
The Complete Guide to Writing More Maintainable, Manageable, Pleasing, and Powerful Ruby Applications Ruby's widely admired ease of use has a downside: Too many Ruby and Rails applications have been created without concern for their long-term maintenance or evolution. The Web is awash in Ruby code that is now virtually impossible to change or extend. This text helps you solve that problem by using powerful real-world object-oriented design techniques, which it thoroughly explains using simple and practical Ruby examples.Sandi Metz has distilled a lifetime of conversations and presentations about object-oriented design into a set of Ruby-focused practices for crafting manageable, extensible, and pleasing code. She shows you how to build new applications that can survive success and repair existing applications that have become impossible to change. Each technique is illustrated with extended examples, all downloadable from the companion Web site, poodr.info.The first title to focus squarely on object-oriented Ruby application design, Practical Object-Oriented Design in Ruby will guide you to superior outcomes, whatever your previous Ruby experience. Novice Ruby programmers will find specific rules to live by; intermediate Ruby programmers will find valuable principles they can flexibly interpret and apply; and advanced Ruby programmers will find a common language they can use to lead development and guide their colleagues.This guide will help youUnderstand how object-oriented programming can help you craft Ruby code that is easier to maintain and upgradeDecide what belongs in a single Ruby classAvoid entangling objects that should be kept separateDefine flexible interfaces among objectsReduce programming overhead costs with duck typingSuccessfully apply inheritanceBuild objects via compositionDesign cost-effective testsSolve common problems associated with poorly designed Ruby code
Contents
Foreword xv Introduction xviiAcknowledgments xxiAbout the Author xxiiiChapter 1: Object-Oriented Design 1In Praise of Design 2The Tools of Design 4The Act of Design 7A Brief Introduction to Object-Oriented Programming 11Summary 14Chapter 2: Designing Classes with a Single Responsibility 15Deciding What Belongs in a Class 16Grouping Methods into Classes 16Organizing Code to Allow for Easy Changes 16Creating Classes That Have a Single Responsibility 17Writing Code That Embraces Change 24Finally, the Real Wheel 33Summary 34Chapter 3: Managing Dependencies 35Understanding Dependencies 36Writing Loosely Coupled Code 39Managing Dependency Direction 51Summary 57Chapter 4: Creating Flexible Interfaces 59Understanding Interfaces 59Defining Interfaces 61Public Interfaces 62Private Interfaces 62Responsibilities, Dependencies, and Interfaces 62Finding the Public Interface 63Writing Code That Puts Its Best (Inter)Face Forward 76The Law of Demeter 80Summary 83Chapter 5: Reducing Costs with Duck Typing 85Understanding Duck Typing 85Writing Code That Relies on Ducks 95Conquering a Fear of Duck Typing 100Summary 104Chapter 6: Acquiring Behavior Through Inheritance 105Understanding Classical Inheritance 105Recognizing Where to Use Inheritance 106Misapplying Inheritance 114Finding the Abstraction 116Managing Coupling Between Superclasses and Subclasses 129Summary 139Chapter 7: Sharing Role Behavior with Modules 141Understanding Roles 142Writing Inheritable Code 158Summary 162Chapter 8: Combining Objects with Composition 163Composing a Bicycle of Parts 164Composing the Parts Object 168Manufacturing Parts 176The Composed Bicycle 180Deciding Between Inheritance and Composition 184Summary 190Chapter 9: Designing Cost-Effective Tests 191Intentional Testing 192Testing Incoming Messages 200Testing Private Methods 213Testing Outgoing Messages 215Testing Duck Types 219Testing Inherited Code 229Summary 240Afterword 241Index 243



