Practical object-oriented design: an agile primer using Ruby Second Edition Metz 2024 Scribd Download
Practical object-oriented design: an agile primer using Ruby Second Edition Metz 2024 Scribd Download
com
https://textbookfull.com/product/practical-object-oriented-
design-an-agile-primer-using-ruby-second-edition-metz/
OR CLICK BUTTON
DOWNLOAD NOW
https://textbookfull.com/product/systems-analysis-and-design-an-
object-oriented-approach-with-uml-dennis/
textboxfull.com
https://textbookfull.com/product/object-oriented-design-with-abap-a-
practical-approach-1st-edition-james-e-mcdonough-auth/
textboxfull.com
https://textbookfull.com/product/object-oriented-data-structures-
using-java-4th-edition-dale/
textboxfull.com
https://textbookfull.com/product/systems-analysis-and-design-an-
object-oriented-approach-with-uml-5th-edition-dennis/
textboxfull.com
C++ Programming: An Object-Oriented Approach, 1e ISE
Behrouz A. Forouzan
https://textbookfull.com/product/c-programming-an-object-oriented-
approach-1e-ise-behrouz-a-forouzan/
textboxfull.com
https://textbookfull.com/product/deep-learning-in-python-an-object-
oriented-programming-1st-edition-hong-m-lei-lei/
textboxfull.com
https://textbookfull.com/product/object-orientation-abstraction-and-
data-structures-using-scala-second-edition-lacher/
textboxfull.com
About This E-Book
EPUB is an open, industry-standard format for e-books.
However, support for EPUB and its many features varies across
reading devices and applications. Use your device or app settings to
customize the presentation to your liking. Settings that you can
customize often include font, font size, single or double column,
landscape or portrait mode, and figures that you can click or tap to
enlarge. For additional information about the settings and features
on your reading device or app, visit the device manufacturer’s Web
site.
Many titles include programming code or configuration
examples. To optimize the presentation of these elements, view the
e-book in single-column, landscape mode and adjust the font size to
the smallest setting. In addition to presenting code and
configurations in the reflowable text format, we have included
images of the code that mimic the presentation found in the print
book; therefore, where the reflowable format may compromise the
presentation of the code listing, you will see a “Click here to view
code image” link. Click the link to view the print-fidelity code image.
To return to the previous page viewed, click the Back button on your
device or app.
Praise for the first edition of Practical
Object-Oriented Design in Ruby
“Meticulously pragmatic and exquisitely articulate, Practical
Object Oriented Design in Ruby makes otherwise elusive
knowledge available to an audience which desperately needs it.
The prescriptions are appropriate both as rules for novices and
as guidelines for experienced professionals.”
—Katrina Owen, Creator, Exercism
“I do believe this will be the most important Ruby book of 2012.
Not only is the book 100% on-point, Sandi has an easy writing
style with lots of great analogies that drive every point home.”
—Avdi Grimm, author of Exceptional Ruby and Objects on Rails
“While Ruby is an object-oriented language, little time is spent
in the documentation on what OO truly means or how it should
direct the way we build programs. Here Metz brings it to the
fore, covering most of the key principles of OO development
and design in an engaging, easy-to-understand manner. This is
a must for any respectable Ruby bookshelf.”
—Peter Cooper, editor, Ruby Weekly
“This is the best OO book I’ve ever read. It’s short, sweet, but
potent. It slowly moves from simple techniques to more
advanced, each example improving on the last. The ideas it
presents are useful not just in Ruby but in static languages like
C# too. Highly recommended!”
—Kevin Berridge, software engineering manager, Pointe Blank
Solutions, and organizer, Burning River Developers Meetup
“This is the best programming book I’ve read in ages. Sandi
talks about basic principles, but these are things we’re probably
still doing wrong and she shows us why and how. The book has
the perfect mix of code, diagrams, and words. I can’t
recommend it enough and if you’re serious about being a better
programmer, you’ll read it and agree.
—Derick Hitchcock, software engineer, Cisco
Second Edition
Sandi Metz
Introduction
Acknowledgments
About the Author
1 Object-Oriented Design
1.1 In Praise of Design
1.1.1 The Problem Design Solves
1.1.2 Why Change Is Hard
1.1.3 A Practical Definition of Design
1.2 The Tools of Design
1.2.1 Design Principles
1.2.2 Design Patterns
1.3 The Act of Design
1.3.1 How Design Fails
1.3.2 When to Design
1.3.3 Judging Design
1.4 A Brief Introduction to Object-Oriented Programming
1.4.1 Procedural Languages
1.4.2 Object-Oriented Languages
1.5 Summary
2 Designing Classes with a Single Responsibility
2.1 Deciding What Belongs in a Class
2.1.1 Grouping Methods into Classes
2.1.2 Organizing Code to Allow for Easy Changes
2.2 Creating Classes That Have a Single Responsibility
2.2.1 An Example Application: Bicycles and Gears
2.2.2 Why Single Responsibility Matters
2.2.3 Determining If a Class Has a Single Responsibility
2.2.4 Determining When to Make Design Decisions
2.3 Writing Code That Embraces Change
2.3.1 Depend on Behavior, Not Data
2.3.2 Enforce Single Responsibility Everywhere
2.4 Finally, the Real Wheel
2.5 Summary
3 Managing Dependencies
3.1 Understanding Dependencies
3.1.1 Recognizing Dependencies
3.1.2 Coupling Between Objects (CBO)
3.1.3 Other Dependencies
3.2 Writing Loosely Coupled Code
3.2.1 Inject Dependencies
3.2.2 Isolate Dependencies
3.2.3 Remove Argument-Order Dependencies
3.3 Managing Dependency Direction
3.3.1 Reversing Dependencies
3.3.2 Choosing Dependency Direction
3.4 Summary
4 Creating Flexible Interfaces
4.1 Understanding Interfaces
4.2 Defining Interfaces
4.2.1 Public Interfaces
4.2.2 Private Interfaces
4.2.3 Responsibilities, Dependencies, and Interfaces
4.3 Finding the Public Interface
4.3.1 An Example Application: Bicycle Touring Company
4.3.2 Constructing an Intention
4.3.3 Using Sequence Diagrams
4.3.4 Asking for “What” Instead of Telling “How”
4.3.5 Seeking Context Independence
4.3.6 Trusting Other Objects
4.3.7 Using Messages to Discover Objects
4.3.8 Creating a Message-Based Application
4.4 Writing Code That Puts Its Best (Inter)Face Forward
4.4.1 Create Explicit Interfaces
4.4.2 Honor the Public Interfaces of Others
4.4.3 Exercise Caution When Depending on Private
Interfaces
4.4.4 Minimize Context
4.5 The Law of Demeter
4.5.1 Defining Demeter
4.5.2 Consequences of Violations
4.5.3 Avoiding Violations
4.5.4 Listening to Demeter
4.6 Summary
Afterword
Index
Introduction
It is a wonder this book exists; the fact that it does is due to the
efforts and encouragement of many people.
Throughout the long process of writing, Lori Evans and TJ
Stankus provided early feedback on every chapter. They live in
Durham, NC, and thus could not escape me, but this fact does
nothing to lessen my appreciation for their help.
Midway through the book, after it became impossible to deny
that its writing would take approximately twice as long as originally
estimated, Mike Dalessio and Gregory Brown read drafts and gave
invaluable feedback and support. Their encouragement and
enthusiasm kept the project alive during dark days.
A number of reviewers cast their keen eyes on the entire book,
acting as gracious stand-ins for you, the gentle reader. As the first
edition neared completion, Steve Klabnik, Desi McAdam, and Seth
Wax gave it careful readings. The second edition was meticulously
scoured by Will Sommers and Tory Peterschild. Their impressions
and suggestions caused changes that will benefit all who follow.
Late drafts were given careful, thorough readings by Katrina
Owen, Avdi Grimm, and Rebecca Wirfs-Brock, and the book is much
improved by their kind and thoughtful feedback. Before they pitched
in, Katrina, Avdi, and Rebecca were strangers to me; I am grateful
for their involvement and humbled by their generosity. If you find
this book useful, thank them when you next see them.
I am also grateful for the Gotham Ruby Group and for everyone
who expressed their appreciation for the design talks I gave at
GoRuCo 2009 and 2011. The folks at GoRuCo took a chance on an
unknown and gave me a forum in which to express these ideas; this
book started there. Ian McFarland and Brian Ford watched those
talks and their immediate and ongoing enthusiasm for this project
was both infectious and convincing.
The process of writing was greatly aided by Michael Thurston of
Pearson, who was like an ocean liner of calmness and organization
chugging through the chaotic sea of my opposing rogue writing
waves. You can, I expect, see the problem he faced. He insisted,
with endless patience and grace, that the writing be arranged in a
readable structure. I believe his efforts have paid off and hope you
will agree.
My thanks also to Debra Williams Cauley, my editor at
Pearson/Addison-Wesley, who overheard an ill-timed hallway rant in
2006 at the first Ruby on Rails conference in Chicago and launched
the campaign that eventually resulted in this book. Despite my best
efforts, she would not take no for an answer. She cleverly moved
from one argument to the next until she finally found the one that
convinced; this accurately reflects her persistence and dedication.
I owe a debt to the entire object-oriented design community. I
did not make up the ideas in this book, I am merely a translator, and
I stand on the shoulders of giants. It goes without saying that while
all credit for these ideas belongs to others—failures of translation are
mine alone.
And finally, this book owes its existence to my partner Amy
Germuth. Before this project started I could not imagine writing a
book; her view of the world as a place where people did such things
made doing so seem possible. The book in your hands is a tribute to
her boundless patience and endless support.
Thank you, each and every one.
About the Author
Object-Oriented Design
The world is procedural. Time flows forward and events, one by one,
pass by. Your morning procedure may be to get up, brush your
teeth, make coffee, dress, and then get to work. These activities can
be modeled using procedural software; because you know the order
of events, you can write code to do each thing and then quite
deliberately string the things together, one after another.
The world is also object-oriented. The objects with which you
interact might include a spouse and a cat, or an old car and a pile of
bike parts in the garage, or your ticking heart and the exercise plan
you use to keep it healthy. Each of these objects comes equipped
with its own behavior, and while some of the interactions between
them might be predictable, it is entirely possible for your spouse to
unexpectedly step on the cat, causing a reaction that rapidly raises
everyone’s heart rate and gives you new appreciation for your
exercise regimen.
In a world of objects, new arrangements of behavior emerge
naturally. You don’t have to explicitly write code for the
spouse_steps_on_cat procedure; all you need is a spouse object
that takes steps and a cat object that does not like being stepped
on. Put these two objects into a room together and unanticipated
combinations of behavior will appear.
This book is about designing object-oriented software, and how
it views the world as a series of spontaneous interactions between
objects. Object-oriented design (OOD) requires that you shift from
thinking of the world as a collection of predefined procedures to
modeling the world as a series of messages that pass between
objects. Failures of OOD might look like failures of coding technique,
but they are actually failures of perspective. The first requirement for
learning how to do object-oriented design is to immerse yourself in
objects; once you acquire an object-oriented perspective, the rest
follows naturally.
This book guides you through the immersion process. This
chapter starts with a general discussion of OOD. It argues the case
for design and then proceeds to describe when to do it and how to
judge it. The chapter ends with a brief overview of object-oriented
programming that defines the terms used throughout the book.
FOOTNOTES:
[6] The History of Human Marriage.
[7] A History of Matrimonial Institutions.
[8] Newer Ideals of Peace, 177.
[9] De Tocqueville, Democracy in America, vol. i, chap. 5.
[10] These matters are expounded at some length in the
writer’s Human Nature and the Social Order.
[11] The Native Tribes of Central Australia. Compare also
Darwin’s views and examples given in chap. 7 of his Descent of
Man.
CHAPTER IV
PRIMARY IDEALS
FOOTNOTES:
[12] Thoreau, A Week on the Concord and Merrimack Rivers,
283.
[13] Charities and the Commons, Aug. 3, 1907.
[14]
Antica lupa,
Che più che tutte l’altre bestie hai preda.
Purgatorio, XX, 10.
[15] 1 Samuel, 15:33.
[16] Vol. i, 540 ff.
[17] The City Wilderness, 116.
[18] Boys’ Self-Governing Clubs, 4, 5.
[19] Charities and the Commons, Aug. 3. 1907, abridged.
[20] John Graham Brooks, The Social Unrest, 135.
[21] The City Wilderness, 113.
CHAPTER V
THE EXTENSION OF PRIMARY IDEALS
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
textbookfull.com