100% found this document useful (7 votes)
38 views

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

Architecture

Uploaded by

tunonnaihe6d
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 (7 votes)
38 views

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

Architecture

Uploaded by

tunonnaihe6d
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/ 50

Download the full version of the ebook at ebookname.

com

Software Architecture Design Patterns in Java 1st


Edition Partha Kuchana

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

OR CLICK BUTTON

DOWNLOAD EBOOK

Download more ebook instantly today 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/

ebookname.com

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/

ebookname.com

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/
ebookname.com

Global Trade in Services Fear Facts and Offshoring 1st


Edition J. Bradford Jensen

https://ebookname.com/product/global-trade-in-services-fear-facts-and-
offshoring-1st-edition-j-bradford-jensen/

ebookname.com
Sauces 3rd Edition James Peterson

https://ebookname.com/product/sauces-3rd-edition-james-peterson/

ebookname.com

Micromechanics of Fracture and Damage Volume 1 1st Edition


Luc Dormieux

https://ebookname.com/product/micromechanics-of-fracture-and-damage-
volume-1-1st-edition-luc-dormieux/

ebookname.com

New History of Anthropology 1st Edition Henrika Kuklick

https://ebookname.com/product/new-history-of-anthropology-1st-edition-
henrika-kuklick/

ebookname.com

Multilateralism and the World Trade Organisation The


Architecture and Extension of International Trade
Regulation Routledge Advances in International Political
Economy 1st Edition Rorde Wilkinson
https://ebookname.com/product/multilateralism-and-the-world-trade-
organisation-the-architecture-and-extension-of-international-trade-
regulation-routledge-advances-in-international-political-economy-1st-
edition-rorde-wilkinson/
ebookname.com

1948 A History of the First Arab Israeli War First Edition


Benny Morris

https://ebookname.com/product/1948-a-history-of-the-first-arab-
israeli-war-first-edition-benny-morris/

ebookname.com
Ecology 4th Edition William D. Bowman

https://ebookname.com/product/ecology-4th-edition-william-d-bowman/

ebookname.com
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: [email protected]
© 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: [email protected]

© 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


Random documents with unrelated
content Scribd suggests to you:
former is the first of six such works published in 1837 as opus 35.
The prelude is the best part of it. Though here as elsewhere he
seems to have no new or interesting means to set the piano in
vibration, though he holds without change to close arpeggio figures
throughout, yet there is a breadth of style and a sweep which
approaches real power of utterance. The fugue is excellently put
together. The theme itself recalls Bach, for whom, be it mentioned,
Mendelssohn had profound and constant admiration, and whose
works his untiring labor resurrected and brought to public
performance. Still it need hardly be added that this fugue is a work of
art, more than of expression. The inversion of the theme is clever,
and there is a certain pompous grandeur in the sound of the chorale
just before the end. The other preludes and fugues in the set are
relatively uninteresting.

The Variations are worthy of study and are by no means lacking in


musical value. The theme itself was happily chosen. There is a
respectable sadness and melancholy in it far more dignified and
genuine than the sentimentalities of the ‘Songs without Words.’ The
harmonies which underlie it are hardly bold enough to dash beyond
the diminished seventh; but a number of chromatic passing notes
give the whole something like poignancy and considerable warmth.
Moreover, it suggests chromatic treatment in the subsequent
variations.

The variations themselves are full of change and offer a range of


contrast of which Mendelssohn was not often master. The effect of
the series as a whole is therefore stimulating and rather brilliant.

The first variation adds a counterpoint to the theme in groups of four


sixteenths. The counterpoint in the second is of groups of six
sixteenths. The first two variations thus seem to set the piece
gradually into a free motion, which throughout the next two grows
more vigorous and more nervous. The fifth is typical of
Mendelssohnian agitation; but it serves as an excellent introduction
to the chords of the sixth and seventh. The eighth and ninth work up
to a frenzy of quick motion. Then follow two in a suppressed and
quiet style, the first a little fugue, the second a brief and exquisite
cantilena. The twelfth is the most vigorous of the lot, a movement as
near the virtuoso style as Mendelssohn ever was able to produce.
The thirteenth is interesting by reason of the contrast between the
legato melody in the left hand and the excellent staccato
counterpoint. A short adagio, rather superior to most of the songs in
a similar style, forms the fourteenth. The fifteenth is transitional, the
sixteenth and seventeenth merely lead up to the presto at the end.
The entire group presents nothing in the treatment of the piano in
advance of Weber, if, indeed, it anywhere equals him; but it is both in
quality and in style a very fine piece of pianoforte music, which can
hardly fall under the censure to which most of his music for the
instrument is open.

There are two concertos and a concert piece for piano and
orchestra. The latter owes its form and style very clearly to Weber’s
concert piece in F minor. Both the concertos are fluent and plausible
enough; the orchestra is handled with Mendelssohn’s customary
good taste and sensitiveness; but the writing for the pianoforte is
wholly commonplace and the themes themselves of little or no
distinction.

The ‘Songs without Words’ were published in six groups of six


pieces each during his life. After his death in 1847 two more sets
appeared. The influence of all these was widely felt, particularly
among composers of mediocre gifts. Chopin had no liking for them.
In fact, Mendelssohn’s music was more than ordinarily distasteful to
him; and he is said to have declared that Mendelssohn never wrote
anything better than the first song without words. In some respects
this is true. Schumann had a great admiration for Mendelssohn;
admired his orderly style and manner. But Schumann’s individuality
was far too pronounced, especially in pianoforte predilections, to
submit to the milky sway of Mendelssohn.

In pianoforte music, William Sterndale Bennett (1816-1875) carried


on the Mendelssohn tradition quite undefiled. Bennett was more than
a pupil of Mendelssohn; he was a devoted and unqualified admirer.
His own pianoforte works are numerous, but they have suffered
something of the same malice of Fate that still preserves the ‘Songs
without Words’ chiefly for fun. They include four concertos, and
many short pieces, studies, diversions, impromptus. They have the
merits of their prototypes, clear, faultless writing and melodiousness.

A contemporary of Mendelssohn whose life led him finally to


Petrograd, is still remembered by one or two of his studies. This is
Adolf Henselt (b. 1814-89). Henselt’s work is really independent of
Mendelssohn. His style was founded upon a close acquaintance with
Weber’s. In 1836 he gave private recitals in Berlin and was
especially prized for his playing of the Weber sonatas. Two sets of
concert studies were published as opus 2; and in them is the still
famous and delightful Si oiseau j’étais. Besides these he composed
numbers of Rhapsodies, Ballades, and other short pieces in the
romantic style; all of which together show distinctly more originality in
the treatment of the piano than Mendelssohn showed.

II
Meanwhile Robert Schumann was composing sets of pieces which
have been and long will be regarded as one of the most precious
contributions of the Romantic movement to pianoforte literature.
Schumann was an enthusiast and an innovator. He was a poet and a
warm-hearted critic. He was the champion of the new and the fresh,
of self-expression and noble sentiment. In his early manhood a
strained finger resulted from over-enthusiastic and unwise efforts to
make his hand limber, and cut short his career as a concert pianist,
for which he had given up his study of the law, not without some
opposition. He turned, therefore, with all fervor to composing music
for the pianoforte, and before his long-delayed marriage with Clara
Wieck, daughter of his teacher, had published the sets of pieces on
which a great part of his fame now rests.

Schumann was steeped in romantic literature, particularly in the


works of Jean Paul Richter and E. T. A. Hoffmann; and most of his
works show the influence of these favorite writers upon him. One
finds symbolical sequences of notes, acrostics in music, expressions
of double and even triple personalities; but these things are of minor
importance in his music. The music itself is remarkably warm and
poetic, remarkably sincere and vigorous whatever the inspiration
may have been. It is happily sufficiently beautiful in itself without
explanation of the cryptograms which oftener than not lie underneath
it.

He was, as we have said, an explorer and an innovator by nature;


and his music is full of signs of it. Though his treatment of the piano
lacks the unfailing and unique instinct of Chopin, nevertheless his
compositions opened up a new field of effects. Not all of these are
successful. Experiments with overtones such as one finds, for
instance, at the end of the Paganini piece in the Carnaval can hardly
be said to be worth while. The result is too palpably an isolated effect
and nothing more. It is too self-conscious. But he was of great
significance in expanding the sonority of the instrument, in the use of
the pedal, in the blending of harmonies, in several finer touches of
technique. The combination of two distinct themes in the last
movement of the Papillons, the fluent and sonorous use of double
notes in the Toccata, the wide skips in the 'Arlequin’ and the
'Paganini’ numbers of the Carnaval, the latter with its cross-accents;
the Reconnaissance in the same series, with its repeated notes; the
rolling figures in the first movement of the Kreisleriana; these, among
other signs of his originality, are new in pianoforte music.

His compositions demand from the pianist an unlimited and a


powerful technique, yet it cannot be said of any that it is virtuoso
music. He employed his skill not so much to display as to express
his ideas. Nowhere does the pianoforte seem more the instrument of
intimate and highly romantic sentiment. Of figure work and
ornamentation there is very little. His music is not at all dazzling.
Much of it is veiled. At the most he is boisterous, as in parts of the
Faschingsschwank and the last movements of the Études
Symphoniques. He rather avoids the high, brilliant registers of the
keyboard, stays nearly constantly in the middle of things, deals in
solid stuff, not tracery.

Perhaps the most distinctive feature of his style is his frequent use of
syncopated rhythms. This becomes at times an obsession with him;
and there are many passages in his music so continuously off the
beat, that the original measure is quite lost, and the syncopation is to
all practical purpose without effect. In such passages it seems hardly
possible that Schumann intended the original beat to be kept in mind
by the accentuation of notes that are of secondary importance;
unless, of course, the interest of the music is chiefly rhythmical. Yet
in some passages of purely melodic significance this may be done
without awkwardness, producing an effect of dissociation of melody
and harmony which may be what Schumann heard in his mind.

These are problems for the pianist, but a few of them may be
suggested here. The last movement of the very beautiful concerto is
in 3/4 time. There is no change of time signature for the second
theme. This, as first announced by the orchestra in E major and later
taken up by the piano solo in B major, is none the less in 3/2 time.
Such must be the effect of it, because the passage is long and
distinct enough to force the 3/4 beat out of the mind, since no note
falls in such a way as to accent it. But when the orchestra takes up
this theme, again in E major, the piano contributes a steadily flowing
stream of counterpoint. In this it is possible to bring out the original
measure beat, throwing the whole piano part into a rhythm counter to
the rhythm of the orchestra. Such an accentuation is likewise out of
line with the natural flow of the counterpoint; yet it may be what
Schumann desired here, as well as in the following section, where,
though the orchestra is playing in 3/2 time, the pianist may go
against the natural line of his own part and bring out a measure of
three-quarter notes.

The middle section of the second movement of the great Fantasy in


C major presents the same problem. Here we have a melody in long
phrases. The notes of it are off the beat, the chords which furnish its
harmony are on the beat. Every eight measures the natural rhythm
asserts itself; yet even these periodic reminiscences of the measure
cannot serve to throw the whole melody into syncopation. The
melody is too strong and its phrases too long. More than the
occasional measures, it must, if allowed fully to sing, determine the
rhythm of the passage. So it is usually played; so, without special
effort to the contrary, it will impress the ear. Now is it possible that
Schumann intended the accompanying chords to be distinctly
accented? Such an accent, delicately applied, with the skillful use of
the pedal, will create a wholly new effect, which can be drawn from
all the succeeding passages as well.

Other passages offer no alternative. There is no way to suggest the


original beat except by movement of the body, or by grunting; both of
which are properly discountenanced. Examples may be found in the
first movement of the Faschingsschwank and elsewhere.

Most of Schumann’s pianoforte music is made up of short pieces.


Such are the Papillons, the Carnaval, the Davidsbündler Dances, the
Faschingsschwank, the ‘Symphonic Studies,’ and the Kreisleriana.
Each of these is a cycle of pieces, and is at best only loosely held
together by one device or another. The Papillons are scenes at a
fancy dress ball. The return of the first piece at the end gives a
definite boundary, as it were, to the whole. The Faschingsschwank
are pictures of a fête in Vienna. There is no structural unity to the
work as a whole. The fanciful idea upon which it rests alone holds
the pieces loosely together.

The Carnaval, likewise a scene at a fair, representations in music of


various people, sights, and sounds, is built on three series of notes
which Schumann called ‘Sphinxes’ and which he had published with
the music. It is very doubtful whether the employment of these
sequences in one form or another gives to the whole series an
organic interdependence. Only with care can the student himself
trace them, in such varied guises do they appear; and to be left in
entire ignorance of them would hardly interfere in the least with an
emotional appreciation of the music. The return at the end of some
of the movements and passages heard at the beginning, however,
rounds off the work and makes an impression of proportions.
Moreover, within the work many of the pieces lead without pause into
the next, or are without an end at all, like the Florestan, which is left
fulminating in the air.

In the Davidsbündler there is again the return at the end of familiar


phrases, but the Kreisleriana is like the Faschingsschwank without
structural unity. Yet perhaps none of the Schumann cycles is less
friable than the Kreisleriana. It is long and it is varied; but here,
perhaps more than in any other similar works of the composer, there
is a continuous excellence of workmanship and intensity of
expression.

Besides these cycles there are sets of short pieces which are
independent of each other. Such are the ‘Fantasy Pieces,’ the
Novelettes, the ‘Romances,’ and the Bunte Blätter, among others.
These may be fairly compared with the ‘Songs without Words’ of
Mendelssohn. How utterly different they prove to be, how virile and
how genuinely romantic! They are not only the work of a creative
genius of the highest order, they show an ever venturesome spirit at
work on the keyboard. Take, for example, the ‘Fantasy Pieces.’ The
first, called Des Abends, is as properly a song as any of
Mendelssohn’s short pieces which are so designated. The very
melody is inspired and new, rising and falling in the long smooth
phrases which are the gift of the great artist, not the mere music-
maker. The accompaniment appears simple enough; but the wide
spacing, the interlocking of the hands, above all, its rhythm, which is
not the rhythm of the melody, these are all signs of fresh life in
music. The interweaving of answering phrases of the melody in the
accompaniment figures, the contrast of registers, the exquisite points
of harmonic color which the accompaniment touches in the short
coda, these are signs of the great artist. It is remarkable how little
Mendelssohn’s skill prompted him to such beautiful involutions; how,
master as he was of the technique of sound, he could amble for ever
in the commonplace. And Schumann, with far less grasp of the
science, could venture far, far beyond him.
The second of the ‘Fantasy Pieces,’ Aufschwung, calls imperiously
upon the great resources of the pianoforte. There is power and
breadth of style, passion and fancy at work. It is a wholly different
and greater art than Mendelssohn’s. It is effective, it speaks, it
proclaims with the voice of genius. And in the little Warum? which
follows it, skill is used for expression. There is perhaps more
appreciation of the pianoforte in this piece, which by nature is not
pianistic, than there is in all the ‘Songs without Words,’ an
appreciation of the contrasting qualities of high and low sounds, of
the entwining of two melodies, of the suggestive possibilities of
harmony.

Take them piece by piece, the Grillen with its brusque rhythms, its
syncopations, its rapidly changing moods; the In der Nacht, with its
agitated accompaniment, its broken melodies, and the soaring
melody of the middle section, not to mention the brief canonic
passages which lead from this section back to the wild first mood;
the delicate Fabel, the Traumes Wirren with its fantastic, restless,
vaporish figures and the strange, hushed, shadows of the middle
section; and the Ende vom Lied, so full for the most part of good
humor and at the end so soft and mysteriously sad; these are all
visions, all prophecies, all treasure brought back from strange and
distant beautiful lands in which a fervid imagination has been
wandering. Into such a land as this Mendelssohn never ventured,
never even glanced. For Schumann it was all but more real than the
earth upon which he trod, such was the force of his imagination.

The imagination is nowhere more finely used than in the short pieces
called the Kinderscenen. Each of these pieces gives proof of
Schumann’s power to become a part, as it were, of the essence of
things, to make himself the thing he thought or even the thing he
saw. They are not picture music, nor wholly program music. They are
more a music of the imagination than of fact. Schumann has himself
become a child in spirit and has expressed in music something of the
unbound rapture of the child’s mind. So, even in a little piece like the
‘Rocking Horse,’ we have less the picture of the ‘galumphing’
wooden beast, than the ecstasy of the child astride it. In the Curiose
Geschichte there is less of a story than of the reaction of the child
who hears it. In the Bittendes Kind and the Fürchtenmachen this
quality of imagination shows itself with almost unparalleled intensity.
The latter is not the agency of fear, it is the fear itself, suspense,
breathless agitation. The former does not beg a piece of cake; it is
the anguished mood of desire. Only in the last two pieces does
Schumann dissociate himself from the moods which he has been
expressing. The former, if it is not the picture of the child falling
asleep, is the process itself; the latter is, as it were, the poet’s
benediction, tender and heartfelt.

The whole set presents an epitome of that imagination which gave to


Schumann’s music its peculiar, intimate, and absorbing charm. His
might well be considered the most subjective of all pianoforte music.
It is for that reason dull to practice. The separate notes of which it is
composed give little objective satisfaction. The labor of mastering
them routs utterly in most cases the spirit which inspired them. Fine
as the craftsman’s skill may prove to be in many of the pieces, it is
peculiarly without significance, without vitality, until the whole is set in
motion, or set afire by the imagination.

The most imaginative and the most fantastic of the works as a whole
is the series of twenty short pieces which make up the Carnaval,
opus 9. Here there is a kaleidoscopic mixture of pictures, characters,
moods, ideas, and personalities; the blazonry of spectacle, the noise
and tumult, the quiet absorption that may come over one in the midst
of such animation, the cool shadows beyond the edge of it wherein
lovers may wander and converse; strange flashes of thought,
sudden darting figures, apparitions and reminiscences. All is
presented with unrelaxing intensity. One cannot pick out a piece from
the twenty which does not show Schumann’s imagination at fever
heat. There is a wealth of symbolism; the Sphinxes, mysterious
sequences of notes that are common to all the pieces, and dancing
letters which spell the birthplace of one of Schumann’s early loves.

As to the Sphinxes it may be said, as before, that the coherence


which they may add can hardly exist outside the mind of the player,
or of the student who has made himself thoroughly familiar with the
work. The average listener may hear the whole work a hundred
times, learn to know it and to love it, without ever realizing that the
first intervals of the Arlequin, the Florestan, of the Papillons and
others are the same; those of the Chiarina, the Reconnaissances,
and the Aveux likewise, note for note identical. Such hidden
relationships in music are vaguely felt if felt at all. Just as two words
spelled the same may have different meanings, so may two musical
phrases made up of the same intervals be radically different in effect.

The Carnaval opens with a magnificent prelude. The first section of it


suggests trumpeters and banners, the splendid announcement and
regalia of a great fête. After this we are plunged at once into the
whirr of merry-making. Schumann’s cross-accents and syncopations
create a fine confusion; there is hurly-burly and din, a press of
figures, measures of dance, light and tripping, an ever-onward rush,
animato, vivo, presto! There is a splendid effect in the last section,
the presto. The measure beat is highly syncopated. It will be
observed that in the first eight measures the first notes of every other
measure, which are in all dance music the strongest, are single
notes. These alone keep up a semblance of order in the rhythm. By
the extension of one measure to four beats, the sequence of notes is
so changed that in the repetition of this first phrase the strong accent
falls upon a full chord, thus greatly re-enforcing the intended
crescendo.

The next two numbers in the scene are pictures of two figures
common to nearly every fair, the Pierrot and the Harlequin. The
distinction between them is exquisite. In Pierrot we have the clown,
now mock-mournful and pathetic, only to change in a second and
startle with some abrupt antic. Harlequin, on the other hand, is
nimble and quick, full of hops and leaps. At the end of the Pierrot, by
the way, there is the chance to experiment with the pedal in
overtones. The sharp fortissimo dominant seventh, just before the
end, will set the notes of the following chord, all but the fundamental
E-flat, in vibration if the pedal is pressed down; so that the keys of
this second chord need hardly to be struck but only to be pressed.
And when the pedal is lifted, this second chord will be left still
sounding, by reason of the sympathetic vibration which was set
about in its strings by the loud chord preceding.

Pierrot and Arlequin are professional functionaries at the fair. We are


next introduced to a few of the visitors. There is a Valse noble and
then Eusebius. Schumann imagined within himself at least three
distinct personalities of which two often play a rôle in his music. One
is active and assertive. He is Florestan. The other is Eusebius,
reflective and dreamy. Here, then, is Eusebius at the fair, wrapped
about in a mantle of gentle musing. His page of music in the
Carnaval is one of the loveliest Schumann ever wrote. Elsewhere,
too, the contemplative young fellow speaks always in gentlest and
most appealing tones; as in the second, seventh, and fourteenth of
the Davidsbündler Dances, all three of which are subscribed with a
letter E.

In the Carnaval, as in the Dances, Florestan breaks roughly into the


meditations of Eusebius. He works himself into a very whirlwind of
energy; and then Schumann, by a delicious sense of humor, lets the
artful Coquette slide into his eye and put an end to his vociferations.
To her there is no reply but the gentle, short Replique. Are the
Papillons which follow masqueraders? The horn figures of the
accompaniment bring in a new group to the fair, fresh from the outer
world. They are gone in a flash, and their place is taken by three
dancing letters, 'As,’ C, and H; As being German for A-flat, and H for
B. And these letters spell the birthplace, as we have said, of one of
Schumann’s early loves.

The love of his whole life follows—Chiarina, his beloved Clara; and,
as if with her were associated the loveliest and most poetic of
pianoforte music, he calls Chopin to mind. Chopin at this fair! It is a
fantastic touch. More than when Eusebius speaks, the background
of gay dancers and masqueraders fades from sight. For a moment
Chopin is in our midst. Then he has vanished. And at once another
thought of Clara, this time as Estrella; then an acquaintance in the
throng. He has seen a face he knew, it is a friend. It is the Sphinx of
Chiarina in the music. Is it she he recognized? Are the lovely
interchanges in the middle section conversations with her? If so,
their mood is light. They have met at a fair. They are in the merry-
making.

Two more professionals, masquers this time—the world-favorites,


Pantalon and Colombine; and at the end of their piece an exquisite
thought of Schumann’s. Then the German waltz, simplicity itself; and
in the midst of it none other than the wizard, Paganini! Surely, there
was never a stranger trick of thought than that which thus placed
Paganini in the midst of a simple, tender German waltz. He vanishes
in a puff of smoke, as conjured devils are supposed to do; and the
waltz goes on, as if all this intermission had been but a flash in the
air above the heads of dancers too absorbed in their pastime to note
such infernal phenomena.

After the waltz, a lover’s confession, hesitating but enraptured; and


then a Promenade. There is full feeling, there is delight and ecstasy.
Our lover whirls his maiden from the fair. Farther and farther they go,
hand in hand, into the shadowy, calm night. Fainter and fainter the
sounds of revelry, till all is silence.

There is a pause. The lovers are dispatched. Away with dreaming,


away with sentiment! Back into the hurly-burly and the din. Here
comes the band of David down the plaisance, hats in air, banners
flying, loudly cheering. These are the sons of the new music. These
are the champions of the new era of freedom, these the singers of
young blood. More and more reckless, madder and more gay!
Spread consternation abroad among the Philistines, put the learned
doctors to rout, send them flying with their stale old tunes and laws!
So the Carnaval ends, with the flight of the old and dusty, and the
triumph of the enthusiasm of youth.

Here is a phantasmagoria unmatched elsewhere in music. It is very


long. It is too long; and, judged as a whole, the work suffers in
consequence. It is overcrowded with figures, too full of symbolism;
and the ear tires, the attention wearies. Yet there is not a piece in it
which one would be willing to discard. All are beautiful and new and
full of life. Many present something peculiar to Schumann, the fruit of
his imagination, which is in advance of most of the music of his time.
It must occupy an important place in the history of pianoforte music,
as representing one of the finest accomplishments directly due to the
influence of the Romantic movement.

III
The other cycles of Schumann comparable to it are the Papillons,
opus 2, the Davidsbündler Tänze, opus 6, and the
Faschingsschwank aus Wien, opus 26. The first of these is short and
slight, but of singularly faultless workmanship and rare charm. The
last must be cherished for the Romanza, the Scherzo, and the
splendid Intermezzo; but the first movement is rather out of
proportion, and parts of the last are perfunctory and uninteresting.

Most of the Dances of the Davidsbündler are beautiful. The series is,
however, much too long and too loose to be regarded as a whole.
There are passages of unsuccessful workmanship, notably in the
third; some of the dances are rambling, some rather commonplace.
On the other hand, many may be ranked among the best of
Schumann’s compositions. The second, seventh, and fourteenth
have been mentioned as among the beautiful utterances of
Eusebius; the fifth is less distinguished but is delightful pianoforte
music. Florestan does not make quite such a good impression,
except possibly in the fourth and the twelfth. The fifteenth speaks for
both Florestan and Eusebius; and the E-flat major section is
splendidly rich and full-throated music. The last dance of all is like a
happy, wayward elf waltzing along in the wake of more substantial
dancers. The series may properly end with the seventeenth; but, as
Schumann said, though Eusebius knew well that the eighteenth was
quite superfluous, yet one could see by his eyes that he was blissful
over it.[32]
Both the ‘Symphonic Studies’ and the Kreisleriana stand apart from
the works previously discussed. The former, opus 13, was written in
1834, the latter, opus 16, in 1838. A brief glance at opus 1, the
‘Abegg’ variations, written in 1830, will serve to make clear the
immense progress Schumann made in the art of composition in the
brief space of four years. The early work is by no means lacking in
interest. Schumann reveals himself in nearly every page. The theme
itself is made up of the notes a, b, e, g, g, spelling the name of the
honorable lady to whom the variations were dedicated. In the middle
of the last movement he experiments with a new style of
diminuendo, allowing a chord to die away by separate notes, till only
one note of it is left sounding. He tried the same effect again at the
end of the Papillons. But the workmanship, though clever, is for the
most part conventional. The statement of the theme is laughably
simple, particularly the ‘echoes,’ pianissimo, in broken octaves. Such
a device recalls the ‘Maiden’s Prayer’ and fountain curls. The
variations show a fine ear for pianoforte effects. The first especially is
in virtuoso style and makes more use of the upper registers of the
keyboard than is common in the later works. But the harmonies,
though richly altered, are conventional, and so are the figures. The
third, fourth, and fifth might have been written by Hummel.

The ‘Symphonic Études’ are immeasurably broader and more


original. They are written as variations; but Schumann confines
himself very little to the conventional scheme; and the third and ninth
are not variations at all, but études made up of wholly extraneous
ideas. The theme itself is dignified and rich, and its statement in the
sonorous middle registers of the piano is impressive. In the first
measures of the first variation there is little or no suggestion of the
theme save in harmony. The opening phrase is given low down,
repeated in higher registers, till the music has climbed nearly four
octaves; at which point a phrase of the theme makes its appearance.
Toward the end of the variation the same phrase is heard again; but
the whole is distinctly dominated by the figure announced in the first
measure.
In the second variation the theme is carried throughout in the bass;
but a beautiful new melody is imposed upon it which carries the
burden of the music. The third of the series is unrelated to the theme
except in key. It is a study in light, wide, staccato figures for the right
hand; under which the left hand carries a suave and expressive
melody. In the next movement, the theme is treated consistently as a
canon at the octave. The next is at once a study in a capricious
dotted rhythm and a subtle variation of the theme. And in the
following, the sixth, the theme is wholly prominent in both hands, the
left anticipating the right by the fraction of a beat. The seventh is a
magnificent study for the movement of the arm from one group of
notes to another. It is in E major, and the theme makes but an
occasional and fragmentary appearance. The eighth is a study in
sharp cross-accents, the theme again wholly concealed, except for
its harmonies; the ninth a study in double notes and octaves for the
wrist. The tenth, eleventh, and twelfth are high-water marks in
Schumann’s treatment of the pianoforte, both in brilliant and poetic
effects. Particularly worthy of study are the accompaniment figure in
the latter, with its rich shimmering of harmony, and the skillful
interweaving of two melodies in the fashion not long before
employed in the short Warum?. The finale, which, with the repeats
Schumann incorporated into it, is far too long, practically exhausts
the power of the piano in big chordal effects.

There is but little trace of the composer of the Abegg variations in


these imposing and wholly beautiful studies. Schumann shows
himself in them such a master of the pianoforte as has no need to
display his wares, but may let their intrinsic richness and splendor
speak for them. Only in the last of them does he lay himself open to
the criticism of having treated the piano in a style too nearly
orchestral, which expects from the instrument a little more than it can
furnish. Elsewhere in the series the very spirit of the piano speaks, a
noble and moving language, full of imagery and of color. The obvious
virtuoso trappings of Weber are left far behind. We are on one of the
great heights of pianoforte literature.
Schumann considered the Kreisleriana to be his best work for the
piano alone. It was inspired by the character of Johannes Kreisler,
an eccentric, highly gifted kapellmeister who figured in the tales and
musical papers of E. T. A. Hoffmann.[33] Just what it means few will
venture to suggest. The last movement may recall the account of the
last appearance of Kreisler on this earth, as he was seen hopping
along the road beyond the town, with a red hat on the side of his
head and a wooden sword by his side. Dr. Oskar Bie quotes from
Hoffmann in connection with the second movement, the tale of the
young girl who was lured to a magic oak by the sound of a lute, and
there killed; whose heart grew into a twining rose-bush.[34] In the
main, however, the music eludes analysis. It is eccentric. Though full
of the mannerisms of Schumann, much of it presents an unfamiliar
mood of the composer. The moods of it are different from the moods
of the ‘Carnival,’ the ‘Symphonic Études,’ the ‘Fantasy,’ the ‘Scenes
of Childhood.’ On the whole, it lacks the warmth of his other works. It
is fantastic, and not unfrequently grotesque; parts of it strangely
deliberate. Many pages of it are out of the usual and consequently
baffling. It is more involved, too, in workmanship, and the separate
movements full of contrasts that seem to be vagaries. Schumann
has, of course, here as elsewhere put himself into the person of his
inspiration; and the result is a tribute to the power of his imagination.
Never was music more fantastic, less consequential.

It is, on the other hand, superb. The opening movement alone, with
its figures like short waves in a windy sea, its sharp cross-accents,
its filmy, elusive trio, is a masterpiece. The second movement is
unbalanced, yet at times most wondrously beautiful. The opening
theme in itself is inspired, though it is perhaps overworked. But what
is the meaning of the harsh chords which interrupt it and shatter the
mood which it might else instill? The style is polyphonic in places;
there are inner melodies that slide long distances up and down the
keyboard, oftenest in tenths. The two intermezzi furnish a welcome
contrast to the intense subjectivity of most of this second movement.
After the second there comes one of the loveliest pages in all
Schumann’s pianoforte music.
The third movement is built on a restless, jerky figure, in ceaseless
movement. There are strong accents and unusual harmonies. A
middle section offers yet another happy instance of Schumann’s skill
in dialogue between two melodies, such as we have already noticed
in Warum? and the eleventh of the ‘Symphonic Études.’ The
movement is somewhat slower than the main body of the piece, but
a strange sort of half-accompaniment does not allow the
restlessness to subside altogether.

The fourth and sixth movements are slow. In both there is some
thickness of scoring, a sinking too deep into the lower registers. Both
are about the same length and both are constructed on the same
plan; consisting of an incompleted, or broken, melody of the most
intimately expressive character, a few measures of recitative, the
melodious phrases again—in the one wandering down alone into the
bass, disappearing rather than ending, in the other not completing
itself, but developing into a contrasting section. In both there are
these contrasting sections of more articulate and more animated
music; and in both there is a return of the opening melody. There is
wonderful music in these two short movements; but it is mysterious,
fragmentary and incomplete, visionary, as it were, and without
definite line.

The remaining movements escape language. The fifth is full of


changing moods; the seventh more than the others, consistent, this
time in a vein of something like fury. The eighth and last is delicate
and whimsical. The right hand keeps to a light, hopping figure most
of the time; the left hand has little more than long single notes, which
pursue a course of their own, without regular rhythm.

There is a lack of titles, there is no motto, there is even no mark of


Florestan and Eusebius. This most whimsical, most subjective, and,
in many ways, most beautiful and most complicated of Schumann’s
creations, stands before us, then, with no clue to its meaning except
its title. This, as we have said, refers us to a half-crazy, fantastical
musician. There is more in the music than lunacy, full of vagaries as
it is. There is much poetry, a clearness and sanity in diction,
inconsequential as the thought may be, a mastery of the science of
music. Yet it is not surprising if some, bearing in mind the
preternatural activity of Schumann’s imagination even in early
manhood, and the breaking-down of his mind toward the end of his
life, will hear in this music a note of something more tragic than
whimsical fancies, will feel that Schumann has strayed perilously far
afield from the world of orderly nature and warm blood.

A few short pieces that Schumann published, like the Novelletten,


are not held together in a cycle. In these the humor is prevailingly
happy and active, the workmanship clear, and the form well-
balanced. Fine as they are, in listening to them separately one
misses something of Schumann. The man was a dreamer. He sank
himself deep into moods. He lived in complete worlds, created by his
fancy. A single piece like one of the ‘Novelettes’ hardly initiates the
listener into these wide domains. Fully to put ourselves in touch with
Schumann we must wander with him, and in the course of our
wandering, drift farther and farther into his land of phantoms.

Four works in broad form must be reckoned among his greatest


compositions. These are two sonatas: one in F-sharp minor, opus
11, one in G minor, opus 22; the great ‘Fantasy’ in C major, opus 17;
and the concerto for pianoforte and orchestra in A minor, opus 54. It
is hard to estimate the worth of the sonatas. That in F-sharp minor is
rambling in structure, and too long; yet there are pages of splendid
music in it. The introduction is full of a noble passion and strength;
the first theme of the first movement has a vitality which, better
ordered, would have made of the whole movement a great
masterpiece; and the second theme is undeniably beautiful. But
transitional sections and the development are monotonous and too
little restrained. The second movement, making fuller use of the
themes hinted at in the introduction, is wholly satisfying; the scherzo,
likewise, with its grotesque Intermezzo and mock-heroic recitatives.
But in the last movement again there is far too much music, far too
little art; and, despite the healthy vigor of the chief theme, the piece
staggers rather than walks.
The sonata in G minor is more concise, is, indeed, perfect and clear-
cut in form. All of it is lovely, particularly so the Andantino and the
Rondo. There is perhaps too much restlessness in the first
movement and, consequently, too little variety. It is all flame and no
embers.

The Fantasy is colossal. It is said that Schumann intended the first


movement to represent ruins, the second a triumphal arch, the last a
starry crown. Subsequently he changed his intention; but something
of these original characteristics still remains. The first movement is a
strange mixture of stark power, tenderness, and romantic legend. It
is not hard to find in it the groundwork of the triplex form. There is a
first theme, the dominant theme of the movement, strangely gaunt
and bare; and a contrasting theme beautifully melodious which
Schumann associated with his beloved Clara. These two themes are
presented fairly regularly in the first section of the movement; and
the last section brings them back again, as in the triplex form. But
there is a broad middle section, in legendary character, which
presents a wealth of different material, some of which has been
freely used between the first and second themes in the first section.
The whole is greatly expanded, full of pauses, passages of
unrestrained modulation. The effect is truly magnificent.

The second movement exceeds the finale of the ‘Symphonic Études’


in triumphant vigor. The last movement is long, richly scored, exalted
in sentiment. The endings of the three movements, especially of the
first and last, are inspired, wholly without trace of the commonplace.
It is one of the truly big works for the piano, lacking perhaps in
subtlety and refinement of technique, sometimes a little awkward
and out of proportion, but full of such a richness of harmony and
melody, of such passion, strength, and romance, of such poetry and
inspiration, as to defy criticism. It is, as we have said, colossal.

The concerto stands as a flawless masterpiece. The themes are


inspired. There is no trace of sentimentality or morbidness. The form
is ruled by an unerring and fine sense of proportion and line. It is
neither too long nor too short. There is no awkwardness, no
tentativeness, no striving for effect. No note is unwisely placed. The
treatment of both pianoforte and orchestra leaves nothing to be
desired, either when the one is set against the other or when both
are intimately blended. Though it in no way suggests the virtuoso, it
is perfectly suited to the piano, bringing out unfailingly the very best
the instrument is capable of. Thus it stands unique among
Schumann’s compositions. There must be many to whom it stands
for an ideal realized. To them it will be unique among concertos, the
most excellent, the perfect type.

With this masterpiece we may take leave of Robert Schumann, for


whom most pianists will ever have a special love. The first
movement was composed in 1841, the Intermezzo and Finale in
1845, all after his marriage in the fall of 1840. After this happy
termination to long and troubled years, his attention turned to other
branches of music, to songs, to oratorios and symphonies; and,
though he never forsook the piano entirely, the best of his work for it,
with few exceptions, was left behind him. The ten years between
1830 and 1840 saw its creation. In this relatively brief period all the
works we have mentioned, except the concerto, were composed.
They were the flower of his early manhood, and they bear witness in
every page to the romantic eagerness and fire of youth. In many a
measure they show a lack of skill, an excess of zeal, an over-
reaching that is awkward; but what are these in the fire of his poetic
imagination? The spirit of Schumann rises far, far above them, one
of the most ardent, soaring spirits that ever sought expression in
music. It was destined to fall back, ruined, charred, and blackened
by its own fire; but happily we have left to us in pianoforte music its
song at the height of its flight.

IV
The only worthy successor to Schumann in the realm of German
pianoforte music is Johannes Brahms. Into the hands of Brahms
Schumann may be said to have given over the standard which he

You might also like