{"id":26863096,"url":"https://github.com/jwill9999/adapter","last_synced_at":"2026-02-12T15:31:33.225Z","repository":{"id":127600585,"uuid":"175223844","full_name":"jwill9999/Adapter","owner":"jwill9999","description":"Creation and implementation tutorial - The Adapter Patttern.","archived":false,"fork":false,"pushed_at":"2019-03-12T14:05:37.000Z","size":212,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-08-24T20:44:14.121Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"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/jwill9999.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,"zenodo":null}},"created_at":"2019-03-12T14:04:21.000Z","updated_at":"2019-03-12T14:04:21.000Z","dependencies_parsed_at":"2023-08-16T22:02:59.393Z","dependency_job_id":null,"html_url":"https://github.com/jwill9999/Adapter","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/jwill9999/Adapter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwill9999%2FAdapter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwill9999%2FAdapter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwill9999%2FAdapter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwill9999%2FAdapter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jwill9999","download_url":"https://codeload.github.com/jwill9999/Adapter/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwill9999%2FAdapter/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29370546,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-12T08:51:36.827Z","status":"ssl_error","status_checked_at":"2026-02-12T08:51:26.849Z","response_time":55,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":[],"created_at":"2025-03-31T02:39:46.473Z","updated_at":"2026-02-12T15:31:33.220Z","avatar_url":"https://github.com/jwill9999.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# The Adapter Pattern\n\n\u003cdiv align=\"center\"\u003e\n\t\u003cimg src=\"https://farm8.staticflickr.com/7801/46439716365_30f9acc400_o.png\" width=\"100%\"\u003e\n\u003c/div\u003e\n\n\nThe adapter pattern allows the developer to add new functionality whilst not changing the users unlying API interface.\n\n### Book/Reader Example\n\nTake that we have a Person Class and they consume a Book class. We provide an interface for the Person to read that Book.\n\nWe want to add other devices to read however we DONT want to change our public facing API\n\n\u003e $book-\u003eopen();\n\n\u003e $book-\u003eturnPage();\n\n### Book Class\n\u003cdiv align=\"center\"\u003e\n\t\u003cimg src=\"./public/img/bookclass.PNG\" width=\"100%\"\u003e\n\u003c/div\u003e\n\n### Book Interface\n\u003cdiv align=\"center\"\u003e\n\t\u003cimg src=\"./public/img/bookInterface.PNG\" width=\"100%\"\u003e\n\u003c/div\u003e\n\n\n### Person Class\n\u003cdiv align=\"center\"\u003e\n\t\u003cimg src=\"./public/img/book.PNG\" width=\"100%\"\u003e\n\u003c/div\u003e\n\n\nSo how can we say add a Kindle Reader that does not affect our API as we still wish the code to use these api points?\n\nWe can use the Adapter Pattern. This allows us to add an additional Kindle Class that does not alter our read method.\n\n### So how does this work?\n\n1. We create a kindle class.\n2. That class implements its own interface and functionality.\n\n### Class Kindle\n\u003cdiv align=\"center\"\u003e\n\t\u003cimg src=\"./public/img/kindle.PNG\" width=\"100%\"\u003e\n\u003c/div\u003e\n\n### Kindle Interface\n\n\u003cdiv align=\"center\"\u003e\n\t\u003cimg src=\"./public/img/interface1.PNG\" width=\"100%\"\u003e\n\u003c/div\u003e\n\n3.\tWe then create an Kindle Adapter class which will allow us to plugin our existing code to the read method interface.\n4. This adapter class `implements the original BookInterface`\n\n### Kindle Adapter Class\n\u003cdiv align=\"center\"\u003e\n\t\u003cimg src=\"./public/img/adapter1.PNG\" width=\"100%\"\u003e\n\u003c/div\u003e\n\n5. We create `a constructor that takes a kindle device`. Here we are injecting that class into the adapter.\n6. We then implement the methods of that original BookInterface and during `each methods implementation logic we adapt from the Kindle's interface`.\n\n\nThen we can create instances by wrapping the kindle device with a Kindle Adapter. \n\n## Note that the read method on the Person class takes a bookInterface argument.\n\n `public function read(BookInterface $book)`\n\n ## This as you can see below is the new kindle device `wrapped` in it's own Adapter.\n\n\n\u003cdiv align=\"center\"\u003e\n\t\u003cimg src=\"./public/img/instances.PNG\" width=\"100%\"\u003e\n\u003c/div\u003e\n\n[Author :  Jason Williams @letuscode.co.uk](http://letuscode.co.uk)\n\n[Email : jasonwilliams@letuscode.co.uk](mailto:jasonwilliams@letuscode.co.uk)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjwill9999%2Fadapter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjwill9999%2Fadapter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjwill9999%2Fadapter/lists"}