factory method pattern
DESCRIPTION
Factory Method Design Pattern ExplainedTRANSCRIPT
![Page 1: Factory method pattern](https://reader035.vdocuments.site/reader035/viewer/2022062513/5562ec23d8b42a213b8b4c10/html5/thumbnails/1.jpg)
Factory Method Pattern
Shahriar Iqbal Chowdhury & Monjurul Habib
Code Name: Remington
http://www.facebook.com/groups/netter/
![Page 2: Factory method pattern](https://reader035.vdocuments.site/reader035/viewer/2022062513/5562ec23d8b42a213b8b4c10/html5/thumbnails/2.jpg)
Why We need Factory? Caveman Example
![Page 3: Factory method pattern](https://reader035.vdocuments.site/reader035/viewer/2022062513/5562ec23d8b42a213b8b4c10/html5/thumbnails/3.jpg)
![Page 4: Factory method pattern](https://reader035.vdocuments.site/reader035/viewer/2022062513/5562ec23d8b42a213b8b4c10/html5/thumbnails/4.jpg)
The Solution
![Page 5: Factory method pattern](https://reader035.vdocuments.site/reader035/viewer/2022062513/5562ec23d8b42a213b8b4c10/html5/thumbnails/5.jpg)
A specialist for the job
![Page 6: Factory method pattern](https://reader035.vdocuments.site/reader035/viewer/2022062513/5562ec23d8b42a213b8b4c10/html5/thumbnails/6.jpg)
Factory Pattern Method Basics
• Creational Pattern• Which object to create• It lets a class defer instantiation to subclasses.• Absolutely all constructors should be private or protected• Also known as Virtual Constructor.
![Page 7: Factory method pattern](https://reader035.vdocuments.site/reader035/viewer/2022062513/5562ec23d8b42a213b8b4c10/html5/thumbnails/7.jpg)
When to consider?
• When we have a class that implements an interface but not sure which object, which concrete instantiation / implementation need to return.• When we need to separate instantiation from the representation.• When we have lots of select and switch statements for deciding which concrete class to create and return.
![Page 8: Factory method pattern](https://reader035.vdocuments.site/reader035/viewer/2022062513/5562ec23d8b42a213b8b4c10/html5/thumbnails/8.jpg)
Factory Says
Define an interface for creating an object, but let subclasses decide which class to instantiate
![Page 9: Factory method pattern](https://reader035.vdocuments.site/reader035/viewer/2022062513/5562ec23d8b42a213b8b4c10/html5/thumbnails/9.jpg)
Problem without Factory Method Pattern
![Page 10: Factory method pattern](https://reader035.vdocuments.site/reader035/viewer/2022062513/5562ec23d8b42a213b8b4c10/html5/thumbnails/10.jpg)
Solution Applying Factory Method Pattern
![Page 11: Factory method pattern](https://reader035.vdocuments.site/reader035/viewer/2022062513/5562ec23d8b42a213b8b4c10/html5/thumbnails/11.jpg)
Banking Account Management System
![Page 12: Factory method pattern](https://reader035.vdocuments.site/reader035/viewer/2022062513/5562ec23d8b42a213b8b4c10/html5/thumbnails/12.jpg)
Object is created based on configuration parameters
![Page 13: Factory method pattern](https://reader035.vdocuments.site/reader035/viewer/2022062513/5562ec23d8b42a213b8b4c10/html5/thumbnails/13.jpg)
Violation of OCP (Open Close Principle of SOLID)
![Page 14: Factory method pattern](https://reader035.vdocuments.site/reader035/viewer/2022062513/5562ec23d8b42a213b8b4c10/html5/thumbnails/14.jpg)
we will need to create a property that indicates type in each account class
![Page 15: Factory method pattern](https://reader035.vdocuments.site/reader035/viewer/2022062513/5562ec23d8b42a213b8b4c10/html5/thumbnails/15.jpg)