Gia Bao TSC

Design Pattern for Dummies - About the Author

Steve Holzner is the award-winning author of 100 books on computing. He’s a former contributing editor for PC Magazine, and has been on the faculty of Cornell University and MIT.

 Design Pattern for Dummies  posted at March 24, 2021

About The Author

In addition to his busy writing schedule, he gives programming classes to corporate programmers around the country and runs his own training company, which you can find at http://www.onsiteglobal.com/.

Design Patterns for Dummies

 

Author’s Acknowledgments

The book you hold in your hands is the result of many peoples’ work. I would particularly like to thank Mark Enochs, editor extraordinaire, and Katie Feltman, my acquisitions editor, who helped get this book off the ground and keep it in flight the rest of the way.

Thanks also to my copy editor, Heidi Unger, for dotting the I’s and crossing the T’s.

Introduction

If you’re ever writing code and get the funny feeling that you’ve solved the problem you’re working on before, you probably have. You may well have come across the same type of situation in the past, puzzled about it, and come up with the solution. And before that, you may have faced the same type of situation and come up with the same type of solution. And even before that . . . same thing.

Why keep reinventing the wheel? Why not just write down your solution and refer back to it as needed? That’s what design patterns are all about. A design pattern represents a solution to a problem or class of problems that you can put to work at once in your own code.

In fact, design patterns go one step further — they also let you share in the solutions found by other programmers, and expert programmers at that. The design patterns you see in this book represent insightful solutions to dilemmas that just about every programmer comes up against sooner or later, and knowing them is going to save you a lot of time and effort.

Got a problem? Most likely, there’s a design pattern for that. All you need to know is that someone has already solved your problem for you, with a careful eye towards good programming practices and efficiency. And all you have to do is apply that solution to your own code. Once you know how, there’s nothing to it.

The design patterns covered in this book are essential for any programmer to know — and certainly for any professional programmer. There’s a lot of ad hoc programming that goes on in the world, and that can lead to a lot of errors in critical code. Why be the one sitting in front of the debugger all day? Put design patterns to work for you and just slip the solution into place.

About This Book

There are plenty of design patterns floating around the programming world, and in time, a particular set of 23 of them has become accepted as the standard set. These patterns were first corralled in a book named Design Patterns: Elements of Reusable Object-Oriented Software (1995, Pearson Education, Inc. Publishing as Pearson Addison Wesley) by Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides — who have since been called the Gang of Four, or GoF, for short. And those 23 design patterns became known as the GoF design patterns.

You see all 23 of those standard patterns in this book, and some additional ones as well. I explain what each pattern does and when you should use the pattern. You also see a programming problem that the design pattern solves, implemented in code. In other words, every design pattern is put to work in easily understandable, runable code in this book.

In fact, some of the design patterns have already been put to work by the people who wrote the Java programming language. In such cases, I also discuss the part of Java that implements the design pattern already — such as closing windows in Swing or registering listeners with event-causing objects. Doing so gives you an immediate leg up with the design patterns covered — hey, you might find yourself saying: That looks familiar.

Foolish Assumptions

To fully understand how each pattern can make your life easier, you need to see it at work in a program, and this book uses the most widely used objectoriented programming language (Java) for its examples. For that reason, I assume you know Java.

You don’t need to be a Java expert, though. If you can put together a program and work with objects, you’ll be okay. You don’t need to be a Java meister; the programming isn’t super-challenging. The idea is to show each pattern at work with the easy-to-understand examples.

Besides Java, there’s no special knowledge or skill needed to read this book. You don’t have to know what patterns are or how they’re put to work. All that’s coming up in this book, from the most simple to the most powerful.

Conventions Used in This Book

Some books have a dozen dizzying conventions that you need to know before you can even start. Not this one. All you need to know is that new terms are shown in italics, like this, the first time they’re discussed. And when new lines of code are introduced, they’re displayed in bold, like this:


JButton button = new JButton(“Check Spelling”);
JTextField text = new JTextField(30);

public void init() {

	Container contentPane = getContentPane();
	contentPane.setLayout(new FlowLayout());
		
        . . .

	button.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent event) {
			text.setText(“Good job.”);

	        }
        });
}

Note, also, that three vertical dots represent code that’s been omitted. That’s all there is to the notation in this book. When I refer to something from the code, such as the name of an object or class, I set it off using a monofont typeface like this: Call the draw method.

How This Book Is Organized  

Part I: Getting to Know Patterns

Part I introduces patterns and how they make life easier. Chapter 1, “Congratulations, Your Problem Has Already Been Solved,” shows how patterns fit into the scheme of things and how this book is going to make your programming problems easier to solve (no kidding). In the chapters that follow, you’re introduced to the Strategy, Factory, Observer, and Singleton patterns, and more as you get to know patterns and how to work with them.

Part II: Becoming an OOP Master

Patterns rely heavily on object-oriented programming (OOP), and in this part, you see how patterns let you take charge of object-oriented work. I show you how to redefine steps of algorithms using subclasses with the Template Method pattern, how to convert an object’s interface into a totally different interface with the Adapter pattern, how to handle object collections with the Iterator and Composite patterns, how to coordinate objects with the Command and Mediator patterns, and a great deal more in this part. After you read this part, you’ll be an accomplished OOP meister.

Part III: The Part of Tens

Chapter 11 tells you about the remainder of the standard patterns, some of which are not in common use anymore, but all of which we cover in this book. Besides those standard patterns, you also see some newer patterns that have been added to the standard set of patterns, bringing us up to the modern day. Chapter 12 is all about joining the worldwide patterns community by creating your own pattern. You’re going to see how to abstract a pattern from a set of problem solutions in this chapter and what it takes to introduce your new pattern to the world.

Where to Go from Here

Alright, you’re all set and ready to jump into Chapter 1. You don’t have to start there; you can jump in anywhere you like — the book is written to allow you to do just that. But if you want to get the full patterns story from the beginning, jump into Chapter 1 first — that’s where all the action starts. Also, for your convenience, all the code I provide in the book is available for downloading at www.dummies.com/go/designpatternsfd1e.  

Thanks Steve Holzner - Author of Design Patterns for Dummies Book.


Comments