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

Software Architecture Design Patterns in Java 1st Edition Partha Kuchana download

The document is a comprehensive guide on software architecture design patterns in Java, authored by Partha Kuchana. It covers various design patterns, including creational, structural, and behavioral patterns, along with UML references and practical examples. The book aims to provide reusable design solutions for software development, making it a valuable resource for software engineers and developers.

Uploaded by

oehmesturrh5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
18 views

Software Architecture Design Patterns in Java 1st Edition Partha Kuchana download

The document is a comprehensive guide on software architecture design patterns in Java, authored by Partha Kuchana. It covers various design patterns, including creational, structural, and behavioral patterns, along with UML references and practical examples. The book aims to provide reusable design solutions for software development, making it a valuable resource for software engineers and developers.

Uploaded by

oehmesturrh5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 56

Software Architecture Design Patterns in Java

1st Edition Partha Kuchana download

https://ebookname.com/product/software-architecture-design-
patterns-in-java-1st-edition-partha-kuchana/

Get Instant Ebook Downloads – Browse at https://ebookname.com


Instant digital products (PDF, ePub, MOBI) available
Download now and explore formats that suit you...

Software Architecture Design Patterns in Java 1st


Edition Partha Kuchana

https://ebookname.com/product/software-architecture-design-
patterns-in-java-1st-edition-partha-kuchana/

Patterns in Java A Catalog of Reusable Design Patterns


Illustrated with UML 2nd Edition Volume 1 Grand

https://ebookname.com/product/patterns-in-java-a-catalog-of-
reusable-design-patterns-illustrated-with-uml-2nd-edition-
volume-1-grand/

Integration Ready Architecture and Design Software


Engineering with XML Java NET Wireless Speech and
Knowledge Technologies 1st Edition Jeff Zhuk

https://ebookname.com/product/integration-ready-architecture-and-
design-software-engineering-with-xml-java-net-wireless-speech-
and-knowledge-technologies-1st-edition-jeff-zhuk/

Music and Sound in Documentary Film 1st Edition Holly


Rogers

https://ebookname.com/product/music-and-sound-in-documentary-
film-1st-edition-holly-rogers/
Principle Advancements in Database Management
Technologies New Applications and Frameworks 1st
Edition Keng Siau

https://ebookname.com/product/principle-advancements-in-database-
management-technologies-new-applications-and-frameworks-1st-
edition-keng-siau/

Panama Patricia Katzman

https://ebookname.com/product/panama-patricia-katzman/

Nanoparticle Drug Delivery Systems for Cancer Treatment


1st Edition Hala Gali-Muhtasib

https://ebookname.com/product/nanoparticle-drug-delivery-systems-
for-cancer-treatment-1st-edition-hala-gali-muhtasib/

Spiritual Assessment in Social Work and Mental Health


Practice David Hodge

https://ebookname.com/product/spiritual-assessment-in-social-
work-and-mental-health-practice-david-hodge/

User Acceptance Testing A step by step guide 1st


Edition Brian Hambling

https://ebookname.com/product/user-acceptance-testing-a-step-by-
step-guide-1st-edition-brian-hambling/
The Handbook of Optical Communication Networks 1st
Edition Mark B. Desman

https://ebookname.com/product/the-handbook-of-optical-
communication-networks-1st-edition-mark-b-desman/
Software
Architecture
Design Patterns
in Java

© 2004 by CRC Press LLC


Other CRC/Auerbach Publications in Software Development,
Software Engineering, and Project Management
The Complete Project Management Six Sigma Software Development
Office Handbook Christine Tanytor
Gerard M. Hill 0-8493-1193-4
0-8493-2173-5
Software Architecture Design Patterns
Complex IT Project Management: 16 Steps in Java
to Success Partha Kuchana
Peter Schulte 0-8493-2142-5
0-8493-1932-3 Software Configuration Management
Creating Components: Object Oriented, Jessica Keyes
Concurrent, and Distributed Computing 0-8493-1976-5
in Java
Software Engineering for Image Processing
Charles W. Kann Phillip A. Laplante
0-8493-1499-2 0-8493-1376-7
Dynamic Software Development: Software Engineering Handbook
Manging Projects in Flux Jessica Keyes
Timothy Wells 0-8493-1479-8
0-8493-129-2
Software Engineering Measurement
The Hands-On Project Office: Guaranteeing John C. Munson
ROI and On-Time Delivery 0-8493-1503-4
Richard M. Kesner
0-8493-1991-9 Software Engineering Processes: Principles
and Applications
Interpreting the CMMI®: A Process Yinxu Wang, Graham King, and Saba Zamir
Improvement Approach 0-8493-2366-5
Margaret Kulpa and Kent Johnson
Software Metrics: A Guide to Planning,
0-8493-1654-5
Analysis, and Application
Introduction to Software Engineering C.R. Pandian
Ronald Leach 0-8493-1661-8
0-8493-1445-3 Software Testing: A Craftsman’s Approach,
ISO 9001:2000 for Software and Systems 2e
Providers: An Engineering Approach Paul C. Jorgensen
Robert Bamford and William John Deibler II 0-8493-0809-7
0-8493-2063-1 Software Testing and Continuous Quality
Improvement, Second Edition
The Laws of Software Process:
William E. Lewis
A New Model for the Production
and Management of Software 0-8493-2524-2
Phillip G. Armour IS Management Handbook, 8th Edition
0-8493-1489-5 Carol V. Brown and Heikki Topi, Editors
0-8493-1595-9
Real Process Improvement Using
the CMMI® Lightweight Enterprise Architectures
Michael West Fenix Theuerkorn
0-8493-2109-3 0-9493-2114-X

AUERBACH PUBLICATIONS
www.auerbach-publications.com
To Order Call: 1-800-272-7737 • Fax: 1-800-374-3401
E-mail: orders@crcpress.com
© 2004 by CRC Press LLC
Software
Architecture
Design Patterns
in Java
Partha Kuchana

AUERBACH PUBLICATIONS
A CRC Press Company
Boca Raton London New York Washington, D.C.

© 2004 by CRC Press LLC


Library of Congress Cataloging-in-Publication Data

Kuchana, Partha.
Software architecture design patterns in Java / Partha Kuchana.
p. cm.
Includes bibliographical references and index.
ISBN 0-8493-2142-5 (alk. paper)
1. Java (Computer program language) 2. Computer Software. 3. Computer architecture.
4. Software patterns. I. Title.

QA76.73.J38K83 2004
005.13′3—dc22 2003070897

This book contains information obtained from authentic and highly regarded sources. Reprinted material is quoted
with permission, and sources are indicated. A wide variety of references are listed. Reasonable efforts have been
made to publish reliable data and information, but the author and the publisher cannot assume responsibility for the
validity of all materials or for the consequences of their use.

Neither this book nor any part may be reproduced or transmitted in any form or by any means, electronic or
mechanical, including photocopying, microfilming, and recording, or by any information storage or retrieval system,
without prior permission in writing from the publisher.

The consent of CRC Press LLC does not extend to copying for general distribution, for promotion, for creating new
works, or for resale. Specific permission must be obtained in writing from CRC Press LLC for such copying.

Direct all inquiries to CRC Press LLC, 2000 N.W. Corporate Blvd., Boca Raton, Florida 33431.

Trademark Notice: Product or corporate names may be trademarks or registered trademarks, and are used only for
identification and explanation, without intent to infringe.

Visit the Auerbach Publications Web site at www.auerbach-publications.com

© 2004 by CRC Press LLC


Auerbach is an imprint of CRC Press LLC

No claim to original U.S. Government works


International Standard Book Number 0-8493-2142-5
Library of Congress Card Number 2003070897
Printed in the United States of America 1 2 3 4 5 6 7 8 9 0
Printed on acid-free paper

© 2004 by CRC Press LLC


DEDICATION

To my family

© 2004 by CRC Press LLC


CONTENTS

SECTION I: AN INTRODUCTION TO DESIGN PATTERNS


1 Design Patterns: Origin and History
Architectural to Software Design Patterns
What Is a Design Pattern?
More about Design Patterns
About This Book
Source Code
Source Code Disclaimer

SECTION II: UNIFIED MODELING LANGUAGE (UML)


2 UML: A Quick Reference
Structure Diagrams
Behavior Diagrams
Model Management Diagrams
Class Diagrams
Class
Inner Class
Access Specifiers
Static
Abstract Class/Method
Exception
Note
Generalization
Interface
Realization
Dependency
Class Association
Multiplicity
Navigability
Composition
Aggregation
Sequence Diagrams
Object
Message
Self Call

© 2004 by CRC Press LLC


SECTION III: BASIC PATTERNS
3 Interface
Description
Example
Practice Questions

4 Abstract Parent Class


Description
Example
Abstract Parent Class versus Interface
Practice Questions

5 Private Methods
Description
Example
Practice Questions

6 Accessor Methods
Description
Accessor Method Nomenclature
Example
Direct Reference versus Accessor Methods
Practice Questions

7 Constant Data Manager


Description
Example
Practice Questions

8 Immutable Object
Description
Example
Practice Questions

9 Monitor
Description
Example
Practice Questions

SECTION IV: CREATIONAL PATTERNS


10 Factory Method
Description
Example
Practice Questions

11 Singleton
Description
Who Should Be Responsible?
Example
Make the Constructor Private
Static Public Interface to Access an Instance
Practice Questions

© 2004 by CRC Press LLC


12 Abstract Factory
Description
Abstract Factory versus Factory Method
Example I
Example II
Logical Flow When the Application Is Run
Practice Questions

13 Prototype
Description
Shallow Copy versus Deep Copy
Shallow Copy Example
Deep Copy Example
Example I
Design Highlights of the HostingPlanKit Class
Example II
Redesign the UserAccount Class
Create a Prototype Factory Class
Practice Questions

14 Builder
Description
Example I
A Side Note
Back to the Example Application
Example II
Example III
Practice Questions

SECTION V: COLLECTIONAL PATTERNS


15 Composite
Description
Example
Design Approach I
FileComponent
getComponentSize()
DirComponent
addComponent(FileSystemComponent)
getComponent(int)
getComponentSize()
Design Approach II
Practice Questions

16 Iterator
Description
Iterators in Java
Filtered Iterators
Internal versus External Iterators
Example: Internal Iterator
Client/Container Interaction
Example: External Filtered Iterator
Practice Questions

© 2004 by CRC Press LLC


17 Flyweight
Description
How to Design a Flyweight in Java
Design Highlights
Example
Design Approach I
Design Approach II
Practice Questions

18 Visitor
Description
Design Idea 1
Design Idea 2
Defining New Operations on the Object Collection
Adding Objects of a New Type to the Collection
Example
Design Approach I
Design Approach II
Design Approach III (Composite Pattern)
Design Approach IV (The Visitor Pattern)
Application Flow
Defining a New Operation on the Order Object Collection
Adding a New Order Type to the Collection
Practice Questions

SECTION VI: STRUCTURAL PATTERNS


19 Decorator
Description
Characteristics of a Decorator
Example
Concrete Logger Decorators
HTMLLogger
EncryptLogger
Adding a New Message Logger
Adding a New Decorator
Practice Questions

20 Adapter
Description
Class Adapters versus Object Adapters
Class Adapter
Object Adapter
Example
Address Adapter as an Object Adapter
Practice Questions

21 Chain of Responsibility
Description
Example
Practice Questions

© 2004 by CRC Press LLC


22 Façade
Description
Example
Important Notes
Practice Questions

23 Proxy
Description
Proxy versus Other Patterns.
Proxy versus Decorator
Proxy versus Façade
Proxy versus Chain of Responsibility
RMI: A Quick Overview
RMI Components
RMI Communication Mechanism
RMI and Proxy Pattern
Example
Additional Notes
Compilation and Deployment Notes
Practice Questions

24 Bridge
Description
Example
Abstraction Implementation Design
Abstraction Interface Design
Design Highlights of the Abstraction Interface Classes
Bridge Pattern versus Adapter Pattern
Practice Questions

25 Virtual Proxy
Description
Advantage
Disadvantage
Example
Practice Questions

26 Counting Proxy
Description
Example
Practice Questions

27 Aggregate Enforcer
Description
Example
Design Approach I (On-Demand Initialization)
Design Approach II (Early Initialization)
Design Approach III (Final Variables)
Practice Questions

28 Explicit Object Release


Description
The finalize Method

© 2004 by CRC Press LLC


When an Object Goes Out of Scope, It Is Believed to
Be Garbage Collected Immediately
The Garbage Collection Process Runs as a Low-Level
Background Daemon Thread
The finally Statement
Example
Best Case Scenario
Exception Scenario 1
Exception Scenario 2
Practice Questions

29 Object Cache
Description
Example
Practice Questions

SECTION VII: BEHAVIORAL PATTERNS


30 Command
Description
Example I
Example II
Application Flow
Practice Questions

31 Mediator
Description
Mediator versus Façade
Example I
Client Usage of the Mediator
User Interface Objects: Mediator Interaction
Example II
Practice Questions

32 Memento
Description
Example
DataConverter (Originator)
ID
Memento
process
createMemento
setMemento
DCClient (Client)
MementoHandler
Practice Questions

33 Observer
Description
Adding New Observers
Example
Subject–Observer Association
Logical Flow

© 2004 by CRC Press LLC


Practice Questions

34 Interpreter
Description
Example
Infix-to-Postfix Conversion (Listing 34.8)
Construction of the Tree Structure (Listing 34.9)
Postorder Traversal of the Tree
Additional Notes
Infix-to-Postfix Conversion
Infix Expression
Postfix Expression
Conversion Algorithm
Example
Binary Tree Traversal Techniques
Preorder (Node-Left-Right)
In-Order (Left-Node-Right)
Postorder (Left-Right-Node)
Level-Order
Practice Questions

35 State
Description
Stateful Object: An Example
Example
Practice Questions

36 Strategy
Description
Strategies versus Other Alternatives
Strategy versus State
Example
SimpleEncryption
CaesarCypher
SubstitutionCypher
CodeBookCypher
Practice Questions

37 Null Object
Description
Example
Practice Questions

38 Template Method
Description
Abstract Class
Concrete Class
Example
Additional Notes
Mod 10 Check Digit Algorithm
Practice Questions

39 Object Authenticator
Description

© 2004 by CRC Press LLC


Example
Practice Questions

40 Common Attribute Registry


Description
Example
Practice Questions

SECTION VIII: CONCURRENCY PATTERNS


41 Critical Section
Description
Example
Approach I (Critical Section)
Approach II (Static Early Initialization)
Practice Questions

42 Consistent Lock Order


Description
Example
Practice Questions

43 Guarded Suspension
Description
Example
Use of wait() and notify() in the ParkingLot Class Design
Practice Questions

44 Read-Write Lock
Description
Design Highlights of the ReadWriteLock Class
Lock Statistics
Lock Methods
Lock Release
Example
Practice Questions

SECTION IX: CASE STUDY


45 Case Study: A Web Hosting Company
Objective
KPS Hosting Solutions: A Brief Overview
Requirements
Functional
Technical
Business Objects and Their Association
Framework for Application Processing
Enterprise Service Level
Generic Interface Contract
Sample Interface Contract
Task Level
Generic Task-Handler Mapping
Sample Task-Handler Mapping

© 2004 by CRC Press LLC


Error Processing
Enterprise Services Design
Address Validation
Credit Card Service
Validation
Search Management
Customer Management
Conclusion

SECTION X: APPENDICES
Appendix A: List of Design Patterns
Appendix B: References

© 2004 by CRC Press LLC


FOREWORD

Partha Kuchana is an experienced enterprise systems architect. He understands


that patterns are not about things that are just good ideas, but that patterns are
about capturing knowledge bred from experience. This hard-won knowledge is
what Partha is sharing with readers of his book. Here are some of the things I
really like about what he has to say.
The book presents 42 design patterns, which include the 23 GoF patterns.
These patterns are categorized as follows:

䡲 7 Basic patterns
䡲 5 Creational patterns
䡲 4 Collectional patterns
䡲 11 Structural patterns
䡲 11 Behavioral patterns
䡲 4 Concurrency patterns

The discussion of each pattern includes an example implemented in Java.


Further, the source code for all examples is found on the following Web site for
this book: http://www.crcpress.com/e_products/downloads/download.asp. The
source code and the easily understood examples make this format work well.
Partha takes complex material and clearly explains the ideas so they are easy-
to-understand, an important consideration for both the novice encountering the
material for the first time and the experienced developer who quickly wants to
extract the important bits for immediate use. Each pattern discussion also includes
Practice Questions for exactly that — your own use to improve your skills or, if
this book were to be chosen as a text, to help the time-pressured instructor.
Partha takes the time to compare and contrast the patterns. For example, in the
discussion on the Mediator pattern, a table shows similarities and differences
between Mediator and Façade. The reader will find that this analysis leads to a
clearer understanding than simply trying to focus on each pattern in isolation. The
text also includes consideration of relationships between patterns. For example, in
the discussion on the Mediator pattern there is a reference to a previous design
example for the Command pattern.

© 2004 by CRC Press LLC


Finally, at the end of the book, the reader will be happy to find a case study
that pulls some of the patterns together to illustrate how a more complicated
problem would be tackled and how the patterns work together. As those who
have studied the work of Christopher Alexander realize—patterns are not applied
in isolation but collaborate within a specific domain to address large and small
problems.
It has been ten years since the GoF book was published. A lot of patterns
have been identified and captured in that time. A lot of patterns books have been
written. This book is like the GoF book, a catalog; probably not one you will
read cover-to-cover in a single setting, but which will find a place on your
bookshelf. Keep it handy for all those “How do I do this in Java?” questions
where you wish you had an expert in the office next door to provide answers.
This book is the next best thing.
Linda Rising
Phoenix, AZ

© 2004 by CRC Press LLC


ABOUT THE AUTHOR

Partha Kuchana is an experienced enterprise systems architect. He has eleven


years of experience in all aspects of project delivery management (onsite/offshore
models), enterprise architecture, design, development, mentoring and training. He
is a Sun certified enterprise architect.
During the last several years, he has worked on numerous client–server, E-
business, Web portal and enterprise application integration (EAI) projects at various
client sites in the United Kingdom and the United States, involving iterative design
methodologies such as Rational Unified Process (RUP) and extreme programming.
He has extensive experience applying design patterns in application architec-
ture and design. He has successfully architected and designed business-to-business
systems and complex heterogeneous systems integration using Web services,
middleware and messaging products from various vendors. He has several pub-
lished software-related publications.

Home page: http://members.ITJobsList.com/partha


E-mail: ParthaKuchana@ITJobsList.com

© 2004 by CRC Press LLC


ACKNOWLEDGMENTS

First and foremost, I would like to thank my wife for her patience and support,
for taking some of my workload especially in the ar eas of UML and Java
programming and for her inspirational contributions at the time of frustrating
moments. I would like to thank my parents, my sister, my brother and my dear
friends whose support and encouragement throughout my life have made it
possible for me to build the skill set necessary to succeed.
I would like to thank Venu Kuchana and D.R. Sudhakar for their contributions
in terms of writing different Java programs. I would like to thank BalaLingam
Kuchana for his contributions in the area of UML and for being in charge of
creating the formatted version of my draft.
I would like to thank the entire team at Auerbach publications for their
contributions in this project and for making this a remarkable experience. In
particular, I have a deep sense of gratitude towards my acquisitions editor, John
Wyzalek, for sharing my enthusiasm and providing me with great advice and
help. I also would like to thank the managing editor, Claire Miller, for her
invaluable advice and contribution in arranging the book in a presentable form.
My sincere thanks to Linda Rising for writing the Foreword.
I am truly appreciative and thankful to the following reviewers who have
taken the time to read the draft and provide me with feedback.

䡲 Pradyumn Sharma, CEO, Pragati Software Pvt. Ltd.


䡲 Carsten Kuckuk, project lead, Design Patterns Study Group Stuttgart, RIB
Software AG
䡲 Tim Kemper, Boulder Design Patterns Group
䡲 Geoffrey Sparks, CEO, Sparx Systems P/L
䡲 Edward L. Howe, software architect, Employease, Inc.
䡲 Christopher R. Gardner, software developer, McKesson Information Solutions
䡲 David Deriso, senior software engineer, Employease, Inc.
䡲 Mike Heinrich, software engineer, Canada
䡲 Rodney Waldoff, director of systems architecture, Encyclopedia Brittanica
Inc.
䡲 Thomas SMETS, software engineer, Belgium
䡲 Linda Rising, Ph.D., independent software consultant, Arizona State University
䡲 Ray Tayek, coordinator LAJUG/OCJUG

© 2004 by CRC Press LLC


In particular, thanks to Pradyumn Sharma, Carsten Kuckuk, and Tim Kemper
for their insightful recommendations, their thoroughness, and their invaluable
suggestions, including questions that an inquisitive reader might have about design
patterns.
I would like to thank Mark Grand for his encouragement and advice on various
aspects of writing a patterns book. I am sure I have forgotten someone important;
please accept my sincere apologies.

© 2004 by CRC Press LLC


I
AN INTRODUCTION TO
DESIGN PATTERNS

© 2004 by CRC Press LLC


1
DESIGN PATTERNS:
ORIGIN AND HISTORY

During the late 1970s, an architect named Christopher Alexander carried out the
first known work in the area of patterns. In an attempt to identify and describe
the wholeness or aliveness of quality designs, Alexander and his colleagues studied
different structures that were designed to solve the same problem. He identified
similarities among designs that were of high quality. He used the term pattern in
the following books to refer to these similarities.

䡲 A Pattern Language: Towns, Buildings, Construction (Oxford University


Press, 1977)
䡲 The Timeless Way of Building (Oxford University Press, 1979)

The patterns identified and documented by Alexander are purely architectural


and deal with structures like buildings, gardens and roadways.

ARCHITECTURAL TO SOFTWARE DESIGN PATTERNS


In 1987, influenced by the writings of Alexander, Kent Beck and Ward Cunningham
applied the architectural pattern ideas for the software design and development.
They used some of Alexander’s ideas to develop a set of patterns for developing
elegant user interfaces in Smalltalk. With the results of their work, they gave a
presentation entitled Using Pattern Languages for Object-Oriented Programming
at the Object-Oriented Programming Systems, Languages, and Applications (OOP-
SLA) ’87 conference. Since then, many papers and presentations relating to patterns
have been published by many eminent people in the Object Oriented (OO) world.
In 1994, the publication of the book entitled Design Patterns: Elements of
Reusable Object-Oriented Software on design patterns by Erich Gamma, Richard
Helm, Ralph Johnson and John Vlissides explained the usefulness of patterns and
resulted in the widespread popularity for design patterns. These four authors
together are referred to as the Gang of Four (GoF). In this book the authors
documented the 23 patterns they found in their work of nearly four and a half
years.

© 2004 by CRC Press LLC


Since then, many other books have been published capturing design patterns
and other best practices for software engineering.

WHAT IS A DESIGN PATTERN?


A design pattern is a documented best practice or core of a solution that has
been applied successfully in multiple environments to solve a problem that recurs
in a specific set of situations.
Architect Christopher Alexander describes a pattern as “a recurring solution to
a common problem in a given context and system of forces.” In his definition,
the term context refers to the set of conditions/situations in which a given pattern
is applicable and the term system of forces refers to the set of constraints that
occur in the specific context.

MORE ABOUT DESIGN PATTERNS

䡲 A design pattern is an effective means to convey/communicate what has


been learned about high-quality designs. The result is:
– A shared language for communicating the experience gained in dealing
with these recurring problems and their solutions.
– A common vocabulary of system design elements for problem solving
discussions. A means of reusing and building upon the acquired insight
resulting in an improvement in the software quality in terms of its
maintainability and reusability.
䡲 A design pattern is not an invention. A design pattern is rather a docu-
mented expression of the best way of solving a problem that is observed
or discovered during the study or construction of numerous software
systems.
䡲 One of the common misconceptions about design patterns is that they are
applied only in an object-oriented environment. Even though design pat-
terns discussions typically refer to the object-oriented development, they
are applicable in other areas as well. With only minor changes, a design
pattern description can be adjusted to refer to software design patterns in
general. From the preceding section, Origin and History, it can be seen
that patterns have existed from the early days of architecture, long before
the object-oriented design and programming era.
䡲 Design patterns are not theoretical constructs. A design pattern can be
seen as an encapsulation of a reusable solution that has been applied
successfully to solve a common design problem.
䡲 Though design patterns refer to the best known ways of solving problems,
not all best practices in problem resolution are considered as patterns. A
best practice must satisfy the Rule of Three to be treated as a design
pattern. The Rule of Three states that a given solution must be verified to
be a recurring phenomenon, preferably in at least three existing systems.
Otherwise, the solution is not considered as a pattern. The goal is to ensure
that some community of software professionals applied the solution
described by the pattern to solve software design problems. Satisfying the

© 2004 by CRC Press LLC


Rule of Three indicates that a design pattern provides a practical solution
to deal with a real-world problem.
䡲 Design patterns do not provide solutions to every problem found in real-
world software design and development. Design patterns are about pro-
viding elegant, reusable solutions to commonly encountered software
development problems in a particular context. This means that a pattern
that is meant to provide the best solution to a problem in a particular
context may not produce an effective solution to the same problem in a
different context. Sometimes, the solution proposed by the design pattern
may not even be applicable in a different context.

Software frameworks can be confused with design patterns. They are closely
related. Table 1.1 lists the similarities and differences between the two.

Table 1.1 Design Patterns versus Frameworks


Design Patterns Frameworks

Design patterns are recurring solutions to A framework is a group of components


problems that arise during the life of a that cooperate with each other to
software application in a particular provide a reusable architecture for
context. applications with a given domain.
The primary goal is to: The primary goal is to:
• Help improve the quality of the • Help improve the quality of the
software in terms of the software software in terms of the software
being reusable, maintainable, being reusable, maintainable,
extensible, etc. extensible, etc.
• Reduce the development time • Reduce development time
Patterns are logical in nature. Frameworks are more physical in nature,
as they exist in the form of some
software.
Pattern descriptions are usually Because frameworks exist in the form of
independent of programming language some software, they are
or implementation details. implementation-specific.
Patterns are more generic in nature and can Frameworks provide domain-specific
be used in almost any kind of functionality.
application.
A design pattern does not exist in the Frameworks are not complete
form of a software component on its applications on their own. Complete
own. It needs to be implemented applications can be built by either
explicitly each time it is used. inheriting the components const
directly.
Patterns provide a way to do “good” Design patterns may be used in the
design and are used to help design design and implementation of a
frameworks. framework. In other words,
frameworks typically embody several
design patterns.

© 2004 by CRC Press LLC


ABOUT THIS BOOK
The objective of this book is to discuss design patterns in an easy to understand
manner with simple examples. This book discusses 42 design patterns including
the 23 patterns by GoF. These patterns are arranged in six categories:

䡲 7 Basic Patterns — Section III (Chapter 3 through Chapter 9)


䡲 5 Creational Patterns — Section IV (Chapter 10 through Chapter 14)
䡲 4 Collectional Patterns — Section V (Chapter 15 through Chapter 18)
䡲 11 Structural Patterns — Section VI (Chapter 19 through Chapter 29)
䡲 11 Behavioral Patterns — Section VII (Chapter 30 through Chapter 40)
䡲 4 Concurrency Patterns — Section VIII (Chapter 41 through Chapter 44)

Each pattern discussion starts with an explanation of the pattern followed by


an example implemented in Java™ programming language. How a given pattern
is applied in the example is discussed in detail along with code segments and
UML diagrams (class, sequence). At the end of each pattern discussion, a few
practice questions are provided for you to work on to improve your understanding
of the pattern. Wherever applicable, patterns are compared with other similar
looking patterns.
The examples in this book are kept simple for easy understanding. The
objective is to enhance the explanation of each pattern with examples for a better
understanding.
The UML section provides an overview of the Unified Modeling Language
(UML) and discusses various elements of class and sequence diagrams.
The case study at the end of the book demonstrates the collective usage of
different design patterns in a real-world application design scenario. This section
discusses how various patterns can be used in designing a reusable application
framework for a fictitious Web hosting company.

Source Code
The source code for all example applications is available on the following Web
site for this book: http://www.crcpress.com/e_products/download.asp.

Source Code Disclaimer


Both the author and the publisher make no representations or warranties about
the suitability of the software, either expressed or implied, including but not
limited to the implied warranties of merchantability, fitness for a particular purpose
or noninfringement. Both the author and the publisher shall not be liable for any
damages suffered as a result of using, modifying or distributing the software or
its derivatives.
Java is a trademark of Sun Microsystems, Inc. Windows is a registered trademark
of Microsoft Corporation.

© 2004 by CRC Press LLC


Exploring the Variety of Random
Documents with Different Content
This was rather vague, though it sounded so precise. And I
whispered to the Captain, "You are as good as John Bright." But he
shoved me with his elbow, while his eloquence went down. Then the
young man with the tar-pot came up mildly, in the presence of a
larger spirit, and said, "Captain, you must be the celebrated
traveller;" and Strogue looked at him augustly, and said, "Young
man, you are right."
After this it is impossible for me to tell the glorious night they made
of it. They had spent all the time, when they could not work, in
making themselves more comfortable; and all the starvation they
had been through was avenged upon itself by its own power. I have
seen a good deal of eating; and Strogue had both seen and done a
great deal more; and the voice of travellers is unanimous that the
Caucasian native acknowledges no superior in that line. It is not for
me to contradict them, but the impression I formed that night, and
with my own mouth confirmed it, was that the British settler can in
that, as in less important matters, adapt himself to his environment.
The sheep of the mountain are but small, and we furthered nature's
ordinances by making six, or perhaps I should say seven of them,
smaller still. For the valleys were spread with the verdure of spring,
and it covered their saddles with sweet white fat.
"One little slice more," Jack Nickols said; "this is the best of the
batch, I know. What would we have given for a cut out of him last
winter! But we were obliged to leave this place altogether. Forty feet
deep the snow was here, and not a bit of firing to be got for love or
money. You heard that two of us were frozen to death; but we never
lost a man. We set that story going, and it did us a lot of good, and
choked off another lot who wanted to come here. We have got it all
to ourselves at present, and mean to keep it. You saw my tar-pot.
Capital plan. An invention of my own. We have scarcely gone
underground at all as yet. We scratch the crannies, and the dribble-
places, and I stand by and watch every fellow. Wonderfully honest,
and all that, no doubt; but just as well to look after them. Every bit
of green they find, I drop it in the tar. They can't get it out again,
even if they could find it, without telling tales on their fingers. Nine
out of ten are not worth keeping; but we have got a few real
beauties. There is one stone I wouldn't take a hundred pounds for,
and a lot worth more than fifty. I'll show you some of them by
daylight. It's the flaws, the flaws that murder them."
"We don't know anything about stones," replied Strogue, "and I
would rather look through a good green bottle than all the emeralds
that ever came from Peru, or wherever they get them. What we
want to talk about is quite another pair of shoes, and I know you will
help us if you can. We gave you that letter from your uncle. He will
be out here this summer if he can. But we cannot wait for that. We
must set to work at once. When the rest are gone, I will tell you all
about it."
"We will go outside, if you don't mind. I can show you a very cosy
place where we do our cooking, and the ashes warm the rock all
night. Let us have our pipes there, and leave the tag-rag here."
We followed him gladly to the open air, and sat upon some bear-
skins in a snug alcove of rock, with the stars shining on us, and the
embers of the fire doing better service still. And here we told young
Jack Nickols all our story, a great part of which he must have known
already.
"You will never go home alive," he said, "if you are going to meddle
with that woman. Let her have her own way. She always does. What
right have you to conclude that she wants to murder her own twin-
brother? It is likely enough, mind, from what you say, and in fact I
have little doubt about it. But for all that, you don't actually know it,
and if you did you are not the Russian Government. Let her alone,
for God's sake."
We told him that this was the very thing we had sworn to ourselves
we would never do; and that he must stand by us, like an
Englishman, and like his uncle's nephew. "Stand a long way off more
likely," he replied, "though I don't call myself a coward, and I hate
that woman. But I will try to contrive something, and let you know
to-morrow."
CHAPTER XLVI
QUEEN MARVA

Discovering nothing of any kind, concerning Sûr Imar and his


daughter, after they had quitted Athens, we made up our minds that
the proper course was to pay a visit to the Princess Marva, and try to
get some inkling of her plans. It was not very likely that a couple of
clumsy fellows, like Strogue and my humble self, would prove a
match, or even a serious check, for a subtle and ruthless woman,
commanding a reckless tribe, and probably well informed of all the
plans of her unsuspicious victims. So that if we appeared in our own
characters, or even let her know that we were here, our days in this
land, or indeed in any other visible except to the eyes of faith, were
likely to be brief indeed.
But for the sake of those who mean well, and desire fair play on the
whole, whenever it leaves a chance for them, Providence has been
gracious enough to lay down one universal rule—that every wicked
person has some special weakness, some nick in his black shell for
the oyster-knife of justice; so that a simple and straight mind, like
Strogue's and mine, may find its way through, and turn the whole to
righteous uses.
"I have hit the mark," Jack Nickols said, when he came home to
breakfast with his tar-pot; "when the sun comes up these rattling
peaks, instead of down over them, is the time to think. I could not
see things clear last night, though you know how little I take,
Captain, compared with anybody else about. But when the sun came
up from under to me, my brains, which are bright now and then,
began to work. I thought of you snoozing in the ashes, and I
resolved to do my best for you."
"Go on, my son," said the Captain kindly, with the tolerance of a
gentleman who is offered lager-froth, instead of solid Bass; "there is
no doubt that you have fine ideas. A man who turns out so early
picks up something."
"Then what do you say to this?" cried Jack. "You might roll over fifty
times, till nine o'clock, as old gentlemen do in England, and yet
never find it occur to you. That Clipper of the
mountains"—"Cleopatra" was the word in his mind perhaps—"is a
terrible oner for money, they say, and we have had a tip or two to
that effect. Till we paid her toll, though it is robbery downright, a
bullet used to come from some black corner, and my very best hand
had a sample through his hat. One must expect that sort of thing of
course, in an out-of-way part of the world like this; but luckily they
have never been at Wimbledon. I came very near the Queen's Prize
once; but I told you all about that, last night. These beggars won't
give me a chance. Never mind, it will come some day. But they
haven't tried to pot us, since we paid toll. Now why shouldn't you go
upon the same tack? Go to Her Majesty, as an opposition company,
and offer a premium over our heads."
"Upon my word, you are a clever fellow," said Strogue, looking at
him thoughtfully; "I fancied so when I saw the tar-pot. But, Jack, my
dear boy, is there any foundation, anything for us to go upon?"
"Yes, there is. And we can make much more of it. I can promise you
an interview with the tigress, if you will offer to put stripes of gold
on her. You know what those confounded Germans are. No sooner
do they hear of any English enterprise than they want to go one
better and collar it. They come in, and hoist us out, and get the
cream of all our sweat. There was a tremendous man of science,
Herr Baddechopps, or Baddechumps, or some such name, poking
about here with spectacles last autumn; I have got his card, and you
shall have it. We put a rope round him, and two men at either end,
and swept him down the hill faster than he came up, and we
promised him the loop round his neck if he came back; for I can't
stand their jealousy of everything we discover! You go and tell Marva
that we have got the place too cheap; that it all belongs to her, and
you will pay three times the royalty. Take a notary with you, but sign
nothing."
"George, I am up for trying it, if you are," said Strogue. "What is the
name of her place—Gomorrah? Doesn't sound very inviting, does it?
But the lady won't hurt us, if we leave our cash behind. We can get
there in three days, you said last night. Let us beard the tigress in
her den. I have never been quite in that part before. There is no
such thing as a road, of course. All the better for that sometimes."
Nickols advised us to take no horses, lest we should be murdered for
their sake; but to hire a guide, and a tent, and half-a-dozen of his
men (whom he would try to spare), as well as our own interpreter,
and a Tartar or two who were always hanging about the Russian
fort. Thus we should be ten or twelve in number, all well-armed, and
capable of giving a good account of some thirty Ossets, if they took
our expedition roughly; for they are not good shots, and their guns
are very poor.
We spent that evening in consultation, receiving many hints from our
young friend, who would have been glad to join us, if the state of his
work had allowed it. But his mate, as he called him, was away, and
so he could not well leave the diggings; moreover, there would have
been some danger that he might be recognised, which would prove
fatal to our case at once. Yet he promised to help us with all his
force, in any great emergency, if we could only give him notice in
good time, and this was of no less value to us than a troop of
Cossacks. Meanwhile he would send to make inquiry at Vladikaukaz,
the chief town on the north, which travellers from Russia would be
almost sure to pass, whether our friends had been heard of there.
And so, with many thanks, we left him for the present, and spent a
day at Kazbek village, preparing for our visit to the Princess Marva.
Against so fierce an enemy, and with so good an object, our
stratagem for obtaining an audience was fair enough; but to use the
German professor's card seemed to me far beyond the most elastic
stretch of honesty; so I threw it into the fire, to save argument, for
Strogue took a different view of the case. "You may take the lead,
and you may call yourself a German," I told him resolutely; "I am a
silent partner, and it does not matter who I am. The lady speaks
better French perhaps than you do, and certainly much better than I
do. You do all the talking, and I nod my head. Cator is drawing up
the rough agreement, which we submit for her consideration. The
beauty of it is, that if in her greed she even gives a nibble at the
bait, we can dangle it ever so long before her, and are sure to find
out something of what we want to know. Cator must put it as
vaguely as he can, and leave the royalty blank for us to fight about."
Cator was one of Jack Nickols' men, a sharp and well-educated
youth, who had been in a lawyer's office, but found a lack of bracing
qualities in the air, and left his stool in search of them. And now we
gave him a double fee to prepare a document and enact the lawyer's
clerk at our interview, for men of law were almost as rare as men of
medicine in these parts. A formidable deed it was, with half-a-dozen
seals to it, and we wrapped it round a straight black horn from some
sheep or goat of the mountains.
The roads were bad, being over-metalled by the melting of the
snow. For the roads are the river-courses, and when nature lays too
much water on, it is not easy to get along them, even the right way
of the grain. And our course now was against the grain, towards the
head springs, or mother glaciers of the river Terek; which would
have conducted us, when in a proper mood, but now knocked us
back again, with a gruff and grey adversity. Neither was there
anything for the eyes to spread their rims at, and make light of all
the discontent of legs and back. All was dry rock, except where it
was wet with dribble, or dirty with reek of thaw; and there was
scarcely a tree to wipe the air, or show what way the wind came.
Nevertheless we strove along, following our guide, who cared much
more about putting his own feet right than ours. For these men are
not like the Alpine guides, whose loyalty is more to them than
money. At length, on the third afternoon, we stood before a strange
place, which I cannot describe, nor even give a rough idea of it,
unless I may compare it with a great pile of big dominoes, set at any
angle, some on end, and some on edge, on the top of a black pillow
bolt-upright. And this was the fortress of the Osset Queen.
We sounded a trumpet, but received no answer. And then we made
a rub-a-dub on a goat-skin drum, which was hanging on a stump for
visitors. And when we left off, we heard a screech of metal going
rustily and heavily upon its hinges. Then a muzzle, as big as a small
church bell, came out, and we thought it was all up with us.
But Strogue, like a brave man, waved a white handkerchief on the
screw of his ramrod, and we pushed the interpreter foremost,
though it required three men to do it. What he said was beyond me
altogether, though crowded with illustrious but anxious words. And if
words were ever known to afford relief, it is fair to acknowledge that
they did so then. The great muzzle which commanded all our bodies,
so that to fly was hopeless, sank upon its pivot—or whatever it
might be—and a ladder, which had been out of sight behind a
buttress, came sliding down the base to meet us. "One man first"
was the order from the loop-hole; and every one of us quite
admitted his friend's claim to precedence. "Can die but once," cried
Strogue; "here goes." Upon which I felt my cheeks burn, and said,
"Let me." But he answered, "No, you shall come next, my son."
The Captain went up heavily, with the scroll upon his back, and the
four-chambered "bull-dog" in his left breast-pocket; and we saw two
men receive him on a narrow parapet, and he waved his hand to us
to indicate all right. Then he vanished round a corner, and we waited
for some minutes, having found a little shelter where it would take
some time to shoot us. We assured one another very strongly that if
anything happened to Captain Strogue, we would not be satisfied
with avenging him, but would have the whole place down, and a
British fleet in a position to rake all the Caucasus, when to our great
relief he appeared again at the head of the ladder and shouted,
"Three more fellows may come up now." This time, I was the
foremost to run up. Not that I was really afraid before; only that I
waited to know what the others thought, as a man of modesty and
deliberation does, when the circumstances are unusual. Cator
followed readily, and so did another of Jack Nickols' men; but the
interpreter said that we should find him more useful at the bottom of
the ladder. "She is a stunner, and she has got a stunning place,"
Strogue whispered to me, as he led us through a dark passage into
a long low room; "she beats the Begum all to fits."
What Begum he meant I could not tell, having heard him speak of
several whose hearts he had broken in his early days. But if he
meant some regal-looking woman, he was not beyond the mark in
his comparison. For I had never beheld one so stately and grand as
the lady who now received us with a slight inclination, reflected by
the polish of the black walnut table before her. She was sitting in a
chair of purple velvet with a leopard's skin thrown over it, and her
dress was of soft maroon brocade, with white fur trimmings at the
neck and wrist, and a gold chain flowing upon her full broad bosom.
There was not a wrinkle or a spot to mar the shapely column of her
neck, or the firm sleek comeliness of her face; and her eyes, if there
had only been some sweetness in them, would have been as lovely
as they were splendid. Her complexion was darker than Sûr Imar's,
and the lineaments more delicate, so that her face excelled his in
perfection of form, as the feminine face should do. But as to
expression, the gentler element was by no means in its duty there;
for the aspect was of one who scorns, mistrusts, and repels all
fellow-creatures, and sees the evil in them only.
"These, then, are the members of your company, Herr Steinhart,"—
she addressed herself to Strogue, after one flashing glance at each
of us, as we entered, and her French pronunciation was a little too
good for me to follow all of it, though she did not infuse much nasal
twang; "and it is your opinion that I am deluded by those who are
working my mines at present?" My mines indeed, how grand! I
thought; what would the Russians have to say to that?
"I never speak ill of the poor," replied Strogue, "and we must make
every allowance for the British audacity, your Highness. All cannot
afford to pay as we can, for the reason that they have not our
enormous capital at command. We always find it the wisest course
to treat the landowners liberally. We make no pretence to be better,
more honest or more generous, than those Englishmen. Your Serene
Highness, although so young, has had sufficient experience of the
world, to know that all men are by nature rogues."
"My faith, but it is true! How seldom, though, have the men the
good manners to acknowledge that! Rather do they not put the fault
upon the more simple and righteous sex?"
"Your Serene Highness," Strogue answered gravely, seeing that this
title was not ungrateful, "the ladies perceive at once that they are
grossly wronged; but they are too magnanimous, too regardless of
gain, to remonstrate. You, for example, how much do you care? You
have ample revenues from your sovereignty, and things that occur
on the back of a mountain are of small account to you. Nevertheless
the right is right, and it ought to be defended."
"And the right shall be defended, when it is my right," said the lady;
"I am not accustomed, as you well observed, to the smaller
business, Herr Steinhart; but those who defraud me suffer for it.
Make your offer, if you please, more intelligible."
This was the very thing we did not want to do, having no offer of
any kind to make. But Strogue had gone far enough, and wide
enough, to know that a question is answered best by another
question.
"Is it possible that your Serene Highness will oblige us with the
amount which those arrogant Englishmen have been in the habit of
contributing to your lofty revenues? We are a wealthy company, but
we cast away no money."
"It is just," she replied, "and my desire is for justice. This is what
they pay me now. But they would have to double it for the coming
year. The trumpery sum of two hundred roubles. With you I will not
treat for less than a thousand, and for one year only at that price."
"Your Highness is very just and moderate," said Strogue, while I
turned away to hide my indignation, and sadness, that a woman so
magnificent should stoop to such a lie; for I knew that Jack Nickols
had paid her only twenty roubles, to last for two years, as she had
no title there whatever. "But your Highness will pardon me for
mentioning that we have heard a rumour, perhaps an absurd one,
that a brother of yours, a great Lesghian chief, who was banished by
the Russians, is now returning to his country, and may claim his
rights over that desolate spot, and finally establish them. In that
case our lease from your Serene Highness might not be so valuable
as we were led to hope."
A deep colour flushed, or I might say flashed, into the clear dusk of
her cheeks, and a brilliance into the darkness of her eyes. Then she
placed the long oval of her smooth plump hands (which reminded
me of Dariel's, but were half again as large) on the black walnut
wood before her, and gazed at the Captain, till he scarce knew
where he was. Then she turned her eyes on me, with contempt
subduing anger.
"Gazed at the Captain till he scarce knew where he was."
"If you think to defraud me by such pretences,"—as she spoke she
rose, and her head towered over the dumb-foundered Strogue's, and
Cator's also,—"it would have been better for you, if you had
remained at the foot of my hospitable ladder. As to the chances of
Sûr Imar's interference, you shall have the evidence of Prince Hafer.
His signature also you shall have. I will produce him to you." With
swift yet dignified steps, she left the long gloomy room, and we
stared at one another.
"Better cut and run, if they have left the ladder there," Strogue
whispered, for several men now occupied the doorway; "it is all up,
if Hafer sees us. I made sure from what they told us that he was
miles away. What's the good of four of us?"
"They can shoot us all the easier, if we run," I said; "let us have it
out here, if it must be; this thundering walnut table makes a grand
breastwork. After all, they may not want to fight us."
"We can settle at least half-a-dozen of them;" Cator's eyes shone
with legal pugnacity, "four Englishmen can lick a score of Ossets."
"Not if they are like that man," said the fourth of us, Tommy
Williams, pointing to the door, which was not a door (as the old joke
has it), neither could it be a jar, but looked more like a bed-curtain.
The lintel was appointed for men of good stature, and I had passed
beneath it without much bend; but the young man, who made his
entry now, was above any moderate stature of mankind, as he
promised in breadth to out-do them. In a flash of thought, Sûr Imar
stood before me, as I first beheld him. "Has that woman killed him,
and is this his spectre?" I asked myself, as I fell back, and stared.
Dark as the room was, another moment showed me the excited
wandering of my wits. This was not Sûr Imar's face, but one of
similar comeliness, without his resolution behind it. A gentle,
pleasant, large, and kindly countenance as his was, but with very
sad placidity, and no strong will to enforce its lines. The face of a
man who can be trusted to do you no wrong, and never to stop any
other man from doing it. Like that of the friends we value most,
when our little world goes smoothly.
He came to the table, behind which we had posted ourselves for a
desperate stand, and there he bowed very gracefully to us, and then
looked round for his admirable mother, as if he were quite at a loss
without her. Strogue, in his polite way, asked in English, "Who the
devil are you, sir?" The young giant looked at him, and shook his
head, like a stranger to our fine language. "No fear; he won't fight,"
the Captain cried to comfort us; and we all took our hands from the
triggers in our pockets.
His golden curls were waving still—for he had the finest crop that I
ever did see—and he was looking at us calmly, and as we thought
with a sweet and hospitable intent, when back came the lady almost
with a rush, and tokens of fury on her too expressive face. She had
not meant her son to come in without her; and we smiled among
ourselves, as we thought how he would "catch it," by and by at any
rate, if not in our presence. However, she controlled herself, and
introduced him grandly.
"Gentlemen, this is my son Prince Hafer, who will add his signature
to mine, to remove all your hesitation, if the terms you propose
should be suitable. Also he will confirm my declaration that my
brother Sûr Imar will raise no claim to the valuable mines you
propose to rent from me. The Prince is capable of speaking French;
though not perhaps with my facility. Your concession, which I have
perused, is in French, but the amount of your payment is not yet
stated. It will be useless to say less than one thousand roubles, five
hundred of which must be paid in advance. Herr Steinhart, I am not
a lover of money; but I must insist upon my son's rights. Do you
consent to the sum I mention?"
Strogue looked at me, and then at Cator. Intending no business, but
only a sham for the purpose of seeing the lady, and hearing
something about her brother, he was taken aback at this close issue,
especially the demand for a large payment on the nail. Moreover, his
mind was in sad confusion, and so was mine, I must confess, about
the existence of two Prince Hafers, while we durst not even hint at
any explanation. But Cator was quicker, and more ready with a
quiddity.
"Your Highness," he said, "as the legal adviser of this wealthy
company, I may say that we shall not object to the rent you reserve,
nor to the prepayment, which to us is a trifle below consideration.
Only I should take a note of guarantee from your Highness, and also
from Prince Hafer, against interference on your brother's part. That
will have to be embodied in this instrument, which moreover has not
as yet the necessary stamp. You have already given us your full
assurance. If the Prince in my presence will add his, according to
your proposition, I will put them into legal form."
"Bravo, Cator!" cried that stupid Strogue in English. "Did you speak,
sir?" asked the Princess. "Your Serene Highness, I am afflicted with a
cough," the Captain replied, with his hand before his mouth.
"My son," said the lady, looking steadily at Hafer, "oblige me by
sitting down in that chair. It is one of my afflictions, gentlemen, that
he is not always in strong health. But he is the delight of all our
tribe; so amiable, so just, so generous! Now," she continued, with
her back towards us, so that we could not see the expression of her
eyes, "assure these gentlemen, my dear son, of your certain
knowledge that Prince Imar will never set foot upon Kazbek again."
"I have no knowledge. I have never seen him. His doings are
unknown to me. I cannot affirm at all where he is." As the Prince
spoke, in French rather worse than my own, he began to tremble
violently, and his eyes turned away from his mother's face.
We saw her place one hand below her solid breast. And then she
said, coaxingly as we thought, "The poor dear, what an affliction it
is! But, my son, you can give us your firm belief that he will never
tread the mountain of Kazbek any more."
"He will never tread that mountain any more," the young man
replied in a low sad voice; and then he broke into a torrent of tears.
"Excuse me, gentlemen. It is most grievous. From a child he has
suffered from these heart-attacks. Oh, the unfortunate mother that I
am!" As she spoke, she was leading him out of the room; and we
drew aside respectfully.
Before we had time to discuss this scene, her ladyship returned with
some tears in her eyes, which made her look strangely beautiful. "I
thank you for your most kind sympathy," she said, "and will not
detain you any longer. If you will put all into proper form (for even in
trouble such things must be seen to), and return with the 500
roubles and the deed, if it may be this day-week, I will grant all your
desires. Till then, farewell."
With silent salaams we took our leave, and were shown forth, not
from the rock-front of the castle, but through a narrow passage, or
gallery, cut in the crag, and provided with iron doors. And the Ossets
who conducted us could not be tempted to open lips, or to make a
sign.
CHAPTER XLVII
WOLF'S MEAT

Thus far Cator, the attorney's clerk, had proved himself the most
sagacious and quick-witted of our party; though Captain Strogue
would have been amazed and indignant to hear me say so. And
now, when we had rejoined the rest of our little expedition, and all
were recruiting the inner man (or the middle man perhaps he is,
body being first, stomach second, and mind—when found, third
portion), that sprig of the law came up, with a bone between his
teeth, and begged the Captain and myself, who were feeding from
the outside tops of our hats, to go a little further round the elbow of
a crag. There he asked us what opinions we had formed; and when
we had taken our seats, we said: "None at all; except that we are all
bamboozled."
"No doubt about that. But how, and why?" He answered with a
mysterious look, which we were inclined to smile at, not having
known him long enough to be sure of his prophetic gifts. "A lot of
things have occurred to me, which may be very absurd of course,
and it is not likely that all are right; but I am pretty sure that some
are. Shall I tell you, and hear what you think of them?" We lit our
pipes, and nodded to him, and smiled at one another.
"To begin with, then, I suspect most strongly that her Majesty, the
Devil's wife, for so she deserves at least to be, has got her brother
under lock and key somewhere, snug enough, and at her mercy, if
she owns such a quality. Did you see what she touched, when she
went to gag, and at the same time to cram, that poor young fellow,
whose will she has crushed out of him by years and years of
bullying? Perhaps you could not see where you stood; and she did
not think that I could. But I saw the tips of her long fingers playing
with a key which was in her belt—a mere household key of course—
but enough to remind her unlucky son where his poor Uncle was,
without much chance of ever coming forth, but in his coffin. And I
caught a glance of his which proved that he understood her
meaning, and might soon have the same thing for himself. And then
you saw how he broke down; for he is a very tender-hearted youth."
"By Jove, it sounds uncommonly like it; I was so taken aback," said
Strogue, "at seeing another Prince Hafer in the field, and so different
from my Simon Pure, that I could not notice small things much; and
perhaps it was the same with Cranleigh. There is some abominable
villany at work, and we shall be too late to stop it. I would like to
insure friend Imar's life for ten thousand at five thousand premium.
Go on, my son, thou speakest well."
"Another thing, according to my lights. He is not in that queer old
place at all, Gomorrah Castle, or whatever they call it, although
there are plenty of black holes there, enough to starve a regiment
man by man. No, he is away to the North at present, perhaps on the
other side of the mountains. You saw the big window that faced the
North, more like a door than a window it was. Well, every time her
brother was in question, and especially when she was fingering that
key, she gave a quick glance through that window, very likely
without even knowing it. People who gesticulate much often follow it
up in that way. When they speak of a distant thing, they glance in
that direction, if they can see it, or anything anywhere near it; and
there was a great double-peaked mountain covered with snow, like a
white mitre, stuck against the sky in the North. And if her brother
had been in the castle dungeons, she would have made us go down
the front ladder again, instead of getting a wink of back premises."
"Upon my word, this boy is wide-awake, considering how little he
has seen yet of the world. Cator, like Cato, thou reasonest well. Go
ahead, my son, we hearken thee."
"You see, Captain," said the young man, feeling abashed in the
presence of such renown, and doubtful about some chaff in its palm;
"you see, I should never care to offer you advice. It might be in
place with Mr. Cranleigh here, because he is only a young beginner.
But you know what's what, I should say, ever so much better than I
do. But as you tell me to go on, I will. Her Serene Highness intends
to make away with her twin-brother, on Monday next."
"Come now, come now! I can stand a great deal, Cator. And none of
your butter-Scotch—no, you are a Shropshire man, you say.
Whatever you are, it won't make that go down. Why, Old Moore, and
Zadkiel would be nothing to you."
"Captain, I will tell you what I go by, and then you'll be able to judge
for yourself, whether I talk bunkum, or good sense. I have been in
these parts for a twelvemonth now, and I ought to know something
of these blessed natives. There are no two lots of them quite alike,
any more than two mountains or two valleys are. But there is not a
pin to choose among them in the matter of laziness. Poor beggars,
they can scarcely help that, I dare say, frozen as they are for half
the year, and roasted for the other half. Well, about here the manner
is to keep three holidays, Friday, Saturday, and Sunday, just as if
they did anything on the other four days. These Ossets about here
have no religion of any sort worth speaking of. Some call themselves
Christians, some Mahometans, many are simple idolaters; but all are
full of superstition, as such people must be. All they do in the
religious way, is to stick to their fasts and festivals, particularly the
festivals. And their great festival of the year finishes up next
Sunday."
"What the deuce has that got to do with it?" Strogue enquired
impatiently, for the sun was beginning to slope along the valley, and
we had ten miles to go to the next covered place.
"Everything, if you will hear me out. That festival goes on for three
weeks; and during that time it is not lawful to follow up even the
blood-feud. But on Monday, it will be the proper thing to stick and
stab all who are waiting for it. And what makes me think that this
little game is on, according to institution, is that we have not seen a
living soul, except an old woman and a child or two, in the miserable
villages we have come by. Why? For the very simple reason that
every noble savage who can swing a dagger is off for this great act
of faith on Monday; to see the death of the head of the clan
avenged."
"I won't believe a word of it," I exclaimed, meaning no rudeness of
course to Cator, but scouting the possibility of such fiendish
abominations, after all I had heard of the great man's lofty hopes
and pure ideals.
"To me it seems likely enough," said Strogue. "I have been among
fellows who would eat their mothers, and serve up their own babies
for a garnish. We have none of that sort to deal with here; and the
men of these mountains, taking them all round, are an indolent
rather than a cruel lot. Quarrelsome of course, and hot of blood, but
most loyal to their chiefs, and very generous sometimes. It is the
blood-feud that makes devils of them; but how can they help that?
It is their test of honour, ever since they came out of the Ark with
the raven. What we have got to do is to act exactly as if all our
friend Cator suggests were the fact. Thursday to-day; there is little
time to lose, even if we can catch it up at all. We shall want every
son of an emerald of you; and you must fight like sons of the
Emerald Isle. By Jove, what a ripping turn-up it will be! Right about
face, quick march for Kazbek!"
It was all very well for him, and Cator, and the rest to take things
lightly thus. They could not be expected to feel much concern for
the Lesghian Chief, or a Lesghian lady even more adorable. And as
for Strogue his main object was less to rescue Sûr Imar, than to
wreak his own vengeance upon Hafer—that is to say the London
Hafer, the one who had leaped the ivied wall, and shot at me, and
robbed the Captain, by some blackleg's process, of £300.
But I (with my warm affection and deep pity for the father, and
passionate love of the daughter) could see no adventurous joy or
fierce delight in the issue impending. I wanted no revenge, no
compensation for anything done against me. Hafer the genuine, and
Hafer the counterfeit, might settle their claims to the title as they
pleased; even that most malignant and awful woman—if she were as
black as she was painted—the Princess Marva might live her life out,
and give the best account of it when her time came; if only she
could be kept from harming her relatives so innocent. There must be
in her motives something more than we could see. Revenge alone
for the loss of a husband, with whom she had lived on the worst of
terms, and who had wronged her on the tenderest point—that, and
the time-worn grievance about the refusal of her marriage-portion
were not enough to drive her to such a horrible and unnatural deed
as—unless we wronged her most shamefully—she was now in cold
blood designing. There must be some other strong motive too, some
great temptation of self-interest, some of that stern, sour stuff which
drives us out of the hive that should be sweet to us.
No man knows what he does or thinks (unless he can keep himself
separate from the thoughts of all around him, which requires a
wonderful nature) when his legs go along with the legs of other
men, and he has to swing his arms accordingly. There was no sort of
march among us; for we had never been even of the Volunteer
Force (except myself, and that only made me critical, without any
help in it), and if we had wanted to show the Caucasus any sense of
drill, we could never have done it, even if we had known how. By
order of the rocky way, or of rocks without any way among them,
we could never march two abreast, or even three in file with
decency. All we could do was to get along, and admire one another's
clumsiness.
Then we came to a place with a sudden gap in front, and nothing
but the sky beyond it. A cleft in the crown of a rugged ascent, with
spires of black rocks right and left. And there on the saddle-ridge
that we must pass, a gaunt and wondrous figure arose, whether of
man or of beast, and wavered against the grey mist of the distance,
and swayed. Two long arms, like a gallows out of gear, or a cross
that has rotted with its weight, struck up; and having been severely
tried already we were much at a loss what to make of it. There was
good light still, and we were not to be frightened, as we must have
been after sunset; but the Interpreter being always nervous turned
round, and exclaimed: "She has sent the Devil, the Devil himself, to
stop us." While he spoke the long figure fell down on its knees, and
swung its lank arms, like a windmill.
"Hold hard! Don't fire!" Strogue shouted sternly, as some of our men
had brought their guns to bear. "Idiots, it is nothing but a poor lost
man, a fellow without a bit of food inside him. George, let us go and
see what he is up to."
I was ready to go anywhere and do anything in my present state of
mind; and when we came up to him, our poor brother mortal fell
upon his face, and put his hands upon our feet. He muttered some
words which we could not understand, and then he opened his
mouth, which was very large, and pointed down it intelligibly to the
slowest comprehension.
"He may be the Devil, but he wants some grub," Strogue shouted
back to our company, who were still looking towards us doubtfully,
for people become superstitious, without intending it, in these wild
places. Then Cator came up, with a barley-cake in one hand and his
rifle in the other. The unfortunate starver took no heed of the
weapon in his extremity, but stretched his shrivelled arm across the
muzzle, and tore the cake from Cator. In a moment it was gone,
almost without a munch; and then he stared at us, with sun-
scorched eyes projecting from their peel like a boiled potato,—and
groaned for more, crooking his fingers like prongs of a rake. We
shrank from him so that he might not touch us. But for the blood he
was covered with we should have taken him for a skeleton; and but
for his groans and nakedness we should have passed him as a
scarecrow.
"Don't be in such a hurry, old chap, or you'll do yourself more harm
than good," Strogue suggested reasonably. But even if the other had
understood, it would have made no difference. He spread his face
out in such a manner that there was nothing left but mouth; as a
young cuckoo in a sparrow's nest, when his stepmother cannot
satisfy him, squattles his empty body down, and distends himself
into one enormous gape. Then Tommy Williams came up laughing,
with his hat full of broken victuals; and the Captain, who understood
the subject, said: "Not too fast, or he'll fall to pieces. And pour down
a little whiskey to soften it."
When the poor fellow came round a little—and flat enough he had
been before—to our surprise he proved himself an exceedingly brave
and well-intentioned man. In fact, if he had been otherwise we
should never have found him there. A barbarian he appeared at first,
but that was appearance only, and under the stress of misfortune,
although he belonged to a race which is the most barbarous of the
Caucasus. When through our nervous interpreter we began to
understand him, we soon perceived that it was our good luck as well
as his own, which had brought him to us. And much as at first we
grudged the time expended in this humanity, we soon came to see
that it had been well spent, even for our own purposes. After such a
fast, and then such feasting (prolonged in even more than due
redress), it would have been most unfair to expect many words from
him prematurely. We clothed him a little, for he was stark naked,—
and so hairy a person I never beheld,—and then we cut the tight
cord knotted round his waist, from which even famine had not freed
him; and then we made a litter—for he could not walk—and carried
him to our night-quarters. Luckily there was no foe in search of us,
or that miserable sufferer's groans and snores must have told our
whereabout to every echo. He surprised us again by an eager call
for supper, but none would we give him, until he had splashed for a
quarter of an hour in the glacier stream. Then we fed him again, and
clothed him fairly, and a decent and reputable man he looked,
though going down the vale of years. And his tale was interpreted as
follows.
CHAPTER XLVIII
USI, THE SVÂN

"I am Usi, of Ushkul, in the country of the Svâns; Usi the Bear-slayer
was my name, as long as I lived among them. The custom of the
country is that as often as a female child is born, any youth of the
village who looks forward to his need of marriage may come to the
cradle and hang his own bullet around the neck of the infant, and
from that time she is pledged to him, and he must marry her when
she is old enough. When I was a stripling, the wife of our Priest
produced him their fourteenth child, a daughter; and I was the first
to go in at his door, and bespeak the young creature for myself. But
as fortune ordained, the damsel proved deaf and dumb, though in
other ways quite useful; and I very justly refused in the presence of
all the village to marry her. And this I did, when she was ten years
old, allowing her plenty of time for others, who might esteem it to
their pleasure and advantage to possess a wife without a tongue.
But the very next day, when I was watching the maize, a bullet
came through my hat, and lodged in a tree behind me; and when I
dug it out, behold it was my own with the fancy pattern on it, with
which I had betrothed myself ten years before. To that I need not
have paid much attention, but that the Priest had nine well-grown
sons, and it would be the duty of all these nine in succession to lie in
wait for me, and endeavour to shoot me through the head. The
eldest had been too near the mark for me to believe without
rashness that the other eight would fire in vain; so I took my good
mother's advice, which she gave me with many tears, and left my
native place for lifetime. Neither was it safe for me to dwell in any of
the villages for miles and miles around, because we people of the
Svâns had suffered from want of food for the last two years, and
had been obliged to take all the loaves, and corn, and cattle of our
neighbours within three days' journey; and so we were out of favour
with them.
"On this account I was compelled, having borne a strong hand in
those forages, to keep myself away from spots where I would have
settled gladly. At a distance I saw beautiful maidens, over the tops of
the raspberries; but whenever I desired to draw near them, there
was sure to be a father or a brother, whose cow or whose sheep had
been beef or mutton to me. And those people bear such things in
mind, not being generous as we are. And thus I went along the
valleys, feeding on the fruit, wherever the bears had left a tail of it.
Then going further towards the rising sun, which is the strength of
all of us, I came upon a man who carried a kinjal on a gun-mouth.
"In those days, I could jump as high as I could put my hands up;
and being surprised by his pointing at me, I did it to give him time to
think. This made him think more of me than I deserved, and instead
of shooting me, he asked in what land men could jump so. I could
not understand at first, though he did it with all his fingers; because
we had kept ourselves apart from other people, whenever we could
live without our neighbours' goods. But I was always considered the
foremost of the young men for understanding, and I contrived to
make out what he meant, and to do a thing which is much harder—
to make him know what I meant. He was a soldier of the great
Imaum, desiring to shoot Russians; and as soon as we made out
one another, he showed me the notches on his gun, and I counted
forty-two, and he said every one was the good corpse of a Russian.
This made me long to do the like, though the Russians had never
shot at me, but my own friends had; and my soul arose to look
along a gun at any stranger, even as it had been done to me.
"Others came up, and when they found how straight my barrel was,
and what it was famous for doing among the bears, the Captain
said, 'Thou shalt do it, my lad, with the bears that eat our people.'
And so I was put into Shamyl's army, and for many years enjoyed
myself. I have shot three Russian colonels, and small officers by the
dozen; and I could have shot the Commander once; but his
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!

ebookname.com

You might also like