From the course: Java EE: Design Patterns and Architecture

Classic GOF software design patterns

From the course: Java EE: Design Patterns and Architecture

Start my 1-month free trial

Classic GOF software design patterns

- [Instructor] Design patterns are solutions to problems already solved. They represent the collective wisdom of developers and providers with a common vocabulary. For example, you can talk about your application by mentioning the singleton, factory, memento, or any other design pattern with developers of another language, and they will understand exactly what you're trying to communicate even though they don't know the language that your application has been developed in. Design Patterns offer solutions to common application design problems. In object-orientated programming, design patterns are normally targeted at solving the problems associated with object creation and interaction rather than the large scale problems faced by overall software architecture. Those problems are solved by enterprise patterns which resolve those types of issues. Later on in this course, I'll be introducing some of the most commonly used enterprise patterns. Design patterns have been an essential tool in the programmer's toolbox ever since the Gang of Four wrote their seminal book Design Patterns: Elements of Reusable Object-Orientated Software, giving developers around the world tried and tested solutions to the commonest software development problems. This book describes 23 design patterns divided into three categories: creational, structural, and behavioral. Design patterns offer a common dictionary between developers. They can use them to communicate in a much simpler way without having to reinvent the wheel for every problem. Imagine you want to demonstrate how you're planning to add dynamic behavior at run time. No more step-by-step drawings or misunderstandings. It's plain and simple. You just utter a few words. Let's use the decorator pattern to address this problem. You're friend will know what you're talking about immediately. No further explanation needed. If you already know what a pattern is and use it in the right context, you're well on your way to developing a durable and maintainable application. However, design patterns are not a magic wand. They're not a silver bullet that fixes all ills. Using design patterns unnecessarily just because you can is likely to result in an accidentally complex and overly engineered system that introduces bugs, inefficient design, low performance, and maintenance issues. Most patterns can solve problems in design, provide reliable solutions to known problems, and allow developers to communicate in a common idiom across languages. Patterns really should only be used when problems are likely to occur. The GOF design patterns are classified into three groups. Creational patterns: these are patterns that control object creation, initialization, and class selection. Behavioral patterns: these are patterns that control communication, messaging, and interaction between objects. Structural patterns: these are patterns that organize relationships between classes and objects, providing guidelines for combining and using related objects together to achieve desired behaviors. The entire range of design patterns described by the Gang of Four are shown here on the screen under their classifications. There are five design patterns that fall under the creational category, and they are Abstract Factory, Builder, Factory Method, Prototype, and Singleton. In this course, we'll explore the unique way that Java E allows you to implement the singleton pattern and the additional features you can add to it. Seven design patterns fall under the structural category. They are Adapter, Bridge, Composite, Decorator, Facade, Flyweight, and Proxy. We'll be exploring the decorator and how Java E makes it really easy to implement this pattern in your application and the Facade pattern which is given a large range of features thanks to the EJB container. Lastly is the behavioral category which consists of eleven patterns. They are Command, Visitor, Interpreter, Observer, Iterator, Strategy, Mediator, State, Memento, Chain of Responsibility, and Template Method. From this list, we'll explore the observer pattern which has been given asynchronous capabilities in Java EE 8.

Contents