O'Reilly logo
live online training icon Live Online training

Design Patterns in Java: Deep Dive

The Timeless Way of Coding

Topic: Software Development
Heinz Kabutz

Based on Heinz's experience covering these topics, and years of teaching, we look at the ten most common design patterns: Builder, Memento, Proxy, Strategy, Composite, Visitor and Default Visitor, Command, Decorator, State, and Chain of Responsibility. The course includes hands-on exercises that the students need to solve, together with exercise walkthroughs.

What you'll learn-and how you can apply it

  • Understand why we need to know about design patterns
  • Understand how patterns influence the Java Virtual Machine JIT compiler and garbage collectors
  • Good working knowledge of the ten most common design patterns

This training course is for you because...

  • Beginner to intermediate Java programmers wishing to become better at writing reusable code

Prerequisites

  • Should be comfortable with at least Java 8 code. Java 11+ is an advantage.

Course Set-up:

Please install the following before the class begins: - JDK 11 or later - IntelliJ 2020.2 or later - Git

Further set-up instructions will be provided at the start of the class.

Recommended Preparation:

Recommended Follow-up:

About your instructor

  • Heinz Kabutz is the author of “The Java Specialists’ Newsletter”, a publication enjoyed by tens of thousands of Java experts in over 145 countries. His book “Dynamic Proxies (in German)” was #1 Bestseller on Amazon.de in Fachbücher für Informatik for about five minutes until Amazon fixed their algorithm. Thanks to a supportive mother, he has now sold 5 copies.

    Heinz’s Java Specialists’ newsletter is filled with amusing anecdotes of life on the Island of Crete. He is a popular speaker at all the best Java conferences around the world, and also at some of the worst. He teaches Java courses in classrooms around the world, where his prime objective is to make absolutely sure that none of his students fall asleep. He is not always successful.

Schedule

The timeframes are only estimates and may vary according to how the class is progressing

Day 1

Segment 1: Welcome (20m)

  • Lay of the Land
  • Why Learn Patterns?
  • What is a Design Pattern?

Segment 2: Builder (40m including exercise)

  • Intent, Motivation, Effective Java vs GoF, polymorphic builder, known uses in the JDK
  • Exercise/activity description: Coding exercise creating a builder

Segment 3: Memento (40m including exercise)

  • Intent, Motivation, avoiding memory leaks, serialization, known uses in the JDK
  • Exercise/activity description: Two coding exercises

Segment 4: Proxy (40m including exercise)

  • Intent, Motivation, virtual proxy, dynamic proxy, known uses in the JDK
  • Exercise/activity description: Coding exercise with virtual proxy and also dynamic

Segment 5: Strategy (40m including exercise)

  • Intent, Motivation, polymorphism vs strategy, known uses in the JDK
  • Exercise/activity description: Coding exercise refactoring spaghetti code to strategy

Segment 6: Composite (40m including exercise)

  • Intent, Motivation, part-whole hierarchies, known uses in the JDK
  • Exercise/activity description: Coding exercise iterating over composite structure

Day 2

Segment 7a: Visitor (30m including exercise)

  • Intent, Motivation, annotation processing, known uses in the JDK
  • Exercise/activity description: Coding exercise adding visitor to composite structure

Segment 7b: Default Visitor (30m including exercise)

  • Intent, Motivation, comparison to GoF visitor, extensibility, known uses in the JDK
  • Exercise/activity description: Coding exercise refactoring visitor to default visitor

Segment 8: Command (40m including exercise)

  • Intent, Motivation, lambdas and method references, composite commands, known uses in the JDK
  • Exercise/activity description: Coding exercise creating actions for devices

Segment 9: Decorator (40m including exercise)

  • Intent, Motivation, object model, client view, known uses in the JDK
  • Exercise/activity description: Coding exercise mixing decorators with iterables

Segment 10: State (40m including exercise)

  • Intent, Motivation, use cases in the real world, complexity, known uses in the JDK
  • Exercise/activity description: Coding exercise creating state machine in code

Segment 11: Chain of Responsibility (40m including exercise)

  • Intent, Motivation, unmanaged requests, known uses in the JDK
  • Exercise/activity description: Coding exercise creating chain of object mappers

Segment 12: Conclusion (5m)