Monday, 7 November 2016

Creational | Builder Patterns

Creation design patterns

Where we deal with the ways to create Objects

1. Builder

Here you can create don't have to supply all the "contructor" argument, you can still create a object with single or more parameters

Like say , Object to be created has constructior like below

Book( String title, String author, String pubDate)


But we provider a
BookBuilder which will have default value for other arguments and set if passes but thr way they create Book will change.
But orginal Book class need not change

BookBuilder {

String title,author,pubDate

public BookBuilder  setTitle(String title) {

this.title = title;
return this.
}
//Similarly others setter


public getBook()
{
Book book = new Book (title,author,pubDate);
}


//User

Book book = new BookBuilder().setTitle("walla").setAuthor("Habibi").getPhone(),

//This will create Book with only two mandatory parameters