Using Factory method pattern in Java project

Опубликовано: 28 Сентябрь 2024
на канале: Improve Your Programming skills
62
1

Factory method(creational design pattern) helps create the object its caller does not need to know how to create that object. The caller only needs to pass the parameters, the function will know what object it has to create to return.

For example, when calling the factory method
createMilkProduct(SweetenedMilk)
It returns sweetened milk product

createMilkProduct(UnSweetenedMilk)
It returns un-sweetened milk product

createMilkProduct(StrawberryMilk)
It returns strawberry milk product