Skip to main content

Posts

Builder Design Pattern

Introduction We will split our discussion into three sections - where to use this design pattern, how to use this design pattern and what is this design pattern. I will discuss what is builder design pattern at the end because the definition of any design pattern will not make sense until you know how and where to use it. In order to discuss where to use builder design pattern, we need to start with the problem statement. Problem Statement (Where to use builder design pattern): Create a class to store the following details of a customer in the database:      private String firstName; //required      private String lastName; //required      private String phone; //optional      private String shippingAddress; //optional      private String billingAddress; //optional public class User { private String firstName ; //required private String lastName ; //required private String phone ; //optional private String shippingAddress ; //optional
Recent posts

Types of Design Patterns

Types of Design Patterns Creational Pattern: This design pattern covers the different ways to create an object. We will discuss all of them in the later posts of this blog: Builder Abstract Factory Factory Method Object Pool Prototype Singleton Structural Pattern: Once an object is created, the next job is to create a relationship between the different objects and it can be done using a structural design pattern. The different types of structural design patterns that we will discuss in the future posts are: Adapter Aggregate Bridge Composite Decorator Extensibility Facade FlyWeight Marker Pipes and Filter Opaque Pointer Proxy Behavioral Pattern: In the last two patterns, we have created an object and established a relationship between different objects. Now, we need to figure out ways to communicate with the different objects. Behavioral design pattern helps us in channelizing the communication between the newly created objects. The different type

Design Pattern in Java

Why Design Pattern In 1994, four authors Erich Gamma, Richard Helm, Ralph Johnson und John Vlissides published a book titled Design Patterns - Elements of Reusable Object-Oriented Software which initiated the concept of Design Pattern in Software development. The idea was to compile a list of common design patterns which can be used by programmers while designing the complex software. All the design patterns in this book are based on the two principles: • Program to an interface, not an implementation. • Favor object composition over inheritance. Let's discuss these two principles in detail. Program to an interface, not an implementation: This principle means that when we create an object, we should create an object for the interface and not the implementation. Example: ArrayList myList = new ArrayList(); //Bad List myList = new ArrayList(); //Good List myList = new TreeList(); // Good In this example, the first declaration i