100% found this document useful (1 vote)
43 views

Pro JavaScript Design Patterns 1st Edition Ross Harmes - The ebook is available for quick download, easy access to content

The document provides information about the book 'Pro JavaScript Design Patterns' by Ross Harmes and Dustin Diaz, which focuses on applying object-oriented design principles to JavaScript programming. It emphasizes the importance of design patterns in creating maintainable and effective web applications. Additionally, it includes links to download the book and other related titles from ebookfinal.com.

Uploaded by

djonevnxemje
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
43 views

Pro JavaScript Design Patterns 1st Edition Ross Harmes - The ebook is available for quick download, easy access to content

The document provides information about the book 'Pro JavaScript Design Patterns' by Ross Harmes and Dustin Diaz, which focuses on applying object-oriented design principles to JavaScript programming. It emphasizes the importance of design patterns in creating maintainable and effective web applications. Additionally, it includes links to download the book and other related titles from ebookfinal.com.

Uploaded by

djonevnxemje
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 47

Visit ebookfinal.

com to download the full version and


explore more ebooks or textbooks

Pro JavaScript Design Patterns 1st Edition Ross


Harmes

_____ Click the link below to download _____


https://ebookfinal.com/download/pro-javascript-design-
patterns-1st-edition-ross-harmes/

Explore and download more ebooks or textbook at ebookfinal.com


Here are some recommended products that we believe you will be
interested in. You can click the link to download.

Pro JavaScript Techniques 2nd Edition John Resig

https://ebookfinal.com/download/pro-javascript-techniques-2nd-edition-
john-resig/

Scala Design Patterns 1st Edition Nikolov

https://ebookfinal.com/download/scala-design-patterns-1st-edition-
nikolov/

Elemental Design Patterns 1st Edition Jason Mcc. Smith

https://ebookfinal.com/download/elemental-design-patterns-1st-edition-
jason-mcc-smith/

Head First Design Patterns 1st Edition Eric Freeman

https://ebookfinal.com/download/head-first-design-patterns-1st-
edition-eric-freeman/
Java Design Patterns 1st Edition Mr. Devendra Singh

https://ebookfinal.com/download/java-design-patterns-1st-edition-mr-
devendra-singh/

The Basics of Permaculture Design Ross Mars

https://ebookfinal.com/download/the-basics-of-permaculture-design-
ross-mars/

C 3 0 Design Patterns 1st Edition Judith Bishop

https://ebookfinal.com/download/c-3-0-design-patterns-1st-edition-
judith-bishop/

Advanced ActionScript 3 2nd Edition Design Patterns Ben


Smith

https://ebookfinal.com/download/advanced-actionscript-3-2nd-edition-
design-patterns-ben-smith/

Ontology Representation Design Patterns and Ontologies


That Make Sense 1st Edition R. Hoekstra

https://ebookfinal.com/download/ontology-representation-design-
patterns-and-ontologies-that-make-sense-1st-edition-r-hoekstra/
Pro JavaScript Design Patterns 1st Edition Ross Harmes
Digital Instant Download
Author(s): Ross Harmes; Dustin Diaz
ISBN(s): 9781590599082, 159059908X
Edition: 1
File Details: PDF, 2.46 MB
Year: 2008
Language: english
 CYAN  YELLOW
 MAGENTA BLACK
 PANTONE 123 C

Books for professionals by professionals ® The EXPERT’s VOIce ® in Web Development


Companion
eBook
Available

Pro JavaScript Design Patterns ™

Pro JavaScript Design Patterns


Dear Reader,

Pro
Web programming is becoming more complex and collaborative each day. A
new JavaScript™ library is born each week, and we are getting closer to the time
when web applications can seamlessly replace those found on our desktops. It
is no longer possible to design the behavior of your sites haphazardly without
thinking about long-term software maintainability.

JavaScript
The JavaScript language has matured. We have reached a point where soft-
ware development techniques once considered useful only in languages such
as Java and C++ are being applied to web programming. Therefore, we felt the

time has come for a book that explores object-oriented design principles and
applies them to the JavaScript language. The techniques needed to implement
patterns like factory, singleton, observer, composite, and facade in JavaScript
are easily understood, but they have not previously been discussed in depth in
a single book. We wanted to show programmers that JavaScript contains features

Design Patterns
on par with other high-level languages and is an object-oriented programming
language in its own right. In fact, we wrote the book that we ourselves have always


wanted to read.
In this book, we will teach you about commonly used software patterns for
designing the code that drives your websites and applications. You will learn
object-oriented JavaScript programming, starting with routine tasks and pro-
gressing to advanced techniques and patterns. We will help you create libraries
and APIs that can be used by others, as well as show you techniques that will
help you interact with other JavaScript programmers and work effectively in
large teams. Most of all, we will show you how powerful, expressive, and flexible
the JavaScript language can be.

Ross Harmes and Dustin Diaz


The essentials of object-oriented
JavaScript™ programming
Companion eBook Related Titles

See last page for details


on $10 eBook version

SOURCE CODE ONLINE


www.apress.com
ISBN-13: 978-1-59059-908-2
ISBN-10: 1-59059-908-X Harmes,
Diaz
Ross Harmes and Dustin Diaz
54499

US $44.99

Shelve in
Web development

User level:
9 781590 599082
Intermediate–Advanced

this print for content only—size & color not accurate spine = 0.693" 296 page count
908Xch00FM.qxd 11/16/07 1:05 PM Page i


Pro JavaScript
Design Patterns

Ross Harmes and Dustin Diaz


908Xch00FM.qxd 11/16/07 1:05 PM Page ii

Pro JavaScript™ Design Patterns


Copyright © 2008 by Ross Harmes and Dustin Diaz
All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means,
electronic or mechanical, including photocopying, recording, or by any information storage or retrieval
system, without the prior written permission of the copyright owner and the publisher.
ISBN-13 (pbk): 978-1-59059-908-2
ISBN-10 (pbk): 1-59059-908-X
ISBN-13 (electronic): 978-1-4302-0495-4
ISBN-10 (electronic): 1-4302-0495-8
Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1
Trademarked names may appear in this book. Rather than use a trademark symbol with every occurrence
of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark
owner, with no intention of infringement of the trademark.
Java and all Java-based marks are trademarks or registered trademarks of Sun Microsystems Inc. in the
United States and other countries. Apress Inc. is not affiliated with Sun Microsystems Inc., and this book
was written without endorsement from Sun Microsystems Inc.
Lead Editors: Chris Mills, Tom Welsh
Technical Reviewer: Simon Willison
Editorial Board: Steve Anglin, Ewan Buckingham, Tony Campbell, Gary Cornell, Jonathan Gennick,
Jason Gilmore, Kevin Goff, Jonathan Hassell, Matthew Moodie, Joseph Ottinger, Jeffrey Pepper,
Ben Renow-Clarke, Dominic Shakeshaft, Matt Wade, Tom Welsh
Project Manager: Richard Dal Porto
Copy Editor: Jennifer Whipple
Associate Production Director: Kari Brooks-Copony
Production Editor: Kelly Winquist
Compositor and Artist: Kinetic Publishing Services, LLC
Proofreader: Dan Shaw
Indexer: Julie Grady
Cover Designer: Kurt Krames
Manufacturing Director: Tom Debolski
Distributed to the book trade worldwide by Springer-Verlag New York, Inc., 233 Spring Street, 6th Floor,
New York, NY 10013. Phone 1-800-SPRINGER, fax 201-348-4505, e-mail [email protected], or
visit http://www.springeronline.com.
For information on translations, please contact Apress directly at 2855 Telegraph Avenue, Suite 600, Berkeley,
CA 94705. Phone 510-549-5930, fax 510-549-5939, e-mail [email protected], or visit http://www.apress.com.
The information in this book is distributed on an “as is” basis, without warranty. Although every precaution
has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to
any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly
by the information contained in this work.
The source code for this book is available to readers at http://www.apress.com.
908Xch00FM.qxd 11/16/07 1:05 PM Page iii

To Mom, and those who have listened, thanks


—Dustin Diaz

To Alec, Dymphi, and Terry


—Ross Harmes
908Xch00FM.qxd 11/16/07 1:05 PM Page iv
908Xch00FM.qxd 11/16/07 1:05 PM Page v

Contents at a Glance

About the Authors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv


About the Technical Reviewer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii
Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi

PART 1 ■■■ Object-Oriented JavaScript


■CHAPTER 1 Expressive JavaScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
■CHAPTER 2 Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
■CHAPTER 3 Encapsulation and Information Hiding . . . . . . . . . . . . . . . . . . . . . . . . . . 25
■CHAPTER 4 Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
■CHAPTER 5 The Singleton Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
■CHAPTER 6 Chaining . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83

PART 2 ■■■ Design Patterns


■CHAPTER 7 The Factory Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
■CHAPTER 8 The Bridge Pattern. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
■CHAPTER 9 The Composite Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
■CHAPTER 10 The Facade Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
■CHAPTER 11 The Adapter Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
■CHAPTER 12 The Decorator Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
■CHAPTER 13 The Flyweight Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
■CHAPTER 14 The Proxy Pattern. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
■CHAPTER 15 The Observer Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
■CHAPTER 16 The Command Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
■CHAPTER 17 The Chain of Responsibility Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . 245

■INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263

v
908Xch00FM.qxd 11/16/07 1:05 PM Page vi
908Xch00FM.qxd 11/16/07 1:05 PM Page vii

Contents

About the Authors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv


About the Technical Reviewer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii
Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi

PART 1 ■■■ Object-Oriented JavaScript


■CHAPTER 1 Expressive JavaScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
The Flexibility of JavaScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
A Loosely Typed Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Functions As First-Class Objects. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
The Mutability of Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Design Patterns in JavaScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

■CHAPTER 2 Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
What Is an Interface? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Benefits of Using Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Drawbacks of Using Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
How Other Object-Oriented Languages Handle Interfaces . . . . . . . . . . . . . 12
Emulating an Interface in JavaScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Describing Interfaces with Comments . . . . . . . . . . . . . . . . . . . . . . . . . 14
Emulating Interfaces with Attribute Checking . . . . . . . . . . . . . . . . . . . 16
Emulating Interfaces with Duck Typing . . . . . . . . . . . . . . . . . . . . . . . . 17
The Interface Implementation for This Book . . . . . . . . . . . . . . . . . . . . . . . . . 18
The Interface Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
When to Use the Interface Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
How to Use the Interface Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Example: Using the Interface Class . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Patterns That Rely on the Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
vii
908Xch00FM.qxd 11/16/07 1:05 PM Page viii

viii ■CONTENTS

■CHAPTER 3 Encapsulation and Information Hiding . . . . . . . . . . . . . . . . . . . . 25


The Information Hiding Principle. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Encapsulation vs. Information Hiding . . . . . . . . . . . . . . . . . . . . . . . . . . 26
The Role of the Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Basic Patterns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Fully Exposed Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Private Methods Using a Naming Convention . . . . . . . . . . . . . . . . . . . 30
Scope, Nested Functions, and Closures . . . . . . . . . . . . . . . . . . . . . . . . 32
Private Members Through Closures . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
More Advanced Patterns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Static Methods and Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Singletons and Object Factories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Benefits of Using Encapsulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Drawbacks to Using Encapsulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40

■CHAPTER 4 Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Why Do You Need Inheritance? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Classical Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
The Prototype Chain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
The extend Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Prototypal Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Asymmetrical Reading and Writing of Inherited Members . . . . . . . . 46
The clone Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
Comparing Classical and Prototypal Inheritance . . . . . . . . . . . . . . . . . . . . . 49
Inheritance and Encapsulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
Mixin Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
Example: Edit-in-Place . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Using Classical Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Using Prototypal Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
Using Mixin Classes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
When Should Inheritance Be Used? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63

■CHAPTER 5 The Singleton Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65


The Basic Structure of the Singleton . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
Namespacing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
908Xch00FM.qxd 11/16/07 1:05 PM Page ix

■CONTENTS ix

A Singleton As a Wrapper for Page-Specific Code . . . . . . . . . . . . . . . . . . . . 68


A Singleton with Private Members . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
Using the Underscore Notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
Using Closures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
Comparing the Two Techniques. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
Lazy Instantiation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
Branching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
Example: Creating XHR Objects with Branching . . . . . . . . . . . . . . . . . . . . . 79
When Should the Singleton Pattern Be Used? . . . . . . . . . . . . . . . . . . . . . . . 81
Benefits of the Singleton Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
Drawbacks of the Singleton Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82

■CHAPTER 6 Chaining . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
The Structure of a Chain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
Building a Chainable JavaScript Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
Using Callbacks to Retrieve Data from Chained Methods . . . . . . . . . . . . . 89
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90

PART 2 ■■■ Design Patterns


■CHAPTER 7 The Factory Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
The Simple Factory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
The Factory Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
When Should the Factory Pattern Be Used? . . . . . . . . . . . . . . . . . . . . . . . . . 99
Dynamic Implementations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Combining Setup Costs. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Abstracting Many Small Objects into One Large Object . . . . . . . . . . 99
Example: XHR Factory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Specialized Connection Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
Choosing Connection Objects at Run-Time . . . . . . . . . . . . . . . . . . . . 103
Example: RSS Reader . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
Benefits of the Factory Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
Drawbacks of the Factory Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
908Xch00FM.qxd 11/16/07 1:05 PM Page x

x ■CONTENTS

■CHAPTER 8 The Bridge Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109


Example: Event Listeners . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
Other Examples of Bridges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
Bridging Multiple Classes Together . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
Example: Building an XHR Connection Queue . . . . . . . . . . . . . . . . . . . . . . 111
Including the Core Utilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
Including an Observer System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
Developing the Queue Skeleton . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
Implementing the Queue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
Where Have Bridges Been Used? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
When Should the Bridge Pattern Be Used? . . . . . . . . . . . . . . . . . . . . . . . . . 122
Benefits of the Bridge Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
Drawbacks of the Bridge Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123

■CHAPTER 9 The Composite Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125

The Structure of the Composite . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126


Using the Composite Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
Example: Form Validation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
Putting It All Together . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
Adding Operations to FormItem. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
Adding Classes to the Hierarchy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
Adding More Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
Example: Image Gallery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
Benefits of the Composite Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
Drawbacks of the Composite Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140

■CHAPTER 10 The Facade Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141


Some Facade Functions You Probably Already Know About. . . . . . . . . . . 141
JavaScript Libraries As Facades . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
Facades As Convenient Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
Example: Setting Styles on HTML Elements . . . . . . . . . . . . . . . . . . . . . . . . 144
Example: Creating an Event Utility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
General Steps for Implementing the Facade Pattern . . . . . . . . . . . . . . . . . 147
When Should the Facade Pattern Be Used? . . . . . . . . . . . . . . . . . . . . . . . . 148
Benefits of the Facade Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
Drawbacks of the Facade Pattern. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
908Xch00FM.qxd 11/16/07 1:05 PM Page xi

■CONTENTS xi

■CHAPTER 11 The Adapter Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149


Characteristics of an Adapter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
Adapting Existing Implementations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
Example: Adapting One Library to Another . . . . . . . . . . . . . . . . . . . . . . . . . 150
Example: Adapting an Email API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
Wrapping the Webmail API in an Adapter . . . . . . . . . . . . . . . . . . . . . 157
Migrating from fooMail to dedMail . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
When Should the Adapter Pattern Be Used? . . . . . . . . . . . . . . . . . . . . . . . . 158
Benefits of the Adapter Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
Drawbacks of the Adapter Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158

■CHAPTER 12 The Decorator Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159


The Structure of the Decorator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
The Role of the Interface in the Decorator Pattern . . . . . . . . . . . . . . 163
The Decorator Pattern vs. the Composite Pattern . . . . . . . . . . . . . . 163
In What Ways Can a Decorator Modify Its Component? . . . . . . . . . . . . . . 164
Adding Behavior After a Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
Adding Behavior Before a Method . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
Replacing a Method. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
Adding New Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
The Role of the Factory. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
Function Decorators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
When Should the Decorator Pattern Be Used? . . . . . . . . . . . . . . . . . . . . . . 173
Example: Method Profiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
Benefits of the Decorator Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
Drawbacks of the Decorator Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177

■CHAPTER 13 The Flyweight Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179


The Structure of the Flyweight . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
Example: Car Registrations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
Intrinsic and Extrinsic State . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
Instantiation Using a Factory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
Extrinsic State Encapsulated in a Manager . . . . . . . . . . . . . . . . . . . . 182
Managing Extrinsic State . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
Example: Web Calendar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
Converting the Day Objects to Flyweights . . . . . . . . . . . . . . . . . . . . . 185
Where Do You Store the Extrinsic Data? . . . . . . . . . . . . . . . . . . . . . . 186
908Xch00FM.qxd 11/16/07 1:05 PM Page xii

xii ■CONTENTS

Example: Tooltip Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186


The Unoptimized Tooltip Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
Tooltip As a Flyweight . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
Storing Instances for Later Reuse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
When Should the Flyweight Pattern Be Used? . . . . . . . . . . . . . . . . . . . . . . 192
General Steps for Implementing the Flyweight Pattern . . . . . . . . . . . . . . 193
Benefits of the Flyweight Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
Drawbacks of the Flyweight Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194

■CHAPTER 14 The Proxy Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197


The Structure of the Proxy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
How Does the Proxy Control Access to Its Real Subject? . . . . . . . 197
Virtual Proxy, Remote Proxy, and Protection Proxy . . . . . . . . . . . . . . 200
The Proxy Pattern vs. the Decorator Pattern . . . . . . . . . . . . . . . . . . . 201
When Should the Proxy Be Used? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
Example: Page Statistics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
General Pattern for Wrapping a Web Service . . . . . . . . . . . . . . . . . . . . . . . 205
Example: Directory Lookup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206
General Pattern for Creating a Virtual Proxy . . . . . . . . . . . . . . . . . . . . . . . . 210
Benefits of the Proxy Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
Drawbacks of the Proxy Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214

■CHAPTER 15 The Observer Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215


Example: Newspaper Delivery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
Push vs. Pull . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
Pattern in Practice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
Building an Observer API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218
Delivery Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
Subscribe . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
Unsubscribe . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
Observers in Real Life. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
Example: Animation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
Event Listeners Are Also Observers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222
When Should the Observer Pattern Be Used? . . . . . . . . . . . . . . . . . . . . . . 223
Benefits of the Observer Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
Drawbacks of the Observer Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
908Xch00FM.qxd 11/16/07 1:05 PM Page xiii

■CONTENTS xiii

■CHAPTER 16 The Command Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225


The Structure of the Command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
Creating Commands with Closures . . . . . . . . . . . . . . . . . . . . . . . . . . 227
The Client, the Invoker, and the Receiver. . . . . . . . . . . . . . . . . . . . . . 227
Using Interfaces with the Command Pattern. . . . . . . . . . . . . . . . . . . 228
Types of Command Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228
Example: Menu Items . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
The Menu Composites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
The Command Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
Putting It All Together . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
Adding More Menu Items Later On . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
Example: Undo and Logging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
Implementing Undo with Nonreversible Actions By Logging
Commands. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
Logging Commands for Crash Recovery . . . . . . . . . . . . . . . . . . . . . . 242
When to Use the Command Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242
Benefits of the Command Pattern. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243
Drawbacks of the Command Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244

■CHAPTER 17 The Chain of Responsibility Pattern . . . . . . . . . . . . . . . . . . . . . . 245


The Structure of the Chain of Responsibility. . . . . . . . . . . . . . . . . . . . . . . . 245
Passing on Requests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251
Implementing a Chain of Responsibility in an Existing Hierarchy . . . . . . 254
Event Delegation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
When Should the Chain of Responsibility Pattern Be Used? . . . . . . . . . . 255
Example: Image Gallery Revisited. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256
Using the Chain of Responsibility to Make Composites
More Efficient . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
Adding Tags to Photos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258
Benefits of the Chain of Responsibility Pattern . . . . . . . . . . . . . . . . . . . . . 261
Drawbacks of the Chain of Responsibility Pattern . . . . . . . . . . . . . . . . . . . 262
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262

■INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263

f7670b088a34e6aa65a5685727db1ff4
908Xch00FM.qxd 11/16/07 1:05 PM Page xiv
908Xch00FM.qxd 11/16/07 1:05 PM Page xv

About the Authors

■ROSS HARMES is a front-end engineer for Yahoo! in Sunnyvale, California.


Educated as an electrical and computer engineer, Ross quickly put down
the soldering iron and oscilloscope and focused on the software aspect of
his degree. After discovering that debugging memory leaks is not much fun,
he dove into the muddy and turbulent waters of web programming. He has
been happily swimming there ever since.
This is Ross’s first book, but he has been publishing his stray thoughts
online for years. These days his technical ramblings can be found at
http://techfoolery.com.

■DUSTIN DIAZ is a user interface engineer for Google in Mountain View,


California. He enjoys writing JavaScript, CSS, and HTML, as well as making
interactive and usable interfaces to inspire passionate users. Dustin has
written articles for Vitamin and Digital Web Magazine, and posts regularly
about web development at his site, http://dustindiaz.com.

xv
908Xch00FM.qxd 11/16/07 1:05 PM Page xvi
908Xch00FM.qxd 11/16/07 1:05 PM Page xvii

About the Technical Reviewer

■SIMON WILLISON is a consultant on client- and server-side web development and a cocreator
of the Django web framework. Simon’s interests include OpenID, unobtrusive JavaScript,
and rapid application development. Before going freelance, Simon worked on Yahoo!’s
Technology Development team, and prior to that at the Lawrence Journal-World, an award-
winning local newspaper in Kansas. Simon maintains a popular web development weblog
at http://simonwillison.net/.

xvii
908Xch00FM.qxd 11/16/07 1:05 PM Page xviii
Discovering Diverse Content Through
Random Scribd Documents
CHAPTER VII.
A STRANGE FANCY.

“What was that?” asked Mabin with a shiver.


She and Rudolph had both turned instinctively toward the spot
from which the rustling noise had come.
“A cat, most likely,” answered Rudolph.
But Mabin shook her head.
“I saw something,” whispered she. “It was not a cat, it was not an
animal at all; it was a man.”
Perhaps Rudolph had his suspicions, for he expressed no
surprise. Before he could answer her they heard the crackling and
rustling again, but at a little distance. The intruder was making his
way through the shrubbery.
“Won’t you find out who it is?” whispered the girl again.
Rudolph hesitated.
“Perhaps I know,” said he shortly. “But if you wish, of course I can
make sure.”
Then, with evident reluctance, and taking no pains to go
noiselessly, he followed the intruder through the bushes, and was in
time to catch a glimpse of him as he disappeared over a part of the
fence that was in a broken-down condition. Rudolph did not attempt
to continue his pursuit, but contented himself with waiting until he
heard the side gate in the garden wall of “Stone House” swing back
into its place with a loud creaking noise. Then he went back to
Mabin. She was standing where he had left her, on the broad gravel
path under the faded laburnum. The shadows were very deep under
the trees by this time, and in the half-light her young face, with its
small, delicate features, its dreamy, thoughtful eyes, full of the
wonder at the world of the very young, looked so pretty that for the
moment Rudolph forgot the errand on which he had been sent, and
approached her with no thought of anything but the beauty and the
sweetness of her face.
She, all unconscious of this, woke him into recollection with one
abrupt word: “Well?”
“Oh!” almost stammered he, “it was as I thought, the same person
that I saw watching before.”
“And he went into our garden. I heard the gate,” said Mabin with
excitement. “It must be this Mr. Banks. Oh, who do you think he is?
What do you think he has come for?”
Rudolph was silent. Even to the least curious mind the
circumstances surrounding both him and Mrs. Dale could not seem
other than mysterious. If he were a detective, and he certainly did
not look like one, surely he would not go to work in this extravagant
manner, by renting a large and expensive house merely for the
purpose of watching his next-door neighbor. Neither, it might be
supposed, would he set to work in such a clumsy fashion as to be
caught making his investigations at the very outset. Rudolph felt that
the whole affair was a mystery to which he could not pretend to have
the shadow of a clew. He confessed this to Mabin.
“I wish,” he went on, in a gentle tone, “that I had known something
of this before your father went away.”
“Why?” asked Mabin in surprise, and with something like revolt in
her tone.
“Because I should have told him something, just enough at any
rate to have made him take you away with him.”
Mabin was for a moment dumb with surprise.
“What,” she stammered at last, “after all your talk about my being
right to stand by my friend?”
“Even after all that,” assented Rudolph with decision. “The matter
is getting too serious,” he went on gravely. “I am afraid myself of
what may be going to happen.”
“Then,” retorted the girl, “for all your talk about meanness being
excusable in a girl, I can be a better friend than you.”
Rudolph smiled.
“Ah,” said he, “you forget that with you it is only a question of your
friendship for Mrs. Dale. Now I have to think of both of you.”
“You need not trouble yourself about me, I assure you.”
“But that is just what I must do, madam, even at the risk of your
eternal displeasure,” said Rudolph, with a mock-heroic air which
concealed real anxiety. “You are not only daring enough, you are too
daring where your heart is concerned, and it is the business of your
friends to see that you do not suffer for your generosity.” He spoke
with so much quiet decision that Mabin was impressed and rather
frightened, and it was with a sudden drop from haughtiness to
meekness that she then asked:
“What are you going to do, then?”
Rudolph hesitated.
“What I should like to do,” said he, “is to take you to my mother’s
——”
Mabin almost screamed.
“You won’t do that,” she said quietly, with her lips very tightly
closed.
“She would be very kind to you,” suggested Rudolph gently,
pleadingly.
He knew the prospect was not an enticing one, but he was not so
quick as the girl to see all its disadvantages.
“And don’t you see that it would set them all saying the most
dreadful things about poor Mrs. Dale, if I were to leave her suddenly
like that? I shouldn’t think of such a thing. It would be cruel as well as
cowardly. She would never be able to stay in Stone after that.”
“I don’t think she will be able to stay in any case,” said Rudolph
gloomily. “If she is persecuted by this spy on the one hand, and by
the old woman on the other, it isn’t likely that she will be able to stay
here long.”
A new idea flashed suddenly into Mabin’s mind and then quickly
found expression:
“Do you suppose,” she asked, “that this man, this Mr. Banks, is
paid by the old lady to spy upon Mrs. Dale? The old lady must be
very rich, I think, and she is eccentric evidently.”
But Rudolph was inclined to think this idea far-fetched. From what
he had seen of the mysterious spy he had come to quite another
conclusion, one that at present he did not care to communicate to
Mabin, for fear of alarming her unnecessarily.
“Of course it is possible that the man may be a paid detective,”
admitted he doubtfully, “but there was nothing of the cut of the ex-
detective about your Mr. Banks. And now,” went on Rudolph, who
found Mabin herself a more interesting mystery than the unknown
man, “let us forget all about him for a little while, and go up to the old
seat where the trees leave off, before it gets too dark for us to see
the sea. You remember the old seat, and how we used to trespass to
get at it, don’t you?”
Mabin blushed a little. She remembered the old seat very well; an
old broken-down bench supported on the stumps of a couple of
felled trees, just on the edge of the plantation belonging to “The
Towers.” Being conveniently near both to “Stone House” and the
Vicarage, the children of both houses had established, in those far-
off years which Rudolph was recalling, a right to tread down the old
fence at that particular point, and to hold wonderful picnics of
butterscotch and sour apples.
“We won’t go up there now,” she said, with a sudden demureness
which contrasted strongly with the eagerness she had shown while
discussing the persecution of Mrs. Dale. “It’s getting dark, and rather
cold, I think, and besides, I hope by this time that Mrs. Dale may be
ready to see us again.”
Rudolph felt snubbed. The girl’s manner was so precise, so stiff,
that it was impossible for him to understand that her sudden
primness was only a relapse into her ferocious girlish modesty. He
followed her without a word toward the house, and there just inside
the portico they saw the slight figure in black looking like a pathetic
vision in the gloaming, with its white, tear-stained face and slender
little jewelled hands.
“Well?” said Mrs. Dale. And her voice was hoarse and broken. “I
have been waiting here for you, wondering where you had gone. I
had almost begun to think,” she went on, with assumed playfulness,
which did not hide the fact that her fear had been real, “that you had
run away from me altogether.”
Mabin lost her awkwardness, her stiffness, her shy, girlish reserve
in an instant; moved by strong pity and affection, she took the two
steps which brought her under the portico, and stooping, flung her
arms round the little figure.
“You didn’t—really?” she whispered hoarsely. “Oh, I hope not, I
hope not!”
Mrs. Dale could not answer. But Mabin felt her frame quiver from
head to foot, and heard the sound of a stifled sob. Rudolph stepped
noiselessly out into the garden again.
“My dear, my dear child,” murmured Mrs. Dale, when she had
recovered some of her self-possession by a strong effort, “you would
have been quite justified if you had gone. But I am glad, oh, so glad,
that you have waited for me to drive you away.”
“You won’t do that!” cried Mabin, starting back, and seeing with
surprise in the fair, blue-eyed face an expression of strong
resolution. “After pretending you were so glad to have me!”
“It was no pretence, believe me!” said Mrs. Dale with a sad little
smile. “But I have got to send you away all the same. It would not be
right to keep you here, now that I see the persecution I am to be
subjected to still.” And her blue eyes flashed angrily as she spoke.
But the next moment her face changed again, and she added
quickly, “I have deserved it all. More than all. I am not complaining of
that; I have no right to complain. Only—she might have spared you. I
should have done you no harm; you would have learnt no evil from
me, wicked as I am.”
The girl interrupted her, with a frightened face, and speaking in an
eager whisper:
“Oh, hush, hush! You are not wicked. It is dreadful to hear you say
such things! I will not let you say them. You have the kindest heart in
the world; if you have ever done wrong, you are sorry, bitterly sorry.
Wicked people are never sorry. Let me stay with you and comfort
you if I can, by showing you how happy it makes me to be with you!”
Mrs. Dale shook her head. She did not, however, repeat in words
her resolve that Mabin must go, though the girl guessed by the
expression of her face that her mind was made up on the subject.
They stood silently looking out at the soft beauties of the twilight,
the greens as they melted into grays blending in such a tender
harmony of color that the sight seemed to supply a balm, through
tear-dimmed eyes, to their heavy hearts; the scent of the roses came
to them across the broad space of gravel, too, mingled with the
pleasantly acrid perfume of the limes.
Rudolph’s step, as he took advantage of the silence to thrust
himself again upon the notice of the ladies, startled them both.
“Now you’ve spoilt it all!” cried Mrs. Dale, in a tone which was
meant to be one of light-hearted pleasantry, but which betrayed too
plainly the difficulty she had in assuming it. “The garden looked like a
fairy picture till you rushed in and ruined the perspective. Aren’t you
going to apologize?”
“No. The picture wanted human interest, so I painted myself into
the canvas, just to satisfy your artistic susceptibilities. I am sorry to
find you so ungrateful. I hope you, Mabin, have more appreciation?”
But the girl’s eyes were full of tears, and not being used to this
light strain of talk, she could not answer, except by a few mumbled
words which had neither sense nor coherence. Mrs. Dale put up her
hand—she had to stretch it up a long way—and smoothed the girl’s
pretty brown hair.
“Don’t tease her,” she said softly. “Mr. Bonnington, I mustn’t ask
you to dine with us, but I would if I might.”
“And why mustn’t you?” asked Rudolph.
“Well, because, in the miserably equivocal position I am in, it
would be a pleasure—if I may take it for granted that it would be a
pleasure to you, as it would certainly be to me—dearly bought. The
Vicar would strongly disapprove; your mother would be shocked
beyond measure.”
“But I shouldn’t mind that, I assure you. I’ve shocked my mother
and excited the disapproval of my father so often that they don’t
expect anything else from me. Besides, I am afraid you flatter
yourself too much in believing that you have such an enviable
peculiarity; if you were to issue invitations to the whole parish to a
garden party, or a dinner, or anything you liked, I’m afraid you would
be disappointed to find that everybody would come.”
“Perhaps they would think there was safety in numbers, and that,
fortified by the presence of everybody else, they could gaze at the
monster in security!” suggested Mrs. Dale with a smile.
“In the mean time how much nearer have I got to get to inviting
myself to dinner this evening?” said Rudolph, with a subdued voice
and a meek manner.
“Ah, well, for Mabin’s sake then, I spare you the humiliation and
invite you myself. You shall stay to amuse her, since I am afraid she
would find me a very dreary companion.”
“Indeed I shouldn’t,” cried Mabin, blushing deeply, and speaking
with as much energy as if the presence of Rudolph were an injury. “I
should like nothing better than an evening alone with you.”
Rudolph drew a deep sigh, and even Mrs. Dale could not suppress
a smile at the girl’s unconscious gaucherie. When Mabin realized
what a stupid thing she had said, she was of course too much
ashamed of herself to laugh at her clumsy words, and fell, instead,
into a stiff silence which the others found it impossible to make her
break except by demure monosyllabic answers.
When they went into the dining-room, therefore, the evening did
not promise to be a lively one. Mrs. Dale seemed to find it impossible
to shake off the effects of the visit of her persecutor. Rudolph was
oppressed by fears for both the ladies, and by doubts whether his
presence there was not an indiscretion which would make matters
worse for both of them. While Mabin, perplexed and troubled by a
score of unaccustomed sensations, was the most silent, the most
distressed of all.
Daylight was still streaming in from the West as they took their
seats at the table in the dingily furnished room. Mrs. Dale gave a
little shudder as she glanced from the “furnished house” knives to
the commonplace dinner service.
“Ah!” she said, “it is not like this that I used to entertain my friends.
My little dinners had quite a reputation—once!”
Then, as if she felt that these regrets were worse than vain, she
turned the subject abruptly, while a spasm of pain for the moment
convulsed her face.
Rudolph on his side was sorry she had mentioned the “little
dinners.” They suggested a past life in which there had been
something more than frivolity; something with which he would have
dissociated Mrs. Dale if he could. But innocent Mabin, wishing to say
something, brought the conversation back to the point it had left.
“But why can’t you have pretty dinners now, if you like to?”
Mrs. Dale’s fair face grew whiter as she answered gently:
“I will tell you—presently—some day—why I don’t have anything
pretty or nice about me now.”
And Mabin, feeling that she had touched a painful chord, became
more silent than ever.
Perhaps it was her sudden subsidence into absolute gloom which
caused the other two to make a great effort to restore something like
animation to the talk. And being both young, and of naturally high
spirits, they succeeded so well that before the meal which had begun
so solemnly was over, Mrs. Dale and Rudolph were talking and
laughing as if there had never been a shadow upon either of their
lives. At first they made brave attempts to drag Mabin into the
conversation. But as these efforts were in vain, it naturally ended in
her being left out of the gayety, and in her sitting entrenched in a
gloomy silence of her own.
And when dinner was over, and they all went into the little
adjoining room which Mrs. Dale called her “den,” it was quite natural
that Mrs. Dale should sit down at the piano, in the good-natured wish
to leave the young people to entertain each other; and equally
natural that Rudolph, on finding that Mabin had nothing to say to
him, and that she was particularly frigid in her manner, should go
over to the piano, and by coaxing Mrs. Dale to sing him his favorite
songs and then hers, should continue the brisk flirtation begun at the
dinner-table.
Mabin had brought it all upon herself, and she tried to persuade
herself that it was quite right and natural, and that she did not mind.
And when Rudolph was gone, and she was alone with her hostess,
she succeeded in persuading her that she had not felt neglected, but
had enjoyed the merriment she had refused to share.
But when she got upstairs into her pretty bedroom, after bidding
Mrs. Dale good-night, she had the greatest difficulty in keeping back
the tears which were dangerously near her proud eyes.
She did not care for Rudolph, of course not; she wanted him to fall
in love with Mrs. Dale, if indeed he had not already done so, and
marry her and console her for all her troubles, and stop the
persecution of “the cat.” But somehow this hope, this wish, did not
give her all the unselfish satisfaction it ought to have done.
And Mabin, wondering what had happened to take the prettiness
out of the room and the pleasure out of her acquaintance with Mrs.
Dale, fell asleep with her heart heavy and full of nameless grief.
She woke with a start to find a white figure standing motionless in
the middle of the room. Mabin sprang up in bed and rubbed her
eyes. Was she awake? Or was she only dreaming that the body of a
dead woman, stiff, rigid, but in an upright position, was standing like
a marble statue between the bed and the nearest window?
She leaped out of bed, and, not without uncanny fears, touched
the statuesque figure.
“Mrs. Dale!” she almost shrieked, as the great eyes suddenly
turned and fixed a blank, wild gaze upon her face. “Oh, what has
happened? What is the matter?”
The figure, which, in white night garments, had looked so unlike
the black-robed widow that she had not recognized it, trembled from
head to foot. The lips parted, but at first no word escaped them. At
last with a strong effort she uttered these words:
“Let me stay here. Let me sit in this arm-chair till morning. Oh, I
will not hurt you, or frighten you. But if I go back I shall go mad! This
house is haunted, haunted! I have seen——”
A hoarse rattle in her throat seized her, threatened to choke her.
With one wild glance round, peering into the corners of the room,
she flung herself on the floor, and buried her face in the chair.
CHAPTER VIII.
A HAUNTED HOUSE.

Mabin was taken so thoroughly by surprise, on seeing the wild


self-abandonment of her unhappy companion, that for a few minutes
she stood staring at the crouching figure on the floor like one only
half-awake.
Was this really Mrs. Dale, this haggard, panting creature with the
hoarse voice, the twitching hands, the wide eyes full of unspeakable
terror. Mabin’s sympathy was ready, but at first she did not dare to
offer it. Such terrible anguish, such paralyzing fear, as that from
which the miserable woman was suffering, was something surely
beyond her poor powers of comfort! And even as the girl advanced
timidly a step nearer to her grief-stricken friend, there flashed into
her mind the horrible question: What must this secret be which was
locked in the widow’s breast, that could throw her into such
paroxysms of abject terror? For, not unnaturally, Mabin came to the
conclusion that the vision which had alarmed Mrs. Dale was one of
the results of the remorse from which she owned that she was
suffering.
“Don’t! Don’t sob like that! You will make yourself ill; you will
indeed. There is nothing, there is nobody here to frighten you,” said
the girl at last, drawing a little closer to the crouching figure, but not
yet daring to touch her, or to speak in a tone louder than a whisper.
At the first sound of her voice, Mrs. Dale had started, and raised
her head quickly, turning to the girl’s view a face so much altered, so
drawn, so old-looking, that she hardly recognized the features of the
lovely widow. Then, when the voice ceased, she glanced round the
room again, with the same hunted, anxious look as before.
“Nothing—nobody to frighten me!” she repeated in a shaking
voice. “No, of course not, of course not. How silly I have been! I am
afraid I frightened you, dear,—with my dreams, my silly fancies!”
She struggled, as if worn out and exhausted by her emotion, to
gain her feet. Timidly, gently, Mabin helped her to rise.
“I’m very glad I was here,” answered Mabin, in kindly tones that
sent a shiver of grateful recognition through her agitated companion.
“Do you feel better now?”
“Yes, oh, yes, I am all right. I am not ill. I am so much ashamed of
myself for disturbing you. I don’t know how to apologize,” answered
Mrs. Dale, trying bravely to speak in her usual tone, but glancing at
the door and then back to the windows as she uttered the words: “It
must have been a dream, of course, that frightened me.”
And then, quite suddenly, she broke down again, and slipping from
the supporting arm of her young companion, she threw herself into
the wicker arm-chair, and burst into a passion of tears. Uncertain
what to do, Mabin, in her sympathy and kindness, did exactly the
right thing. She drew another chair besides the wicker one, sat down
in it, and putting her right arm round Mrs. Dale’s shoulder, and
holding the poor lady’s trembling fingers in her own, remained in
perfect silence until the first ebullition of violent grief had passed
away.
“I shall never forget your kindness, child, never,” said Mrs. Dale,
when, as suddenly as it had begun, her passion of tears ended. “You
have saved me from going mad—yes, mad. I—I must leave you now,
or you won’t get any rest.”
She rose as she spoke; but Mabin saw that the panic of terror
which had been upon her at her entrance was regaining its hold
upon her as she approached the door. With her fingers on the handle
she stopped, and seemed once more to grow rigid with fear.
Mabin was by her side in an instant.
“Stay here,” she said. “You will have the dream again perhaps, if
you go away by yourself.”
At these words a shiver ran through Mrs. Dale, and she faltered.
“It must have been that gloomy room!” she said at last in a
whisper. “And the effect of her visit! But it will kill me if it comes
again!” Suddenly she turned to Mabin. “May I lie on the sofa until the
morning?” she asked piteously. “I won’t disturb you. I feel as if I
should be safe from—it—in here with you?”
The wistful pleading in her eyes brought the tears to Mabin’s.
“Of course you must stay,” she cried heartily. “And I do hope you
will get to sleep, and not have any more dreams.”
Very quietly Mrs. Dale lay down on the couch between the
windows, and drawing the sofa blanket over her, and refusing any
other covering, she closed her eyes. Mabin knew that this apparent
tranquillity was assumed only, and she placed herself on the bed in
such a position that she could watch her friend, while appearing to
be herself asleep.
Before many minutes had passed, she saw, from between half-
closed eyelashes, that Mrs. Dale was sitting up, and bending her
head in a listening attitude. And presently the slender figure with its
white dressing-gown slipped softly off the sofa, and hurried on tiptoe
across the floor to the door. There it knelt down and listened again.
And after a few minutes Mrs. Dale turned the key in the lock and
crept back, not to the couch, but to the arm-chair.
Mabin shut her eyes and tried to disentangle the knot of strange
ideas that filled her brain:
What was the nature of the secret which weighed on the
conscience of Mrs. Dale? Why was she kept in luxury by the very
woman who tried to make her life unbearable, to cut her off from
every human friend? What was the strange tie between the hard,
elderly woman and the impulsive, volatile young one? What was the
vision which had caused her so much distress? And, above all, why,
if it was only a vision, did she try to keep it away by locking the door?
And why—and why—? More questions surged up into her tired
brain; but Mabin forgot them as they rose. She fell asleep.
When she awoke in the morning it was to find that some one was
knocking at the door, and then she heard the housemaid’s voice
announcing that it was eight o’clock. She sprang up, and looked
toward the sofa, but there was no one but herself in the room.
Surely, she thought, the strange visit of the night must have been
a dream? The rug on the sofa was neatly folded, just as it had been
when she came up to bed last night. Not a sign was to be seen of
any intrusion during the night.
Even when she went downstairs and met Mrs. Dale in the hall,
there was little to tell of the experience of the hours of darkness.
Perhaps the pretty widow looked a little paler than usual, but in every
other respect she was the same airy, impulsive creature, now
smiling, now looking sad, as she had been before the dreadful visit
of the lady whom irreverent Mabin called “the cat.”
It was not indeed until breakfast was over and they had gone out
into the garden to cut some flowers while the dew was on them, that
either of the ladies made any reference to the events of the night.
Mrs. Dale, with one daintily shod foot in a flower-bed, was
stretching out her hands toward a bush of sweet-peas, when, without
turning her head, she said:
“I am in great trouble about you, Mabin.”
“Are you? Why, Mrs. Dale?”
“I don’t quite know what to do with you. If I send you to Mrs.
Bonnington, I shall have to tell some shocking tarradiddle about the
drains having come up, or the roof having given way, and she will be
sure to find me out and to pry, and to give both of us what the old
women call ‘much unpleasantness.’ And if I send you on to Geneva,
I don’t know whether they will be glad to see you when you arrive.”
“And I’m sure they won’t,” said Mabin heartily. “And there is one
other objection to sending me anywhere, and that is that I won’t go.”
Mrs. Dale dropped her sweet-peas, and turned round. Her eyes
were full of sudden tears.
“Nonsense, child!” she said sharply, but in a querulous tone which
betrayed her emotion, “nonsense! It was decided yesterday
afternoon that you were to go. You know it was.”
“You decided that I was to go. I didn’t. And—” instinctively she
dropped her voice—“And something that happened last night—in the
night, made me decide not to go. There!”
“But, my dear——”
“No, Mrs. Dale, I’m not to be ‘got round.’ You’ve chosen to take me
upon your shoulders, so now you must just keep me. Ha, ha! You
didn’t know I had so much determination, did you?”
But Mrs. Dale could scarcely speak. Now for the first time that
morning Mabin realized that the scene of the night had really taken
place, for the emotion aroused by this little bit of talk had brought
back into Mrs. Dale’s blue eyes a faint reproduction of the wild terror
she had shown when she came to the girl’s room. When she had
recovered her voice, the lady in black, pale, hoarse, shaken with her
agitation, stammered out these words:
“My dear girl, it is beautiful of you to offer to stay. But I cannot let
you. You ought never to have come. I was mad, wicked to let you
come; and my madness and my wickedness I must bear alone.”
How strange these words seemed in the broad daylight, Mabin
thought! By the weak glimmer of the night-light Mrs. Dale’s wild looks
and words had seemed fantastic, weird. But the broad sunlight
seemed to give the nameless horror which hung about the poor little
lady in black a reality as vivid as it was painful. But with this feeling
there came also into the heart of the young girl a great tenderness
toward the suffering woman, who was haunted by the shadow of her
own past. So she smiled, and with a pretty, half-shy look in her eyes,
said:
“You told me I saved you from going mad. So I mean to stay. And I
mean to sleep in the same room with you, so that you shall not be
frightened any more.”
Mrs. Dale shook her head.
“I can’t let you do that,” said she. “I don’t sleep very well, and
sometimes I start up and cry out. I should frighten you.”
“Then we will exchange rooms,” said Mabin.
By the look of joy and relief which flashed over Mrs. Dale’s face at
this suggestion, Mabin saw that she had conquered.
“But—won’t you be afraid?” asked the widow in a troubled voice.
“What! Of a ghost, a vision? Or of having bad dreams? No, not a
bit.”
Mrs. Dale glanced gratefully at the young face, with its look of
robust Philistine scorn of phantoms.
“It is a temptation,” she murmured. “For, after all, I know, I know
that it was only a dream, a horrible dream. And there is no fear that
the dream will come to you.”
“And if it did,” retorted Mabin stoutly, “it wouldn’t frighten me. I’m
too ‘stodgy;’ I have no imagination.”
Mrs. Dale smiled sadly.
“You are right,” she said. “If you did have the same dream, it would
have no terrors for you. Your conscience is clear.”
“And my digestion good,” added Mabin lightly, as she picked up
the fallen flowers and put them in her basket.
There was no doubt that her refusal to go had taken a load of
melancholy from the shoulders of her hostess, who sent the young
girl out for a walk as soon as the gathering of the flowers was over,
and charged her not to go far enough to tire her still weak ankle.
Mabin, with a book and a sunshade, sauntered slowly down the
hill to the nearest gap in the cliff, and went down the steep descent
to the sands. This was no paradise of nursemaids and babies, but a
solitary nook beloved by quiet maiden ladies and sentimental
couples. With rash disregard of the danger of sitting under a chalk
cliff, Mabin found a seat on a rock worn smooth by the sea, opened
her book and began—not to read.
The circumstances to which she found herself were far too
interesting for her to be able to give herself up to the milder
excitements of fiction. She sat with her open book on her lap and her
eyes staring out at the sea, which was vividly blue in the strong
sunshine, when she became suddenly conscious of a footstep she
knew in her immediate neighborhood.
Although she affected to be surprised when Rudolph appeared
before her, she had known that he was approaching, and her heart
began to beat very fast. He looked down at her between the spikes
of her sunshade, pretending to be afraid to speak to her.
“Good-morning,” said she at last.
“I was wondering whether I dared say the same thing!”
“Dared?”
“Yes. After your treatment of me last night, I felt nervous.”
“My treatment of you! What treatment?”
“Why were you so unkind? Or mustn’t I ask why?”
“You may ask, of course. But I can’t give you any answer, because
I didn’t know that I was unkind.”
“I wish I could believe that.”
“Well, if you won’t believe it, I have nothing to say.”
Rudolph was silent a few minutes. Then with a burst of explosive
energy, he made up his mind.
“No!” he cried so loudly that Mabin started, and threw himself
down on the sand beside her, “I will not be daunted. I will encase
myself in double snub-proof armor plates, and I will try to teach her
that to be dignified it is not necessary to be unkind—and—yes, I will
say it—absolutely rude.”
Mabin became crimson, and the tears started to her eyes. She
had not meant to be rude, but undoubtedly her behavior had laid her
open to this accusation.
“I am stupid, clumsy; I am rude without meaning it,” she said in a
tone of such excessive humility and penitence that it was impossible
to doubt her sincerity. “I am very sorry. But you shouldn’t take any
notice of what I do or say. Nobody does at home. When I am more
awkward and tiresome than usual, they always say: ‘Oh, it’s only
Mabin!’ And then nobody minds.”
“Ah, well, I can’t quite feel like that—that it’s only Mabin. When one
likes a person, and wants to be good friends, very good friends with
that person, just as one used to be when that person and one’s self
were little things in short frocks and knickerbockers, it is very
disheartening to find that person so determined to be—er—to be—er
—so reserved that when one sits beside that person as I did last
night, you know, she will only let one see so much of her right ear as
to practically turn her back to one!”
“I didn’t!”
“You did though. And it is what you were doing again just now until
the horror of hearing the truth made you turn around to fly at me! You
did turn your back upon me last night, Miss Rose, and you hurt my
feelings.”
“Indeed, you did not seem to be hurt. You seemed to be enjoying
yourself very much!”
“Well, so I was in a way. But I should have enjoyed myself much
more if you had been as nice as you were in the garden.”
Mabin heaved a deep sigh.
“It’s no use expecting me to be nice,” she said in a voice of
despair, “I can only manage it so very seldom.”
“Well, could you hold out some signal, such as by wearing a
particular flower, or color, or some especial knot of ribbon, to let one
know when one may speak to you without being snubbed?”
“No, I couldn’t,” retorted Mabin with great fierceness, but with a
twinkle of fun in her gray eyes, which gave greater hopes than her
words did. “It is of no use for me to promise more than I can perform.
You had much better look upon me as a decidedly disagreeable
person, with rare moments of proper behavior.”
“Proper behavior, then, means niceness? I’m glad you think it
proper to be nice to me!” said Rudolph. “I perceive that I’ve lighted
upon one of the ‘rare moments,’ and I’m going to take advantage of
it,” he added, as he came a little nearer to her, and looked up in her
face with a glance of amusement and admiration which made her
blush a little. “I’m going to make you talk to me, and amuse me, as
you were told to do last night.”
“No! It was you who were told to amuse me!”
“Was it? Well, we’ll take it in turn then. Do you remember how I
taught you cricket?”
“Yes, oh yes.”
“And what a rage you used to be in when you were caught out?”
“Yes,” answered Mabin, “I remember; but I don’t want to talk about
cricket. I want to tell you something. Mrs. Dale has a fancy that ‘The
Towers’ is haunted.”
And she related the adventure of the previous night, and her
intention of changing rooms with her hostess.
Rudolph listened gravely, and there was a pause when she had
finished before he made any comment. Then he said abruptly:
“You are not nervous, are you, Mabin? I know you used to have no
end of pluck.”
“Well, I haven’t any less than I ever had.”
“Well, if you do change rooms, you have got to be prepared to see
the ghost yourself.”
“You make me feel rather—rather creepy! What do you really think
I shall see?”
“A face at the window probably. The face of the spy from your
house. What else can she have seen?”
Mabin considered a moment.
“I’ll risk it!” she cried at last. “I shan’t go to bed at all. I shall sit up
and watch.”
“I wish you would. We should find out something if you had the
strength of mind to do that.”
Not without a wild beating of the heart, Mabin undertook the task
of holding the strange night-watch, without saying a word to Mrs.
Dale of her intention.
“She thinks she only had a dreadful dream, you know,” said Mabin.
“Well,” replied Rudolph, “I want to know what sort of dream you
will have.”
He had to admire the courage she showed in undertaking a task
which was, as she expressed it, “rather shuddery,” but when he left
her at the gate of “The Towers” she was still steadfast in her
intention.
It was not until after dinner that evening that Mrs. Dale introduced
the young girl to the apartment she was to occupy that night. Mabin
was astonished at its dinginess, its gloominess, contrasting so
strongly as they did with the fresh prettiness of the room which had
been prepared for herself.
It was a large square room, with a mouldy old-fashioned wall-
paper, on which unnatural pink roses climbed up a succession of thin
hop poles. The pictures were groups of trees, done with the pencil in
the woolly early Victorian manner, and stiff bouquets, in water-color,
of conventional early Victorian flowers. The bed, which was hung
with green curtains, occupied an undue space; and Mabin felt that, in
the weird circumstances of her tenancy of the room, she would have
died rather than sleep in that funereal erection.
When Mrs. Dale had kissed her and bade her good-night, after
receiving Mabin’s assurance that she did not feel in the least
nervous, the young girl felt a strong inclination to follow her friend out
of the room, and to implore her to find her some other sleeping-
place.
By a valiant effort, however, she conquered this weakness, and
made a careful survey of her surroundings. In the first place, the
windows and their fastenings had to be examined. They were
carefully secured, and were both so high above the ground that it
would have been impossible for an intruder to reach them without a
ladder.
There were three doors; and at first Mabin was inclined to regard
this as a disquieting circumstance. But on finding that two of them
were unused, locked, and without a key, and that there was a bolt on
the door by which she had entered, she began to feel more at ease.
Exchanging her frock for a dressing-gown, and providing herself
with a book, she placed herself in an arm-chair which stood near the
fireplace, which, although shabby, was sufficiently comfortable, and,
putting her candles on a small table beside her, settled herself to
read. Her book was a novel of an excellent type, not too clever to be
charming, not so commonplace as to be dull. Much to her own
surprise, she got interested, and forgot, or almost forgot, the vague
fears which kept her in the arm-chair instead of in bed.
She was in the very heart of the book, and her candles had burnt
low in their sockets, when a sound, a very slight sound, behind her
back, caused the blood almost to freeze in her veins.
It was a soft, stealthy tread.
Looking round, half paralyzed with terror, she saw that the door
was ajar, and that creeping softly round toward the inside handle
was the long, thin hand of a man.
CHAPTER IX.
A PICTURE.

In the ordinary course of things, it would have been natural for


Mabin to conclude, on seeing a man’s hand inside her door in the
middle of the night, that the intruder was a burglar. But her mind had
been rendered more clear, her perceptions more acute, by the
stimulating mystery which she had been for the past two days trying
to solve.
Instead, therefore, of screaming, or stretching out her hand to the
old-fashioned bell-rope which hung by the fireside at a little distance
from her right hand, she waited, watched, and listened. Apparently
she had unconsciously made some slight noise as she turned in her
chair to look behind her, for the intruder, whoever he was, instead of
entering, waited and listened also.
There was a pause; and then the hand which had crept so
stealthily round the door was slowly and quietly withdrawn. Mabin,
fascinated, watched the long, bloodless fingers as they gradually
disappeared from her sight; and was sufficiently self-possessed to
observe that the hand was that of a gentleman. And upon this
discovery there sprang up in her mind a strong curiosity to see the
face of the intruder.
Even while she felt the last remains of fear give place to courage
and vivid interest, Mabin, with her wits all sharpened with
excitement, wondered at the change in herself. She sprang lightly to
her feet, and with the intention of taking him by surprise, ran lightly
round on the tips of her toes toward the door. But the candles,
flickering in the draught caused by her light hanging sleeves, caused
the shadows on the dingy rose-covered wall to dance and quiver.
The mysterious visitor, as much on the alert as the girl was, closed
the door softly between her and himself.
Mabin, however, sprang forward and seized the door-handle. She
heard the sound of rapid footsteps on the other side, and for one
moment she hesitated to go in pursuit. With the clearness of intellect
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

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.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookfinal.com

You might also like