Java Design Patterns
How you can get Java design patterns to do exactly what you want and accelerate your software career in less than 1 week
" First of all, best wishes for this new year ! I just wanted to tell you that I have completed the Java Design Patterns Course, it was very interesting the examples were very clear and the books recommendation was awesome, I was following the course with some of the books you mentioned that I already have and I put a couple of your recommendations on my Amazon wish list."
Like so many programmers of my generation, I started coding in BASIC. After a short foray into Turbo Pascal, my university led me gently to C.
Professor MacGregor then introduced C++. His lectures were ramblings in a thick Glasgow accent with matching handwriting. Stroustrup's writing became my bible.
All through my university education, I struggled to rid myself of the bad habits endowed by years of BASIC and C. Polymorphism? No, I used switch statements and multi-conditional ifs.
I was insanely productive through the generous application of CTRL+C and CTRL+V. Part of my masters was an editor for SDL, used for network protocols. My professor and I sold this to a company in France. They visited us at the University of Cape Town and liked my program. To make it perfect, they wanted a few changes. It only took me a few hours to finish everything they wanted.
IT WAS ONLY WHEN I STARTED WORKING THAT I DISCOVERED THAT EVERYTHING I HAD LEARNED ABOUT OBJECT-ORIENTATION WAS WRONG
I had used the same coding techniques from C and BASIC in my C++ code. The result were lots of switch statements distributed throughout my codebase. Whenever I had to add a new design element, I would have to find and change each switch statement in turn. If I forgot one, which happened a lot, then one feature would not work anymore. For example, if I didn't change the switch for printing, then my new element would show on the screen, but not in the printout. Each time I added one element, I had to test each function in turn to make sure everything worked.
This type of coding behaviour might be ok when you're the only one working on that code. But it doesn't make for happy team mates.
At my first real job, my mentor handed me the GoF book and said: "Here, you have to read this."
I did. Most of the patterns seemed somewhat familiar from my years of coding C++. I put it aside. What could I possibly learn?
A year later I heard Martin Fowler at a conference in Cape Town. He described "Design Patterns" as the most significant software development book of the decade.
I picked it up for a second read. Perhaps I had missed something? It all seemed obvious the first time.
I DID NOT UNDERSTAND A WORD ON THE SECOND READ
How was it possible that a year of coding experience had made me so stupid? Surely real-world coding should have the opposite effect, making me more valuable as a programmer?
Indeed, it had. But the first time I read the book, I did not have enough insight to understand its true value. Martin Fowler's words had made me pick up the book for a second time that I had discarded as "completely obvious".
"If one has to choose to take a single design patterns course it should be Java Design Patterns by Heinz Kabutz. I can't recommend it enough.The class is very well organized and covers 30 design patterns. What sets it apart is how well each pattern is explained and the coverage of several less known design patterns like Memento, Essence, Object Recursion, Acyclic Visitor. Heinz spends enough time to give details how each pattern originated and its main usages. Currently its 5 edition the course covers the material in great depth, but at he same time doesn't spend more time that necessary on each pattern. What I find very useful are the comments about common pitfalls to avoid and ways to extend and improve the implementation of these design patterns using latest language features of Java 8,9 and 10. A personal favorite of mine are the exercises that follow each design pattern allowing the student to put to practice what she learned. And if you complete all the exercises and send them to Heinz he will issue you a course completion certificate."
I struggled through each pattern, trying to think of places where I had seen it in our Java project. We even formed a design pattern study group that met every Friday lunch. I still remember the Visitor pattern described by my colleague Martin Booyens. He spoke about the dominee (Afrikaans for parson) visiting. Whilst I remember his analogy twenty years later, I was complete befuddled by his explanation of this rather simple pattern. Having lay people teach the patterns did not work as well as we had hoped.
TEACHING DESIGN PATTERNS IS HARD - MANY ONLINE PATTERNS COURSES HAVE SERIOUS ERRORS THAT WILL HURT YOU
During my third read through GoF, I finally had the Eureka! moment. Every pattern used polymorphism. Even the Singleton. This was the key concept used everywhere. Furthermore, most of the pattern used a combination of inheritance and composition. When in doubt, we used composition.
If only I had known all this during my university days, I could have avoided all those nasty switch statements.
I immersed myself in patterns, determined to understand the various nuances of each design. I bought books, read papers, reached out to one of the authors of the original GoF book - John Vlissides. I even did a technical review on some papers he authored for IBM (Composite1 and Composite2). I studied the writing of Christopher Alexander, famous architect whose pattern language the software community cloned. After months of preparation, I was ready to teach my first Java design patterns course.
BOOKS REFERENCED IN THIS COURSE
There are others. I own about 30 books on patterns. I read them so that you don't have to. But these are the most important. Especially Pattern Hatching. If you buy any one book, get that one.
SOMETHING INTERESTING HAPPENED
Something interesting happened. I would teach a small class at a company. A few months later, I would get an order for a much larger course. This often carried on until the entire development staff had gone through the course.
Why was this? Why did companies want everyone to learn this?
Ordinary Java courses and university curricula focus on the syntax of the language, but are sparse on the semantics. If they are lucky, students will learn that there are three different types of patterns: creational, behavioral and structural. But they won't see the practical applications of where patterns are used.
In my Java Design Patterns Course, I show where each of the patterns is used in the Java Development Kit. This makes our course immensely practical. The patterns are not just some abstract concepts. They are presented from the coal face of timeless software.
DESIGN PATTERNS ARE RELEVANT TODAY
Through its 18 year history, and with countless revisions, our Design Patterns Course has remained relevant and useful. The patterns of Iterator, Composite and Strategy are as important with Java 11 as they were with Java 1.1. As in the 90s, patterns still make programmers more productive and able to communicate better.
Java 8 added lambdas and method references to the language. This makes some patterns such as Command easier to use. Default methods in interfaces means we are not always force d to use abstract classes.
"Some of the exercises I managed to do alone.. and some not.. but those which I "copied" I tried to understood by going through code, debug it.. and of course I watched the walkthroughs after that.
It's a great course, I will go through it again without too many breaks. Lots of patterns are covered, I like how it is explained and in combination with exercises containing good examples and use cases this is a great stuff..
And not to forget you as instructor, I like the spontaneous way in which you teach and share your obviously big amount of the knowledge.. Overall great course worth the money!"
Get started now!
"The course has a lot of code examples to better understand the various design patterns.What I've learned: capturing/non-capturing lambdas, use only ConcurrentHashMap since Java 8, performance considerations, etc. The difficulty of the course is exactly right: difficult code samples and patterns are explained in more detail. What I also liked: Solution walkthroughs of the exercises with live coding. Sometimes Heinz came up with better solutions than he had in his model answers.He answers all questions very carefully."
- Anonymous, Feedback from an in-house course presented in Graz, Austria
No one likes forward references in books or courses. "Don't worry about this, we will do it in a later chapter" tends to distract us. We try to have as few of these as possible.
We start with an extensive introduction to Java on modern virtual machines. A lot of the concerns in the original Gang-of-Four book stem from when we only had static compilation. Java can optimize our code on-the-fly. The JIT compiler can even inline polymorphic method calls, if it can determine that it is safe. If later on another type of subclass appears, it will undo that optimization. Indirection costs are also inlined. Too many objects? No worries, the garbage collector does a splendid job of managing these.
One of the starting precepts is that of meronomy. This defines what we mean by "part-whole hierarchy". The reason we care about meronomy is because we need to avoid memory leaks in our designs. Memory leaks should be a thing of the past with Java's automatic memory management. Unfortunately they still happen when we ignore meronomy.
Another important concept is intrinsic versus extrinsic state. It occurs in lots of the patterns. We can usually rewrite the implementations to move from one to the other. Neither is good or bad, but extrinsic usually allows us to share objects. Intrinsic is a bit more object-orientated.
THE GOLDEN ORDER
After our detailed introduction, we start with simple patterns that occur everywhere. Patterns like Strategy, Iterator, Proxy and Abstract Class.
Most courses and books starts with the creational patterns Singleton and Factory Method. The thinking is that these are very simple patterns. They are not. Singleton has a lot of subtleties. The pattern allows polymorphism and multiple instances of the "Singleton". Lazy vs eager initialization? Most courses get this wrong, with code that can break in production.
The patterns are sourced from both the original Gang-of-Four book by Erich Gamma et al, in addition to proceedings from the Pattern Language of Program Design conferences. They are categorized into behavioral (B), structural (S) and creational (C) patterns. Here is the golden order that we follow through this maze of patterns:
Abstract Class (B), Builder (C), Essence (C), Memento (B), Proxy (S), Flyweight (S), Strategy (B), Null Object (B), Iterator (B), Factory Method (C), Template Method (B), Composite (S), Visitor (B), Acyclic Visitor (B), Object Recursion (B), Default Visitor (B), Adapter (S), Command (B), Decorator (S), Extension Object (S), Singleton (C), State (B), Facade (S), Prototype (C), Abstract Factory (C), Interpreter (B), Mediator (B), Observer (B), Bridge (S), Chain of Responsibility (B)
EXERCISES, EXERCISES, EXERCISES, EXERCISES, EXERCISES
We learn more by doing than by listening. Every pattern is followed by exercises that we solve to improve our understanding of the pattern. For each exercise we have model solutions and a detailed walkthrough, where I show you the thought process in solving the exercise. Some of the exercises are hard. Others easier.
We have different types of exercises for the patterns:
COURSE COMPLETION CERTIFICATE
So your employer bought this nice shiny course for you. How can you prove to them that you have finished it?
Teachable tracks your progress through the course. At the end of each section, you can mark it as "completed". Once you have finished at least 88% of the course, you can qualify for a course completion certificate. To claim this, you can submit your completed exercises to Heinz Kabutz for marking. The certificate and marking cost are included in your course price.
UNHAPPY? GRAB A 100% REFUND WITHIN 30 DAYS!
We believe that this is the best value-for-money course in the Java world. It is useful for all levels of Java knowledge: beginner, intermediate and advanced. Everyone will learn something that will help them become better Java programmers.
To put our money where our mouth is, we are offering a 100% money-back guarantee within 30 days of purchasing the course. No questions asked. Simply let us know that this training wasn't for you and we will refund you.
Course Curriculum
-
Start1.1. Lay of the Land (8:40)
-
Preview1.2. Why Learn Patterns (15:35)
-
Preview1.3. What is a Design Pattern (6:01)
-
Start1.4. References Used in Course (7:46)
-
Preview1.5. Unified Modeling Language (UML) (14:02)
-
Start1.6. Java Memory Management (11:41)
-
Start1.7. Java HotSpot Optimizations (6:53)
-
Start1.8. Modern Java Syntax (3:56)
-
Start2. Abstract Class Pattern (PLoPD4) (15:35)
-
Start2.1. Abstract Class Pattern Exercise Walkthrough (15:52)
-
Start3. Builder Pattern (GoF and Effective Java) (19:43)
-
Start3.1. Builder Exercise 1 Walkthrough (6:46)
-
Start3.2. Builder Exercise 2 Walkthrough (2:15)
-
Start4. Essence Pattern (PLoPD4) (10:39)
-
Preview5. Memento Pattern (GoF) (22:15)
-
Start5.1. Memento Pattern Exercise 1 Walkthrough (10:59)
-
Start5.2. Memento Pattern Exercise 2 Walkthrough (3:07)
-
Start6. Proxy Pattern (GoF) (32:18)
-
Start6.1. Proxy Pattern Exercise 1 Walkthrough (3:47)
-
Start6.2. Proxy Pattern Exercise 2 Walkthrough (7:22)
-
Start7. Flyweight Pattern (GoF) (51:37)
-
Start8. Strategy Pattern (GoF) (33:34)
-
Start8.1. Strategy Exercise 1 Walkthrough (15:02)
-
Start8.2. Strategy Exercise 2 Walkthrough (9:03)
-
Start9. Null Object Pattern (PLoPD3) (16:56)
-
Start9.1. Null Object Exercise Walkthrough (12:11)
-
Start10. Iterator Pattern (GoF) (27:31)
-
Start10.1. Iterator Pattern Exercise Walkthrough (9:44)
-
Start11. Factory Method (GoF and Refactoring) (27:40)
-
Start12. Template Method Pattern (GoF) (11:15)
-
Start12.1. Template Method exercise (8:17)
-
Start13. Composite Pattern (GoF) (12:33)
-
Start13.1. Composite Exercise Walkthrough (17:20)
-
Start14. Visitor Pattern (GoF) (17:28)
-
Start14.1. Visitor Exercise Walkthrough (8:06)
-
Start15. Acyclic Visitor Pattern (PLoPD3) (12:52)
-
Start15.1. Acyclic Visitor Exercise Walkthrough (5:01)
-
Start16. Object Recursion Pattern (PLoPD4) (9:04)
-
Start17. Default Visitor Pattern (PLoPD3) (19:47)
-
Start17.1. Default Visitor Exercise Walkthrough (12:52)
-
Start18. Adapter Pattern (GoF) (21:54)
-
Start18.1. Adapter Exercise Walkthrough (12:19)
-
Start19. Command Pattern (GoF) (14:24)
-
Start19.1. Command Exercise 1 Walkthrough (5:31)
-
Start19.2. Command Exercise 2 Walkthrough (2:10)
-
Start20. Decorator Pattern (GoF) (28:54)
-
Start20.1. Decorator Exercise Walkthrough (11:31)
-
Start21. Extension Object Pattern (34:09)
-
Start22. Singleton Pattern (GoF) (40:50)
-
Start22.1. Singleton Exercise 1 Walkthrough (0:58)
-
Start22.2. Singleton Exercise 2 Walkthrough (1:33)
-
Start22.3. Singleton Exercise 3 Walkthrough (14:21)
-
Start23. State Pattern (GoF) (24:47)
-
Start23..1. State Exercise Walkthrough (20:27)
-
Start24. Facade Pattern (GoF) (11:15)
-
Start24.b. Session Facade Pattern (JEE) (3:41)
-
Start25. Prototype (17:11)
-
Start26. Abstract Factory Pattern (GoF) (10:29)
-
Start26.1. Abstract Factory Exercise Walkthrough (5:14)
-
Start27. Interpreter Pattern (GoF) (16:20)
-
Start27.1. Interpreter Exercise Walkthrough (11:34)
-
Start28. Mediator Pattern (GoF) (13:03)
-
Start29. Observer Pattern (GoF) (28:13)
-
Start29.1. Observer Exercise Walkthrough (8:20)
-
Start30. Bridge Pattern (GoF) (13:44)
-
Start30.1. Bridge Exercise Walkthrough (10:07)
-
Start31. Chain of Responsibility Pattern (GoF) (10:35)
-
Start31.1. Chain of Responsibility Exercise Walkthrough (13:04)
-
Start32. Conclusion (9:44)
"Revision of patterns I knew before, and learning of new patterns. Learning new Java features in the exercises. Best practices, like using ConcurrentHashMap. Learned useful new IntelliJ shortcuts. Live coding sessions by Heinz."
- Anonymous, Feedback from an in-house course presented in Graz, Austria
Get started now!
"Pattern advantages / disadvantages in contrast with later Java versions (lots of small objects are not so expensive now...) Exercises were fun. Example unit test gave good direction towards solutions. Liked the structure checking tests."
- Anonymous, Feedback from an in-house course presented in Graz, Austria
Your Instructor
Heinz Kabutz is the author of The Java Specialists’ Newsletter, a publication enjoyed by tens of thousands of Java experts in over 150 countries. He has been a Java Champion since 2005.