 Hello everyone, welcome to the channel. So today in this video, I'll be sharing you one of the important interview questions by taking the real-time example of my project. So explain about the factory design pattern. So how to answer this. So basically, factory design pattern is one of the most used design patterns in Java as most of you know, this type of, this is a creation design pattern actually. So which provides the best, one of the best ways of creating an object. So in factory design pattern, what we actually do is we hide the logic of creating the object to the client. And by using a common interface, we create the objects. So this is a basic definition you can say. So now let me take an example, real-time example and explain. So basically in my project, there were customers. So I have taken employer's name. So for in the customer class, there used to be one field called mode of contact. How you want, how the customer wanted to get contacted through email or mobile number. So that will be contained in this like email or mobile phone number. So based on the mode of contact, the process would happen. So now let me quickly create, I already created, let me quickly create one interface. Let me name more point of communication. Communication. Okay. So in this we will be having one method, public void process, which takes employee class reference. Okay. So now we need two classes which implement this communication. So if we take class, one is mobile, sorry, one is email communication. Okay. So in the, okay, implement communication. Okay, we need to override the method. Now, let us take add an implement method. Just I'll be adding one sys out here. The actual logic used to go here like how do we send an email to the employee. So let me add one sys out by saying employee, get name, communicate via email. What is the email? The email employee dot get email. Okay. This is done. Save this. I will create one more class mobile communication. Okay. Mobile communication. Okay. I'll directly add here interface communication. Okay. So in this method, I'll add one more sys out. So most basically this would be the sys out copy and paste communicated via mobile employee dot get mobile number. Sorry. What is the phone number? Okay. Save this. So these are the two classes which implement communication interface and based on the employee mode of communication or the objects will get created. Now, let us create a factory class. Let us name the communication factory finish. So inside this, we can have our logic like one method probably what it is written in communication get process. It will take a string as an input communication. Let us name it like that. So here goes our actual logic. If equals signal mode of communication, then I'll be passing. I'll be retaining new email. What happened? What was the class email communication only right? Yeah, got it. Else if if it is mobile, mobile dot equals ignore, then I'll be returning new mobile communication. Yeah. So the sorry, and the default condition should be there. So return none. So now let us test this design factory design pattern. So if you can if you can see, so I've already created a employee list. So I have created five employees. One is Angel Priya. A mode of communication is email and email ID is Angel Priya thread fav dot com. Second employee is Thakur mode of communication is mobile. Email ID is Thakur at the red show lay and mobile number is seven four some random number I have given third is papa ki pari mode of communication is mobile and papa ki pari at insta.com employee four is gubber thing whose mode of communication is mobile and 50,000 is the mobile number just randomly I gave some number employee five is Ramu kaka who needs to be communicated to email and 90s Ramu kaka at garden.com. So now we got an employee list. Now what we can do I'm using forage here. Okay, I need to catch this processor. So communication processor. So I'll firstly getting the processor but how I'll be getting I'll be creating the object of factory class communication factory factory equals new communication factory. So using this factory reference dot get process employee dot get mode of contact. So now based on the mode of contact I'll be getting the processor now using this processor dot process I'll process the employee so not let us see. So basically what should print Angel Priya communicated via email and this email ID Thakur got communicated via mobile mobile number. Similarly Papa ki pari and gubber Singh Ramu kaka. So now let me run this application. So yeah as you can see Angel Priya got communicated via mobile and sorry via email the email ID is this Thakur got communicated via mobile mobile number got printed gubber communicated via mobile mobile number got printed Papa ki pari got communicated via email Ramu kaka got communicated by email. So the same thing we can do using for each as well. Yeah. I know most of us might have commented by this time for each directly I can use this line factory dot get processor the employee dot get mode employee dot dot get dot sorry process of employee. So in one line we can finish this off. So let me read this out using Java 8 for each. Yeah. Yeah. Just this is all to print one empty line. So let us see whether we are getting the same input. Yeah. The same thing happened. So this is the simple example that we can give to demonstrate factory design pattern. So most of us like I took my real time experience real time scenario where we have used this. So if you don't have any what I can say readily available answer you can take this example and you can demonstrate it just fake it saying that we have a requirement based on which a customer has to be communicated via mobile number or email ID. So based on the mode of contact we have there is a scenario based on the mode of contact the employee needs to be contacted. So in that scenario we have we have used the factory design pattern and you can demonstrate this example. So most of my interviews I do this. So thought it would be definitely helpful for many. So this is the real time scenario and that's it for this video. So one request if you want to contribute something you can always if you're told you're buying something on Amazon you can open any of our videos and you know people already know that we have using Amazon affiliation. So you can open the link below any video and if you're told you're buying something you can search here directly and you will like basically we may get some what I like some commission on this. So if you haven't subscribed in our channel I would request you to please do subscribe our channel. You can already see the list of videos that we have already shared and this might and there are few which are already there in the queue. So please do subscribe to catch all the latest updates and thank you for watching. I hope this video might have helped at least few people and one more thing if at all you want to reach us out you can always reach out at this email ID for any questions or any help you can always reach us out on this email ID which is there in the word section or mostly under every video it will be given. So you can share even your interview experiences with us so that we post it on our channel and the and the what I can say the higher portion of the audience at the video can be reached and thank you for watching don't forget to subscribe.