Knowledge of Object oriented design principle and various design pattern is must for any Java developer. As I said earlier on 10 OOPS and SOLID design principles, coding without knowing these principles are like trying to learn language without knowing alphabets. By the way there are several books written on Object oriented design principles, design patterns and best practices, but only few of them provides what they claim. There are two things here, design principles and design patterns, one is basic and other is best practice built on that basic. One should first learn Object oriented principles and then learn design pattern to see how those principles are used to solve day to day problems. Keeping this in mind, I have collected following list of 5 books to learn Object oriented basics and design patterns in Java. These books are ordered from a beginners to advanced perspective. J2EE design patterns are little different than core Java design patterns but equally important for a Java developer, core J2EE patterns books is a good choice to learn that.
This was the first book, I read on head first series and design pattern as well, prior to that I have no idea, when to use abstract class or interface or Why composition is better than Inheritance. I usually code each feature and requirement as they come and end of doing more changes, more testing and introducing more bugs in first few years of software development. Thanks to my appetite of learning and reading, I discovered Head First design pattern and after reading it's first chapter, I was thrilled. Now I can say that was basics but it's easier to get to know about advance stuff than basics, and there, this books scores. It's a must read book on Object oriented design patterns for any Java developer, including experienced and senior developers. I would even suggest to start learning design pattern from this book. It not only explains concepts in clear way, but also gives lots of diagram, exercise, quizzes and real life examples to make you think and learn. I am a big fan of head first books, be it Head First Java or this book. Head first design patterns is great example of active learning and anyone who wants' to know about Object oriented basics like Inheritance, Encapsulation, Polymorphism and Abstraction, must read this book. There chapter on Decorator design pattern and Observer design pattern is also great piece of work.
Top 5 books on Java design patterns
Here is my list of books to learn object oriented and Java design patterns. Design patterns are tried and tested way to solve a problem in a context. These patterns are discovered while solving similar problems multiple times over the year and they address some of the most common task in object oriented application development e.g. creating object, structuring code, dynamic behavior based on context and object etc. Following five books are great resource to learn Java design patterns, which is equally applicable to any other object-oriented programming language. If you know any other book on design patterns, which is worth reading, then please share with us.
Head First Design Patterns by Elisabeth Freeman, Eric Freeman, Bert Bates, Kathy Sierra, Elisabeth Robson
Design Patterns: Elements of Reusable Object-Oriented Software by Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides
This is the classic Gang of Four (GOF) design pattern book, which became source and motivation for many object oriented design pattern books written and published so far. Any list of must read books on design patterns in Java is incomplete, without including this book. After almost 20 years, this book is still relevant on Object oriented and Java design patterns. This book has a case study chapter on designing Document Editor and then explains various design patterns e.g. Creational patterns, Structural and Behavioral patterns. IMHO, this is one of the best book in design pattern and must read for any Java developer, along with Java concurrency in Practice and Effective Java. You can buy this book from amazon, it’s available as both hardcover, paperback edition and as multimedia CD.
Design Patterns Explained: A New Perspective on Object-Oriented Design (2nd Edition) by Alan Shalloway, James R. Trott
Like multithreading and concurrency, design patterns are also not easy to understand. What is most difficult part is understanding enough to identify real world scenarios, where you can apply these design patterns. That's why sometime it's better to use multiple books to learn design patterns in Java, it's worth doing it. Main reason for that is, different style of writing and explaining stuffs. Some programmer find a particular author more readable than others, I guess only exception is Joshua Bloch which really connects to most of Java developer. Design Patterns Explained: A New Perspective on Object-Oriented Design, is that alternate way of learning Object oriented design pattern. Though it also explains same set of OOPS principles, UML and design patterns like decorator, factory or observer, the way it explains may be easier to understand for many beginners. Examples given this design pattern books is also good and non trivial.
Software Architecture Design Patterns in Java by Partha Kuchana
This is a another good book on Object oriented and Java design patterns, it not only covers basic Object-oriented principles like Class, Object, Inheritance, Polymorphism, Abstraction and Encapsulation, but also covers details which is quite practical but not obvious e.g. private methods, getter and setters, Immutable objects, interface and monitor. This book also provide extensive and comprehensive coverage of whole lot of design patterns e.g. Creational patterns, Collection patterns, Structural patterns, Behavioral patterns, and Concurrency patterns. It's coverage on Factory design pattern and Singleton pattern is really interesting to read. Another thing, which I like in this book is practice questions and UML diagrams, which not only helps to understand topic well but also ensures that you practice application part, which is most important to learn any design pattern. Finally they have a case study of designing software solution for a web hosting company, which gives you a real chance of identifying and applying design patterns in a real world scenario. In short, Software Architecture Design Patterns in Java has almost everything you need to know about Java design patterns.
Core J2EE Patterns: Best Practices and Design Strategies (2nd Edition) by Deepak Alur, Dan Malks, and John Crupi
J2EE platform is most popular way of using Java programming language, and since it's mainly focus on web and enterprise solution, it has it's own set of problems and requirements. Core J2EE patterns explains some of the most useful design patterns from J2EE world e.g. Intercepting Filters, Front Controller, Model View Controller or MVC pattern, Data Access Object or DAO pattern, View Helper or View Resolver pattern, Service Locator patterns etc. This book divides design pattern based upon there functional area e.g. Presentation tier design patterns, business tier design pattern etc. This is a must read book for any Java J2EE developer, who is responsible for coding web application and enterprise application. Though modern day framework like Spring, ensures you follow these J2EE design pattern at framework level e.g. MVC is enforced by Spring MVC, similarly it also uses Front Controller in form of DispatcherServlet and ViewResolver. Spring framework, also let you use dependency Injection and IOC at container level. Having said that, whether you use Spring MVC, Struts or any other web framework, knowledge of these J2EE patterns will help you to understand legacy code as well as to create solution which is easier to maintain.
Apart from these 5 books you can also look on Effective Java 2nd Edition by Joshua Bloch and Head first object oriented analysis and design for getting some good idea about object oriented design principles and how it has used in Java. Effective Java is must read for any Java programmer, as it explained lot of practical design advices used in Java library itself.