It's not necessary that the Adapter class inherits the Adaptee class. The Adapter class can have an Adaptee attribute. For example: public class Adapter { private Adaptee adaptee; public Adapter() { this.adaptee = new Adaptee(); } //Rest of the code goes here } By this way, Both Adapter and Adaptee are independent so that they are loosely coupled.
right, I am thinking the same. We can also do it with simple inheritance and new keyword(I commented my solution here regarding kudvenkat). Now I am confused why do we need adapter design pattern and where do we use it.
adaptor pattern is used to connect to interfaces that are not compatible - this example does not show it :( - It shows haw a client can get the employees in JSON using NewtonSoft lib
Hi Venkat Sir, Hope you read this message. I am watching this 17th video of design pattern series by hoping that Kudvenkat series are the best to understand pattern which is considered as the base of .NET Programming. But seriously, I don't like the way that Avish has explained in all the design pattern(I am talking about the diagram or the Representational diagram on pattern that has been used has some kind of disconnection in the video as well as the auto-implemented code in every video which makes the topic disconnected as the video is short now). I feel like I am in a huge mess now. I would like if you could build a brief video on the same in your way. I am saying this because the way you taught makes me understand the topic easily as it gives a way to connect those with real scenarios.
Hello sir. I have a query regarding this tutorial. what's the use of IEmployee interface because we can achieve same result without using IEmployee interface. Please clear my doubt.
Hi Kanish, It's contract for client,client should call the methods using IEmployee interface. We need to make sure at any point of time to implement all the methods for IEmployee interface,we are not going to change existing clasees.
Hi sir, Do u have an example code snippet for point2 mentioned under Implementation Guidelines for adapter pattern Point2: We need to work through a seperate adapter that adapts the interface of an existing class without changing it…
I have to say. All videos I found online and all articles I google just doesn't explain this very clearly (or the way that is good for me personally). So I did something desperate. I actually read that Adapter chapter from GoF book. First three pages and it was all clear. So if you find this hard to understand after hours of watching / googling then maybe that book can help you too! PS. Obviously this comment is not for the author of the video but for future viewers. And I'm not saying video is necessarily bad, I just find book and its example much easier to comprehend.
Hi, Very well explained, I have a doubt though. Here, the return type of GetAllEmployees function of both Adaptee and Adapter is string. Will this work if adapter needs a different return type, let's say integer ?
It is not necessary to override the function and return same String type. One can have a new method in Adapter Class that accepts the String from GetAllEmployees as input and returns an Integer. The idea is to not disturb the existing Adaptee class.
I really miss Venkat's approach. This tutorial by Avish must be extremely confusing, especially for new people. You are not actually adapting the `Employee` at all, but rather the `EmployeeManager`. Here is updated code without the confusion: pastebin.com/1fGxS6tu
It's not necessary that the Adapter class inherits the Adaptee class. The Adapter class can have an Adaptee attribute. For example:
public class Adapter {
private Adaptee adaptee;
public Adapter() {
this.adaptee = new Adaptee();
}
//Rest of the code goes here
}
By this way, Both Adapter and Adaptee are independent so that they are loosely coupled.
right, I am thinking the same. We can also do it with simple inheritance and new keyword(I commented my solution here regarding kudvenkat). Now I am confused why do we need adapter design pattern and where do we use it.
adaptor pattern is used to connect to interfaces that are not compatible - this example does not show it :( - It shows haw a client can get the employees in JSON using NewtonSoft lib
Excellent way. Liked very much
Hi Venkat Sir, Hope you read this message. I am watching this 17th video of design pattern series by hoping that Kudvenkat series are the best to understand pattern which is considered as the base of .NET Programming. But seriously, I don't like the way that Avish has explained in all the design pattern(I am talking about the diagram or the Representational diagram on pattern that has been used has some kind of disconnection in the video as well as the auto-implemented code in every video which makes the topic disconnected as the video is short now). I feel like I am in a huge mess now. I would like if you could build a brief video on the same in your way. I am saying this because the way you taught makes me understand the topic easily as it gives a way to connect those with real scenarios.
Nice video! but it is slightly hard to look for the previous/next tutorial video. It will be nice to have a playlist. Thank you
At 4:00 can you please provide the complete line no. 39....???
Great explanation with a perfect example...
In this case, existing clients who expect xml doesn't work, correct?
Nice video and explanation.
Simply explained a great thing .. Thank you!!!
Very clear and concise. Excellent!
Hello sir. I have a query regarding this tutorial. what's the use of IEmployee interface because we can achieve same result without using IEmployee interface. Please clear my doubt.
I have same doubt
Hi Kanish, It's contract for client,client should call the methods using IEmployee interface. We need to make sure at any point of time to implement all the methods for IEmployee interface,we are not going to change existing clasees.
Using interface at client will allow to add more adapters if needed in future. We should never use concrete implementation at client.
Hi sir, Do u have an example code snippet for point2 mentioned under Implementation Guidelines for adapter pattern
Point2: We need to work through a seperate adapter that adapts the interface of an existing class without changing it…
"ArrayOfEmployee" How this name was attached to the final JSON string...?????
where we have given this name...???
I have one doubt. What if your method is not a virtual method. Inheriting from EmployerManager looking bit impractical
I have to say. All videos I found online and all articles I google just doesn't explain this very clearly (or the way that is good for me personally). So I did something desperate. I actually read that Adapter chapter from GoF book. First three pages and it was all clear. So if you find this hard to understand after hours of watching / googling then maybe that book can help you too! PS. Obviously this comment is not for the author of the video but for future viewers. And I'm not saying video is necessarily bad, I just find book and its example much easier to comprehend.
Hi,
Very well explained, I have a doubt though. Here, the return type of GetAllEmployees function of both Adaptee and Adapter is string. Will this work if adapter needs a different return type, let's say integer ?
It is not necessary to override the function and return same String type. One can have a new method in Adapter Class that accepts the String from GetAllEmployees as input and returns an Integer. The idea is to not disturb the existing Adaptee class.
Great explanation with a perfect example
Nice
Is it adapter pattern 🤔 it does not fit the definition 🙄
EmployeeManager should also inherit from IEmployee interface.
EmployeeManager is existing class and idea behind adapter design pattern is allow to access without modifying existing method
Thank you!
Examples are very tough for understanding
It will be easy if you use it in real project. Eventually you will find the need of this design pattern.
HAPPY NEW YEAR .GOOD TO SEE YOU IN 2018.
Thank you and we wish you the same.
What script is this? Java | C | C++ or something else .
Phong Phung c#
Iemploy is redudant here.
Console.Writeline("Happy New Year");
Thank you so much and we wish you the same.
I really miss Venkat's approach. This tutorial by Avish must be extremely confusing, especially for new people. You are not actually adapting the `Employee` at all, but rather the `EmployeeManager`.
Here is updated code without the confusion:
pastebin.com/1fGxS6tu
Happy New Year
Thank you and we wish you the same.
@Phong Phung c#
Not very clear