{"id":18798631,"url":"https://github.com/liteobject/demo.designpattern.adapter","last_synced_at":"2026-05-02T02:31:58.409Z","repository":{"id":27151206,"uuid":"30620308","full_name":"LiteObject/Demo.DesignPattern.Adapter","owner":"LiteObject","description":"Example of adapter design pattern using Java \u0026 C#","archived":false,"fork":false,"pushed_at":"2023-06-10T03:31:02.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-29T18:22:05.684Z","etag":null,"topics":["adapter","csharp","design-patterns","java"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LiteObject.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-02-10T23:29:29.000Z","updated_at":"2023-06-10T03:31:40.000Z","dependencies_parsed_at":"2024-11-07T22:12:39.828Z","dependency_job_id":null,"html_url":"https://github.com/LiteObject/Demo.DesignPattern.Adapter","commit_stats":null,"previous_names":["liteobject/demo.designpattern.adapter"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LiteObject%2FDemo.DesignPattern.Adapter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LiteObject%2FDemo.DesignPattern.Adapter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LiteObject%2FDemo.DesignPattern.Adapter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LiteObject%2FDemo.DesignPattern.Adapter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LiteObject","download_url":"https://codeload.github.com/LiteObject/Demo.DesignPattern.Adapter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239727055,"owners_count":19687099,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["adapter","csharp","design-patterns","java"],"created_at":"2024-11-07T22:12:31.729Z","updated_at":"2026-01-02T02:30:16.324Z","avatar_url":"https://github.com/LiteObject.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# The Adapter Design Pattern\nThe Adapter design pattern allows objects with incompatible interfaces to work together by providing a common interface that both objects can use. \n\nThis pattern is useful when you want to reuse an existing class but its interface doesn't match the requirements of the client code. \n\n## Example 1\nWe have a legacy `LegacyCar` class that has an incompatible interface (`Start` method). \nWe want to use this class in our client code that expects objects to implement the `IVehicle` interface.\n\nTo bridge the gap, we create an `CarAdapter` class that implements the `IVehicle` interface. \nThe adapter takes an instance of `LegacyCar` in its constructor. Inside the adapter's `StartEngine` method,\nwe convert the parameters-less to the format expected by the `LegacyCar` and then call its `Start` method.\n\nThe `Client` class doesn't know about the `LegacyCar` or the adapter details. It simply uses the `IVehicle` \ninterface to start the engine.\n\nFinally, in the `Main` method, we create an instance of `LegacyCar`, create the adapter by passing the \n`LegacyCar`, create the client, and use the client to start the engine. The client code is unaware of \nthe adapter and can seamlessly work with the `IVehicle` interface.\n\nThe Adapter pattern allows us to reuse the existing `LegacyCar` class in our client code without modifying\nit. It provides a way to adapt the incompatible interface of the `LegacyCar` to the `IVehicle` interface \nexpected by the client.\n\n## Example 2\nWe have an existing `Logger` class with a method Log that takes a string message as an argument. However, we \nwant to use a new logging framework that expects a different interface, `ILog`, with a method `LogMessage`.\n\nTo adapt the `Logger` class to the `ILog` interface, we create a `LoggerAdapter` class that implements `ILog`. The \nadapter takes an instance of the `Logger` class in its constructor. Inside the adapter's `LogMessage` method, we \ncall the `Log` method of the `Logger` class.\n\nThe `Client` class depends on the `ILog` interface and doesn't know about the `Logger` or the adapter details. \nIt uses the `ILog` interface to log messages.\n\nIn the `Main` method, we create an instance of `Logger`, create the adapter by passing the `Logger`, create the client \nby passing the adapter, and use the client to log messages. The client code is unaware of the adapter and can \nseamlessly work with the `ILog` interface.\n\nThe Adapter pattern allows us to adapt the existing `Logger` class to work with the new logging framework without \nmodifying it. It provides a way to bridge the gap between the incompatible interfaces and allows the client code \nto use the `ILog` interface to log messages.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliteobject%2Fdemo.designpattern.adapter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fliteobject%2Fdemo.designpattern.adapter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliteobject%2Fdemo.designpattern.adapter/lists"}