So in our last video, we understood factory pattern which was a creational pattern. And now we are moving forward to the second design pattern which is also a creational pattern. Name of the design pattern is abstract factory pattern. Now I hope you can notice one thing that in the name of the design patterns we have one important word which is factory which shows me that there is also something which is connected or something similar to our factory pattern which we learn in the last video. Let me tell you one thing that in this particular design pattern video you are going to create a factory pattern in a very advanced way because this is not going to be one simple factory like in the last video. This pattern is also called as a factory of factories because it's good to have more than one factory send to one.
And actually, this is something which is almost there in all the real life business values. Because whatever sample we have done in the last one, that was a factory pattern, but in real life, we do not have a project which is going to have only a single factory, we most of the times, we are going to have more than one factories into one particular project. And that's why abstract factory is the one which is going to be the most useful, this creational pattern. In this case, the basic terminology of the factory pattern is going to show us that our interface is going to be responsible for creating a set of related objects or dependent objects with that without defining the concrete class. If I compare this scenario with the last sample, in that also we were having interface, which was actually with the name I factory, and that was responsible for my face.
Three instances. In this case also we are going to have an interface, but this interface is going to associate with the other factories, which may be going to create different types of product or different different products. One basic difference between the factory pattern and abstract factory pattern is in abstract factory pattern, we are not going to have our concrete classes which were associated with the interfaces. So without specifying the concrete classes somewhere the main root level interface is going to take care of the other interfaces, how we can deal with this multiple factories and how we can associate one main route level factories with the multiple factories. That's what we need to see in this particular sample. Now, before we see the code, let me tell you one thing that we are also going to deal with this scenario which is going to have a KitKat manufacturing company with us.
The company's same which you have used in the last time Also, but in this case, this time, this company wants me to create three products, not one. And like last time, we still have more than one client. So we are going to have multiple clients inside this. So the scenario of the project is this, that we are going to have multiple clients and for each client, we are going to create multiple products. When we want this kind of thing, we have three kinds of products right now, computers, tablets, and smartphones. Now we are going to create three types of products.
That's why maybe our structure is going to change. And somewhere we need one factory pattern, which can be associated with all three different products. So let's see how we can deal with the code in this case. In this scenario, you can see that I have created two basic projects in one solution. One is get card, which is actually my console application and the other one is get card cool which is actually My class library. Right last sample, we are going to use this to projects and the most of the code we are going to write inside this card core.
And then we are going to have everything inside get card main method. Now the first thing which I'm going to do is I'm going to right click on my car core project, and I'm going to add a new item. This new item is actually going to be my first product type, which is going to be computer so I'm going to add one interface. And I'm going to give a name of the interface which is going to be AI computer. I will click on OK. And this one is going to create a new interface for me which is going to be a computer. I'm going to make sure that this computer is going to be public so that I can access this thing anywhere.
And after this. I'm going to copy this i computer.cs file, and I'm going to paste it twice Because I am going to create multiple types of products. The second interface is going to have a name, I tablet, and the third one is going to have a name I smartphones. Now once we have three interfaces, we know that we are going to have three different types of products. Now, all three interfaces are public. And we are going to change the name of this interface file with this I smartphone and I template.
I'm going to right click on my project and I'm going to add a new item now. And this time this is going to be a class because we have three interfaces. Now is the time to create classes which are associated with this. That's why I'm going to give a name of this class client a and we know that you know we are going to have more than one clients. So assume that this class is going to represent client a and the computer for example. Day, and therefore the name of the class is client computer.
I'm making this class public. And now, same way because we have multiple clients and multiple products, I'm just making a copy of this class. So we're going to rename this classes to client, a tablet, as well as client a smartphone. In short, these three classes are going to represent my three different products which are going to manufacture for my client a. Obviously, these three classes are actually having three different types of products and three different products. Once you're done with the renaming of these files, now let me change the class names also to the similar.
So we have client a tablet, and we have client a smartphone. Once we have the three classes ready with us, I'm going to copy all three classes and I will paste them Once we do that, you can see that we got a copy of this three classes. And now I'm going to rename this for my client B. So this one is going to be client B tablet. Same way, we're going to have some more class renamed like we are going to have client B smartphone. So this is going to be a smartphone only but for a different client.
And then we are going to have client B tablet also. And then we are going to have client B computer also. So you can see now we have six different classes and out of the six different classes, to our computers, to our tablets and to our smartphones. And I'm just renaming these classes based on the file names. Let me build this project. And I hope I'll get build succeeded.
Yes, I'm getting that and now it's time to move on. So we have three interfaces in our site. And you can see that we have six different products which are actually representing three types of products. So we if someone asked me I would say that we have computers, smartphone and tablet, but we have six different products for two different clients. Now because this client a computer is a computer to specify the type we are just implementing this I computer interface in that same way client B computer is also offer same type so we are going to add a computer in that. Similarly we are going to smartphone and we are adding a smartphone in that and client the smartphone is also going to be of the same type.
So we are adding a smartphone in that. Let's go to the tablet and we are reading it tablet and client B tablet is also going to be a tablet. Logically, we should have some logic inside this three C sharp classes because these three C sharp Classes are implementing interface. So, we should have some method inside the interface and when we implement the interface we should have some logic inside this. But right now, we are not making this code that much complex. So, we do not have any logic here.
And, but if you want in the real sample, you should have some logic inside a computer. And then you're going to implement that interface into this class and you can write some different different logics inside these three methods. So, the six classes are going to have logical code inside that, but right now, we are not doing that thing because we are not concentrating on that. So, we will right click on our project now and we are going to add a new item. This new item is going to be my interface which is going to be my factory. So now this is going to be my actual factory which can deal with my all the products.
I will make sure that this class is public and then in Inside this AI factory, it's time to write some methods. So I'm going to create one method first, maybe the name of the method is going to be create computer. So this method is going to create a new computer for my client which is going to return of Type II computer. So we are going to make sure that this method returns I computer type of object. We are going to copy this method and because our factory deals with multiple products, I'm going to say that my second method is going to return I smartphone and the name of the method is create smartphone. Similarly, the third one is going to return a tablet and the name of the method is going to be create tablet.
You can see that we have one eye factory which is actually having three methods inside that which are returning three different types of products. Now my each method is actually returning some particular type of product, which is a computer I smartphone or a tablet. But we know that because we have two clients, this one method can actually associate with two different kinds of computers. So client, a computer or client computer, anyone can be there into that, which is returning a computer. Same way, the second method is also going to associate with any of the classes of client a or client B. Let me right click on the project and I'm going to add a new item again.
And this new item is going to be a class. So because we have a factory, now we have to create a implementation class of that. And I'm creating a name of this client a factory. This client a factory class is going to implement I factory and when we are going to implement this interface by right click quick actions. And we are going to implement this interface, you can see that I'm getting three different methods. Now this three different methods are going to return three products specifically for this particular client.
So we are going to return the client a computer. And same way the second and third method is going to return client, a smartphone and client a tablet. So we are just going to rename this thing to client, a smartphone and client a tablet. So this class is returning all the products for this particular client. Now it's time to deal for the second one. So let me go to my solution explorer.
I'm going to copy my client a factory I'm going to paste it and I will rename this class to client B factory. This client B factory class is going to give me all the products of client B. So we are quickly going to change the class names which are returning client B computer, client B smartphone and client B tablet. Once we are done with this, we are all set to go you can see that we have two factories now which are client a factory and client B factory, both associated with our interface I factory, which is having these three methods inside that. And we have two different implementations of this interface which is actually connected with my three three products of my each client. So this are the three products of client a and same way we have three different products of client we also where we have Client B computers, smartphones and tablets.
Once you're done with this is a time to deal with our credit card manufacturing company, which can actually manufacture these three types of products and six different products for me. So that's what we are going to do in our next video. Thank you