SlideShare a Scribd company logo
1 of 19
Builder Pattern
Copyright 2016. Jyaasa Technologies. All Right Reserved
h
ttp://jyaasa.com
Sagun Shrestha
Sr. Software Engineer,
Jyaasa Technologies
What is Builder Pattern?
Copyright 2016. Jyaasa Technologies. All Right Reserved
h
ttp://jyaasa.com
● The builder pattern is an object creation software
design pattern.
● It is a pattern designed to help you configure complex
objects
● It helps separate the construction of a complex object
from its representation.
● So that the same construction process can create
different representations.
Let’s suppose we are building a system that
will support computer manufacturing
business
Copyright 2016. Jyaasa Technologies. All Right Reserved
h
ttp://jyaasa.com
class Computer
attr_accessor :display
attr_accessor :motherboard
Attr_reader :drives
def initialize(display=:crt, motherboard=Motherboard.new,drives=[ ])
@motherboard = motherboard
@drives = drives
@display = display
end
end
class CPU
# Common CPU stuff...
end
class BasicCPU < CPU
# Lots of not very fast CPU-related stuff...
end
class TurboCPU < CPU
# Lots of very fast CPU stuff...
End
# Computer’s motherboard and drive
class Motherboard
attr_accessor :cpu
attr_accessor :memory_size
def initialize(cpu=BasicCPU.new, memory_size=1000)
@cpu = cpu
@memory_size = memory_size
end
end
class Drive
attr_reader :type # either :hard_disk, :cd or :dvd
attr_reader :size # in MB
attr_reader :writable # true if this drive is writable
def initialize(type, size, writable)
@type = type
@size = size
@writable = writable
end
end
# Build a fast computer with lots of memory...
motherboard = Motherboard.new(TurboCPU.new, 4000)
# ...and a hard drive, a CD writer, and a DVD
drives = [ ]
drives = << Drive.new(:hard_drive, 200000, true)
drives << Drive.new(:cd, 760, true)
drives << Drive.new(:dvd, 4700, false)
computer = Computer.new(:lcd, motherboard, drives)
class ComputerBuilder
attr_reader :computer
def initialize
@computer = Computer.new
end
def turbo(has_turbo_cpu=true)
@computer.motherboard.cpu = TurboCPU.new
end
def display=(display)
@computer.display=display
end
def memory_size=(size_in_mb)
@computer.motherboard.memory_size = size_in_mb
end
def add_cd(writer=false)
@computer.drives << Drive.new(:cd, 760, writer)
end
def add_dvd(writer=false)
@computer.drives << Drive.new(:dvd, 4000, writer)
end
def add_hard_disk(size_in_mb)
@computer.drives << Drive.new(:hard_disk, size_in_mb, true)
end
end
builder = ComputerBuilder.new
builder.turbo
builder.add_cd(true)
builder.add_dvd
builder.add_hard_disk(100000)
# new computer
computer = builder.computer
class DesktopComputer < Computer
# Lots of interesting desktop details omitted...
End
class LaptopComputer < Computer
def initialize( motherboard=Motherboard.new, drives=[] )
super(:lcd, motherboard, drives)
end
# Lots of interesting laptop details omitted...
end
class ComputerBuilder
attr_reader :computer
def turbo(has_turbo_cpu=true)
@computer.motherboard.cpu = TurboCPU.new
end
def memory_size=(size_in_mb)
@computer.motherboard.memory_size = size_in_mb
end
end
class DesktopBuilder < ComputerBuilder
def initialize
@computer = DesktopComputer.new
end
def display=(display)
@display = display
end
def add_cd(writer=false)
@computer.drives << Drive.new(:cd, 760, writer)
end
def add_dvd(writer=false)
@computer.drives << Drive.new(:dvd, 4000,
writer)
end
def add_hard_disk(size_in_mb)
@computer.drives << Drive.new(:hard_disk,
size_in_mb, true)
end
end
class LaptopBuilder < ComputerBuilder
def initialize
@computer = LaptopComputer.new
end
def display=(display)
raise "Laptop display must be lcd" unless display ==
:lcd
end
def add_cd(writer=false)
@computer.drives << LaptopDrive.new(:cd, 760,
writer)
end
def add_dvd(writer=false)
@computer.drives << LaptopDrive.new(:dvd, 4000,
writer)
end
def add_hard_disk(size_in_mb)
@computer.drives << LaptopDrive.new(:hard_disk,
size_in_mb, true)
end
end
Structure
Participants
● Builder
○ Specifies an abstract interface for creating parts of a Product object.
● ConcreteBuilder
○ Constructs and assembles parts of the product by implementing the
Builder interface.
○ Defines and keeps track of the representation it creates.
○ Provides an interface for retrieving the product
● Director
○ Constructs an object using the Builder interface.
● Product
○ Represents the complex object under construction. ConcreteBuilder
builds the product's internal representation and defines the process by
which it's assembled.
○ Includes classes that define the constituent parts, including interfaces
for assembling the parts into the final result.
Collaboration
● The client creates the Director object and configures it with the desired
Builder object.
● Director notifies the builder whenever a part of the product should be built.
● Builder handles requests from the director and adds parts to the product.
● The client retrieves the product from the builder.
def computer
raise "Not enough memory" if @computer.motherboard.memory_size < 250
raise "Too many drives" if @computer.drives.size > 4
hard_disk = @computer.drives.find {|drive| drive.type == :hard_disk}
raise "No hard disk." unless hard_disk
@computer
end
Building Sane Object
Thank you
Copyright 2016. Jyaasa Technologies. All Right Reserved
h
ttp://jyaasa.com

More Related Content

What's hot

Builder pattern vs constructor
Builder pattern vs constructorBuilder pattern vs constructor
Builder pattern vs constructorLiviu Tudor
 
Design pattern (Abstract Factory & Singleton)
Design pattern (Abstract Factory & Singleton)Design pattern (Abstract Factory & Singleton)
Design pattern (Abstract Factory & Singleton)paramisoft
 
The Art of Unit Testing - Towards a Testable Design
The Art of Unit Testing - Towards a Testable DesignThe Art of Unit Testing - Towards a Testable Design
The Art of Unit Testing - Towards a Testable DesignVictor Rentea
 
ASP.NET Routing & MVC
ASP.NET Routing & MVCASP.NET Routing & MVC
ASP.NET Routing & MVCEmad Alashi
 
Declarative UIs with Jetpack Compose
Declarative UIs with Jetpack ComposeDeclarative UIs with Jetpack Compose
Declarative UIs with Jetpack ComposeRamon Ribeiro Rabello
 
Hexagonal architecture - message-oriented software design
Hexagonal architecture  - message-oriented software designHexagonal architecture  - message-oriented software design
Hexagonal architecture - message-oriented software designMatthias Noback
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object ModelWebStackAcademy
 
Java database connectivity with MySql
Java database connectivity with MySqlJava database connectivity with MySql
Java database connectivity with MySqlDhyey Dattani
 
From framework coupled code to #microservices through #DDD /by @codelytv
From framework coupled code to #microservices through #DDD /by @codelytvFrom framework coupled code to #microservices through #DDD /by @codelytv
From framework coupled code to #microservices through #DDD /by @codelytvCodelyTV
 
Building RESTful applications using Spring MVC
Building RESTful applications using Spring MVCBuilding RESTful applications using Spring MVC
Building RESTful applications using Spring MVCIndicThreads
 
SOLID Design Principles applied in Java
SOLID Design Principles applied in JavaSOLID Design Principles applied in Java
SOLID Design Principles applied in JavaIonut Bilica
 
Factory Design Pattern
Factory Design PatternFactory Design Pattern
Factory Design PatternKanushka Gayan
 
React event
React eventReact event
React eventDucat
 
Dom(document object model)
Dom(document object model)Dom(document object model)
Dom(document object model)Partnered Health
 

What's hot (20)

SOLID principles
SOLID principlesSOLID principles
SOLID principles
 
Builder pattern vs constructor
Builder pattern vs constructorBuilder pattern vs constructor
Builder pattern vs constructor
 
Design pattern (Abstract Factory & Singleton)
Design pattern (Abstract Factory & Singleton)Design pattern (Abstract Factory & Singleton)
Design pattern (Abstract Factory & Singleton)
 
The Art of Unit Testing - Towards a Testable Design
The Art of Unit Testing - Towards a Testable DesignThe Art of Unit Testing - Towards a Testable Design
The Art of Unit Testing - Towards a Testable Design
 
ASP.NET Routing & MVC
ASP.NET Routing & MVCASP.NET Routing & MVC
ASP.NET Routing & MVC
 
Declarative UIs with Jetpack Compose
Declarative UIs with Jetpack ComposeDeclarative UIs with Jetpack Compose
Declarative UIs with Jetpack Compose
 
Hexagonal architecture - message-oriented software design
Hexagonal architecture  - message-oriented software designHexagonal architecture  - message-oriented software design
Hexagonal architecture - message-oriented software design
 
Decorator design pattern
Decorator design patternDecorator design pattern
Decorator design pattern
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object Model
 
Java database connectivity with MySql
Java database connectivity with MySqlJava database connectivity with MySql
Java database connectivity with MySql
 
Design pattern
Design patternDesign pattern
Design pattern
 
From framework coupled code to #microservices through #DDD /by @codelytv
From framework coupled code to #microservices through #DDD /by @codelytvFrom framework coupled code to #microservices through #DDD /by @codelytv
From framework coupled code to #microservices through #DDD /by @codelytv
 
Building RESTful applications using Spring MVC
Building RESTful applications using Spring MVCBuilding RESTful applications using Spring MVC
Building RESTful applications using Spring MVC
 
Factory Method Pattern
Factory Method PatternFactory Method Pattern
Factory Method Pattern
 
Flask
FlaskFlask
Flask
 
SOLID Design Principles applied in Java
SOLID Design Principles applied in JavaSOLID Design Principles applied in Java
SOLID Design Principles applied in Java
 
Factory Design Pattern
Factory Design PatternFactory Design Pattern
Factory Design Pattern
 
React event
React eventReact event
React event
 
Dom(document object model)
Dom(document object model)Dom(document object model)
Dom(document object model)
 
Clean Code
Clean CodeClean Code
Clean Code
 

Viewers also liked

Design pattern builder 20131115
Design pattern   builder 20131115Design pattern   builder 20131115
Design pattern builder 20131115LearningTech
 
Builder pattern
Builder pattern Builder pattern
Builder pattern mentallog
 
Design Patterns: Builder pattern (Le monteur)
Design Patterns: Builder pattern (Le monteur)Design Patterns: Builder pattern (Le monteur)
Design Patterns: Builder pattern (Le monteur)RadhoueneRouached
 
Desing pattern prototype-Factory Method, Prototype and Builder
Desing pattern prototype-Factory Method, Prototype and Builder Desing pattern prototype-Factory Method, Prototype and Builder
Desing pattern prototype-Factory Method, Prototype and Builder paramisoft
 
Strategy Pattern
Strategy PatternStrategy Pattern
Strategy PatternGuo Albert
 
Amazon Web Service EC2 & S3
Amazon Web Service EC2 & S3Amazon Web Service EC2 & S3
Amazon Web Service EC2 & S3Pravin Vaja
 
Generic repository pattern with ASP.NET MVC and Entity Framework
Generic repository pattern with ASP.NET MVC and Entity FrameworkGeneric repository pattern with ASP.NET MVC and Entity Framework
Generic repository pattern with ASP.NET MVC and Entity FrameworkMd. Mahedee Hasan
 
Python: Common Design Patterns
Python: Common Design PatternsPython: Common Design Patterns
Python: Common Design PatternsDamian T. Gordon
 
Strategy Design Pattern
Strategy Design PatternStrategy Design Pattern
Strategy Design PatternGanesh Kolhe
 

Viewers also liked (14)

Design pattern builder 20131115
Design pattern   builder 20131115Design pattern   builder 20131115
Design pattern builder 20131115
 
Builder pattern
Builder patternBuilder pattern
Builder pattern
 
Builder pattern
Builder pattern Builder pattern
Builder pattern
 
Design Patterns: Builder pattern (Le monteur)
Design Patterns: Builder pattern (Le monteur)Design Patterns: Builder pattern (Le monteur)
Design Patterns: Builder pattern (Le monteur)
 
Desing pattern prototype-Factory Method, Prototype and Builder
Desing pattern prototype-Factory Method, Prototype and Builder Desing pattern prototype-Factory Method, Prototype and Builder
Desing pattern prototype-Factory Method, Prototype and Builder
 
Strategy Pattern
Strategy PatternStrategy Pattern
Strategy Pattern
 
Strategy Pattern
Strategy PatternStrategy Pattern
Strategy Pattern
 
Amazon Web Service EC2 & S3
Amazon Web Service EC2 & S3Amazon Web Service EC2 & S3
Amazon Web Service EC2 & S3
 
Generic repository pattern with ASP.NET MVC and Entity Framework
Generic repository pattern with ASP.NET MVC and Entity FrameworkGeneric repository pattern with ASP.NET MVC and Entity Framework
Generic repository pattern with ASP.NET MVC and Entity Framework
 
Python: Design Patterns
Python: Design PatternsPython: Design Patterns
Python: Design Patterns
 
Python: Common Design Patterns
Python: Common Design PatternsPython: Common Design Patterns
Python: Common Design Patterns
 
Prototype pattern
Prototype patternPrototype pattern
Prototype pattern
 
Strategy Design Pattern
Strategy Design PatternStrategy Design Pattern
Strategy Design Pattern
 
Design Patterns (Examples in .NET)
Design Patterns (Examples in .NET)Design Patterns (Examples in .NET)
Design Patterns (Examples in .NET)
 

Similar to Builder pattern

Sap Solman Instguide Dba Cockpit Setup
Sap Solman Instguide Dba Cockpit SetupSap Solman Instguide Dba Cockpit Setup
Sap Solman Instguide Dba Cockpit Setupwlacaze
 
Continuous Delivery: The Dirty Details
Continuous Delivery: The Dirty DetailsContinuous Delivery: The Dirty Details
Continuous Delivery: The Dirty DetailsMike Brittain
 
Tips and Tricks for Automating Windows with Chef
Tips and Tricks for Automating Windows with ChefTips and Tricks for Automating Windows with Chef
Tips and Tricks for Automating Windows with ChefChef Software, Inc.
 
mloc.js 2014 - JavaScript and the browser as a platform for game development
mloc.js 2014 - JavaScript and the browser as a platform for game developmentmloc.js 2014 - JavaScript and the browser as a platform for game development
mloc.js 2014 - JavaScript and the browser as a platform for game developmentDavid Galeano
 
Faster computation with matlab
Faster computation with matlabFaster computation with matlab
Faster computation with matlabMuhammad Alli
 
Creating Virtual Infrastructure
Creating Virtual InfrastructureCreating Virtual Infrastructure
Creating Virtual InfrastructureJake Weston
 
Using GPUs to handle Big Data with Java by Adam Roberts.
Using GPUs to handle Big Data with Java by Adam Roberts.Using GPUs to handle Big Data with Java by Adam Roberts.
Using GPUs to handle Big Data with Java by Adam Roberts.J On The Beach
 
Ankit Phadia Hacking tools (2)
Ankit Phadia Hacking tools (2)Ankit Phadia Hacking tools (2)
Ankit Phadia Hacking tools (2)Chandra Pr. Singh
 
Parallel Graphics in Frostbite - Current & Future (Siggraph 2009)
Parallel Graphics in Frostbite - Current & Future (Siggraph 2009)Parallel Graphics in Frostbite - Current & Future (Siggraph 2009)
Parallel Graphics in Frostbite - Current & Future (Siggraph 2009)Johan Andersson
 
How to Use the Command Line to Increase Speed of Development
How to Use the Command Line to Increase Speed of DevelopmentHow to Use the Command Line to Increase Speed of Development
How to Use the Command Line to Increase Speed of DevelopmentAcquia
 
Computer systems|Computer Networking & Communication System Assignment - Netw...
Computer systems|Computer Networking & Communication System Assignment - Netw...Computer systems|Computer Networking & Communication System Assignment - Netw...
Computer systems|Computer Networking & Communication System Assignment - Netw...freeassignmenthelp
 
How to make a large C++-code base manageable
How to make a large C++-code base manageableHow to make a large C++-code base manageable
How to make a large C++-code base manageablecorehard_by
 
Game programming workshop
Game programming workshopGame programming workshop
Game programming workshopnarigadu
 
Profiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / WebgrindProfiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / WebgrindSam Keen
 
Strategies for refactoring and migrating a big old project to be multilingual...
Strategies for refactoring and migrating a big old project to be multilingual...Strategies for refactoring and migrating a big old project to be multilingual...
Strategies for refactoring and migrating a big old project to be multilingual...benjaoming
 
Automating the Cloud with Terraform, and Ansible
Automating the Cloud with Terraform, and AnsibleAutomating the Cloud with Terraform, and Ansible
Automating the Cloud with Terraform, and AnsibleBrian Hogan
 
Build 2016 - B880 - Top 6 Reasons to Move Your C++ Code to Visual Studio 2015
Build 2016 - B880 - Top 6 Reasons to Move Your C++ Code to Visual Studio 2015Build 2016 - B880 - Top 6 Reasons to Move Your C++ Code to Visual Studio 2015
Build 2016 - B880 - Top 6 Reasons to Move Your C++ Code to Visual Studio 2015Windows Developer
 

Similar to Builder pattern (20)

Sap Solman Instguide Dba Cockpit Setup
Sap Solman Instguide Dba Cockpit SetupSap Solman Instguide Dba Cockpit Setup
Sap Solman Instguide Dba Cockpit Setup
 
Ams.rb Oktober
Ams.rb OktoberAms.rb Oktober
Ams.rb Oktober
 
Continuous Delivery: The Dirty Details
Continuous Delivery: The Dirty DetailsContinuous Delivery: The Dirty Details
Continuous Delivery: The Dirty Details
 
Tips and Tricks for Automating Windows with Chef
Tips and Tricks for Automating Windows with ChefTips and Tricks for Automating Windows with Chef
Tips and Tricks for Automating Windows with Chef
 
mloc.js 2014 - JavaScript and the browser as a platform for game development
mloc.js 2014 - JavaScript and the browser as a platform for game developmentmloc.js 2014 - JavaScript and the browser as a platform for game development
mloc.js 2014 - JavaScript and the browser as a platform for game development
 
Faster computation with matlab
Faster computation with matlabFaster computation with matlab
Faster computation with matlab
 
Creating Virtual Infrastructure
Creating Virtual InfrastructureCreating Virtual Infrastructure
Creating Virtual Infrastructure
 
Using GPUs to handle Big Data with Java by Adam Roberts.
Using GPUs to handle Big Data with Java by Adam Roberts.Using GPUs to handle Big Data with Java by Adam Roberts.
Using GPUs to handle Big Data with Java by Adam Roberts.
 
Dev ops
Dev opsDev ops
Dev ops
 
HPC Examples
HPC ExamplesHPC Examples
HPC Examples
 
Ankit Phadia Hacking tools (2)
Ankit Phadia Hacking tools (2)Ankit Phadia Hacking tools (2)
Ankit Phadia Hacking tools (2)
 
Parallel Graphics in Frostbite - Current & Future (Siggraph 2009)
Parallel Graphics in Frostbite - Current & Future (Siggraph 2009)Parallel Graphics in Frostbite - Current & Future (Siggraph 2009)
Parallel Graphics in Frostbite - Current & Future (Siggraph 2009)
 
How to Use the Command Line to Increase Speed of Development
How to Use the Command Line to Increase Speed of DevelopmentHow to Use the Command Line to Increase Speed of Development
How to Use the Command Line to Increase Speed of Development
 
Computer systems|Computer Networking & Communication System Assignment - Netw...
Computer systems|Computer Networking & Communication System Assignment - Netw...Computer systems|Computer Networking & Communication System Assignment - Netw...
Computer systems|Computer Networking & Communication System Assignment - Netw...
 
How to make a large C++-code base manageable
How to make a large C++-code base manageableHow to make a large C++-code base manageable
How to make a large C++-code base manageable
 
Game programming workshop
Game programming workshopGame programming workshop
Game programming workshop
 
Profiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / WebgrindProfiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / Webgrind
 
Strategies for refactoring and migrating a big old project to be multilingual...
Strategies for refactoring and migrating a big old project to be multilingual...Strategies for refactoring and migrating a big old project to be multilingual...
Strategies for refactoring and migrating a big old project to be multilingual...
 
Automating the Cloud with Terraform, and Ansible
Automating the Cloud with Terraform, and AnsibleAutomating the Cloud with Terraform, and Ansible
Automating the Cloud with Terraform, and Ansible
 
Build 2016 - B880 - Top 6 Reasons to Move Your C++ Code to Visual Studio 2015
Build 2016 - B880 - Top 6 Reasons to Move Your C++ Code to Visual Studio 2015Build 2016 - B880 - Top 6 Reasons to Move Your C++ Code to Visual Studio 2015
Build 2016 - B880 - Top 6 Reasons to Move Your C++ Code to Visual Studio 2015
 

More from Jyaasa Technologies (20)

Incident management with jira
Incident management with jiraIncident management with jira
Incident management with jira
 
Extreme programming practices ( xp )
Extreme programming practices ( xp ) Extreme programming practices ( xp )
Extreme programming practices ( xp )
 
The myth of 'real javascript developer'
The myth of 'real javascript developer'The myth of 'real javascript developer'
The myth of 'real javascript developer'
 
Microservices
MicroservicesMicroservices
Microservices
 
Facade pattern in rails
Facade pattern in railsFacade pattern in rails
Facade pattern in rails
 
Scrum ceromonies
Scrum ceromoniesScrum ceromonies
Scrum ceromonies
 
An introduction to bitcoin
An introduction to bitcoinAn introduction to bitcoin
An introduction to bitcoin
 
Tor network
Tor networkTor network
Tor network
 
Collective ownership in agile teams
Collective ownership in agile teamsCollective ownership in agile teams
Collective ownership in agile teams
 
Push notification
Push notificationPush notification
Push notification
 
The Design Thinking Process
The Design Thinking ProcessThe Design Thinking Process
The Design Thinking Process
 
User story
User storyUser story
User story
 
Design sprint
Design sprintDesign sprint
Design sprint
 
Data Flow Diagram
Data Flow DiagramData Flow Diagram
Data Flow Diagram
 
OKRs and Actions Overview
OKRs and Actions OverviewOKRs and Actions Overview
OKRs and Actions Overview
 
Vue.js
Vue.jsVue.js
Vue.js
 
Active record in rails 5
Active record in rails 5Active record in rails 5
Active record in rails 5
 
Design Patern::Adaptor pattern
Design Patern::Adaptor patternDesign Patern::Adaptor pattern
Design Patern::Adaptor pattern
 
Association in rails
Association in railsAssociation in rails
Association in rails
 
Web design layout pattern
Web design layout patternWeb design layout pattern
Web design layout pattern
 

Recently uploaded

Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 

Recently uploaded (20)

Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 

Builder pattern

  • 1. Builder Pattern Copyright 2016. Jyaasa Technologies. All Right Reserved h ttp://jyaasa.com Sagun Shrestha Sr. Software Engineer, Jyaasa Technologies
  • 2. What is Builder Pattern? Copyright 2016. Jyaasa Technologies. All Right Reserved h ttp://jyaasa.com
  • 3. ● The builder pattern is an object creation software design pattern. ● It is a pattern designed to help you configure complex objects ● It helps separate the construction of a complex object from its representation. ● So that the same construction process can create different representations.
  • 4. Let’s suppose we are building a system that will support computer manufacturing business Copyright 2016. Jyaasa Technologies. All Right Reserved h ttp://jyaasa.com
  • 5. class Computer attr_accessor :display attr_accessor :motherboard Attr_reader :drives def initialize(display=:crt, motherboard=Motherboard.new,drives=[ ]) @motherboard = motherboard @drives = drives @display = display end end
  • 6. class CPU # Common CPU stuff... end class BasicCPU < CPU # Lots of not very fast CPU-related stuff... end class TurboCPU < CPU # Lots of very fast CPU stuff... End
  • 7. # Computer’s motherboard and drive class Motherboard attr_accessor :cpu attr_accessor :memory_size def initialize(cpu=BasicCPU.new, memory_size=1000) @cpu = cpu @memory_size = memory_size end end class Drive attr_reader :type # either :hard_disk, :cd or :dvd attr_reader :size # in MB attr_reader :writable # true if this drive is writable def initialize(type, size, writable) @type = type @size = size @writable = writable end end
  • 8. # Build a fast computer with lots of memory... motherboard = Motherboard.new(TurboCPU.new, 4000) # ...and a hard drive, a CD writer, and a DVD drives = [ ] drives = << Drive.new(:hard_drive, 200000, true) drives << Drive.new(:cd, 760, true) drives << Drive.new(:dvd, 4700, false) computer = Computer.new(:lcd, motherboard, drives)
  • 9. class ComputerBuilder attr_reader :computer def initialize @computer = Computer.new end def turbo(has_turbo_cpu=true) @computer.motherboard.cpu = TurboCPU.new end def display=(display) @computer.display=display end def memory_size=(size_in_mb) @computer.motherboard.memory_size = size_in_mb end def add_cd(writer=false) @computer.drives << Drive.new(:cd, 760, writer) end def add_dvd(writer=false) @computer.drives << Drive.new(:dvd, 4000, writer) end def add_hard_disk(size_in_mb) @computer.drives << Drive.new(:hard_disk, size_in_mb, true) end end
  • 11. class DesktopComputer < Computer # Lots of interesting desktop details omitted... End class LaptopComputer < Computer def initialize( motherboard=Motherboard.new, drives=[] ) super(:lcd, motherboard, drives) end # Lots of interesting laptop details omitted... end class ComputerBuilder attr_reader :computer def turbo(has_turbo_cpu=true) @computer.motherboard.cpu = TurboCPU.new end def memory_size=(size_in_mb) @computer.motherboard.memory_size = size_in_mb end end
  • 12. class DesktopBuilder < ComputerBuilder def initialize @computer = DesktopComputer.new end def display=(display) @display = display end def add_cd(writer=false) @computer.drives << Drive.new(:cd, 760, writer) end def add_dvd(writer=false) @computer.drives << Drive.new(:dvd, 4000, writer) end def add_hard_disk(size_in_mb) @computer.drives << Drive.new(:hard_disk, size_in_mb, true) end end class LaptopBuilder < ComputerBuilder def initialize @computer = LaptopComputer.new end def display=(display) raise "Laptop display must be lcd" unless display == :lcd end def add_cd(writer=false) @computer.drives << LaptopDrive.new(:cd, 760, writer) end def add_dvd(writer=false) @computer.drives << LaptopDrive.new(:dvd, 4000, writer) end def add_hard_disk(size_in_mb) @computer.drives << LaptopDrive.new(:hard_disk, size_in_mb, true) end end
  • 13.
  • 15. Participants ● Builder ○ Specifies an abstract interface for creating parts of a Product object. ● ConcreteBuilder ○ Constructs and assembles parts of the product by implementing the Builder interface. ○ Defines and keeps track of the representation it creates. ○ Provides an interface for retrieving the product ● Director ○ Constructs an object using the Builder interface. ● Product ○ Represents the complex object under construction. ConcreteBuilder builds the product's internal representation and defines the process by which it's assembled. ○ Includes classes that define the constituent parts, including interfaces for assembling the parts into the final result.
  • 16. Collaboration ● The client creates the Director object and configures it with the desired Builder object. ● Director notifies the builder whenever a part of the product should be built. ● Builder handles requests from the director and adds parts to the product. ● The client retrieves the product from the builder.
  • 17.
  • 18. def computer raise "Not enough memory" if @computer.motherboard.memory_size < 250 raise "Too many drives" if @computer.drives.size > 4 hard_disk = @computer.drives.find {|drive| drive.type == :hard_disk} raise "No hard disk." unless hard_disk @computer end Building Sane Object
  • 19. Thank you Copyright 2016. Jyaasa Technologies. All Right Reserved h ttp://jyaasa.com