From the course: Java Design Patterns: Creational

What is a design pattern? - Java Tutorial

From the course: Java Design Patterns: Creational

Start my 1-month free trial

What is a design pattern?

- [Instructor] A design pattern is a way of structuring code to solve a specific problem. The aim is always to make use of solutions to common problems and make code more elegant and flexible. Design patterns do not require knowledge of any complex or obscure code to be able to use them. But knowing how to use the right design pattern in the right situation will make you a much better programmer. Often, using a design pattern will make the code simpler, shorter, and more elegant, by allowing it to be reused in other places. The concept of design patterns originally came from a book co-written by four different authors. The book is called Design Patterns: Elements of Reusable Object-Oriented Software. The authors of the book are four computer scientists called Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides. They are often referred to as the Gang of Four, and the book is often credited with being a milestone in how software is written. One of the key advantages of using design patterns is that they are a way of reusing other people's knowledge. Instead of starting from scratch to try and find the best way to solve a problem, a good solution can be used and repeated to solve the same problem again and again. Imagine someone who wants to cook a lasagna. They don't have to come up with the method of making it themselves, they can follow a recipe instead and use the knowledge of someone who has previously made a lasagna and come up with a better way to do it. Similarly, in programming, solutions to problems that have already been solved by others can be used to save time. Design patterns are not specific to a certain type of application, they can be used in programs that do a wide range of different things. It does not matter if the application is to pass documents or a gaming application. What the program actually does is not important. Design patterns can and should be used in all different kinds of applications. Going back to the lasagna analogy, a cookbook doesn't provide you with an actual lasagna, it just gives guidelines on how to make one. Similarly, a design pattern does not give you any actual code to use. It is just a guideline or template on how to solve a commonly-occurring problem. Learning design patterns are an important part of learning to write Java programs and are also very useful in refactoring existing code. The ability to make use of existing design patterns to solve common problems will make you a faster and better Java programmer.

Contents