
Explore creational design patterns in Java by hiding object instantiation from the new keyword and mastering patterns such as builder, telescoping constructor, singleton, factory, abstract factory, prototype, and interface-based design.
Identify prerequisites for this course: install a JDK from Oracle or OpenJDK and set up Eclipse IDE or another IDE. Build basic core Java knowledge and hands-on experience before sessions.
Learn how the builder design pattern reduces complex constructors by enabling readable, stepwise object creation with optional fields, illustrated by a bedroom example.
Explore why telescoping constructors create boilerplate and maintenance challenges, compare them with the builder pattern, and learn when to use a required x constructor versus a true builder.
Learn how to implement a builder inside a builder in Java, demonstrated with a bedroom and TV example to illustrate nested builders, the telescoping approach, and constructing complex objects.
Explore telescoping constructor and builder patterns, including a builder inside a builder, and learn how mixing these patterns avoids refactoring when adding a TV.
Identify when to apply the singleton pattern in Java by ensuring a single instance is created and accessible across the application, with examples like database connectors, logging, and system classes.
Implement the singleton pattern in Java by using a private constructor, a static getInstance method, and a static reference to ensure only one printer object is created.
Explore how a singleton fails under multithreading and how to fix it by synchronizing the getInstance method, ensuring a single instance and thread-safe initialization.
Compare lazy and eager instantiation in the singleton pattern, noting lazy creates the instance on first use while eager initializes at class load, with thread-safety considerations and synchronization.
Explore how reflection can break the singleton pattern by accessing private constructors, and discover how a singleton enum offers a robust, reflection- and serialization-safe alternative.
Explore how cloning can break the singleton pattern in Java, demonstrate unsafe cloning, and prevent it by overriding clone to throw a clone not supported exception.
Explain how the singleton pattern ensures a single instance and contrasts eager versus lazy creation, while noting fixes for serialization, cloning, and reflection with enum-based safety.
Explore the prototype pattern in Java, focusing on the cloning process to create exact object copies. Learn how shallow copy enables efficient duplication versus recreating objects.
Demonstrates mutability in cloning a complex object with a transmission type, which can be automatic or manual, and shows how cloneable deep cloning keeps original and clone independent.
Explore shallow copy versus deep copy in Java: shallow copies primitive data, whereas deep copies clone a nested custom object to solve mutability by implementing Cloneable and overriding clone.
Demonstrates the prototype pattern by contrasting shallow and deep copies and showing how overriding clone enables creating independent copies of nested objects to solve mutability problems.
Explore how the factory pattern in Java enables flexible object creation by using a factory class to instantiate various milkshake or animal objects, letting you add new types with ease.
Implement the factory design pattern with a factory class that creates different milkshake types like chocolate, strawberry, and butterscotch, enabling flexible, dynamic object creation.
Explore how the factory pattern provides flexibility to create different kinds of objects, reducing complexity in project structure and future object creation.
Explore the abstract factory pattern as a super factory that creates other factories, illustrated with an animal factory and a human factory producing dog, cat, male, and female.
Implement the abstract factory pattern with a factory producer that yields animal and human factories, extending a common abstract factory for flexible related object creation.
Explore how the abstract factory pattern acts as a super factory creating specific factories (animal, human) through a getFactory method, all extending an abstract factory base class.
Design patterns provide a template for writing quality code. Knowing which design pattern to use in which scenario can be challenging but will make you a master Java programmer. In this course you will take a deep dive into creational patterns, which can help you create more flexible, reusable objects.
I will be covering the six most popular creational patterns— Builder, Telescoping Constructor, Singleton, Prototype, Factory and Abstract Factory as well as concepts such as multithreading, mutability, inheritance and Java Heap and Stack workings.
I will provide example use cases, complete with implementation instructions and tips for avoiding the unique challenges posed by each pattern also explain how do design patterns work inside Java Heap and Stack Memory.
By the end of this course, you'll be equipped with the knowledge and skills necessary to implement each design patterns in your Java projects.
Learning Objectives:
What are creational design patterns?
How to avoid complex constructors?
Implementing the Builder pattern
Implementing the Telescoping pattern
Understanding similarity between Builder and Telescoping pattern
Best interview answers for Singleton pattern Questions.
Also get a practical idea about the advance concepts such as serialization, cloning, multi-threading and reflection
Problem and Solution of Multi-threading with the Singleton pattern
Implementing the Prototype pattern
Best interview answers for Prototype pattern Questions.
Implementing simple Factory pattern
Implementing Abstract Factory pattern