For the Adapter pattern, Reynald walks through the code to explain the structure, classes & methods of how the sample application works. After the walkthrough, you should be ready to add code that will be used to execute the program. Key participants from the class diagram discussed that will be mentioned include: Target, Adapter, Adaptee, and Client
- [Instructor] So let's go ahead and walk though the code of the Adapter pattern. So, as you recall, we had our ThirdPartyEmployee, ITarget, and EmployeeAdapter, which is the Adaptee, Target, and Adapter, respectively. Okay? So let's go ahead and look at those in the code. So here, starting on line 12, is our ThirdPartyEmployee class. And what's important to recognize in this class is that it's currently a list collection, but it could've been any type of collection.
It could've been an array or something else. And whatever it is, it's completely independent on its own. Now, right below it we have our interface ITarget, which will get the employees, okay? So on line 32, we actually implement the interface and then call the GetEmployeeList method to actually get the list of employees. So, really, that's it.
Those are the three main parts of an Adapter class, and it's called the Adapter because if we had a different type of list at the very top, it's not going to be a big deal to have different ways of calling the different types of lists whether it be for one third-party that uses a generic list for collection versus another that might be using an array or a dictionary object. Now how do we actually use this? Let's go ahead and actually write out the code for the client to implement this and see what the output is.
That's up next.
- What are design patterns?
- Who are the Gang of Four?
- Learning about the three categories of design patterns
- Builder pattern
- Adapter pattern
- Composite pattern
- Chain of Responsibility pattern
- Command pattern
- Interpreter pattern
- Mediator pattern
- Visitor pattern