Skip to main content

Adapter Design Pattern 😃

 Adapter Design Pattern 😃





لو افترضنا انك عامل integration مع بوابة دفع و مستخدم interface والي بتحتوي علي methods زي (auth , prepare , pay)

و انطلب انك هتضيف بوابة دفع تانية لكن هنا

هتستخدم third party library في الـ integration و بالفعل مش هينفع تستخدم interface الي كنت عاملها و دا بسبب ان integration هنا محتاج فقط (pay method )

طبعا استخدامك لنفس interface مفروغ منه علشان SOLID و حاجات تانية

تفتكر اي الحل ؟

الحل هنا ببساطه انك تجيب حاجه زي موصل أو converter يقدر يخلي

new integration class تتناسب مع current interface و دا هيبقي Adapter .


- دا يعتبر أول pattern هيتم شرحه في مجموعة structural patterns و الي بتحل لك

مشاكل structure code و بيستخدم بكثرة عند إنشاء frameworks .


هتلاقي مرفق مثال مشهور أوي و هوه ان شاحن الموبايل بيبقي ثلاثي علشان تقدر

تستخدمه بتحتاج converter و الي هوه هنا

بيمثل adapter class

Comments

Popular posts from this blog

Using Larave Api Resource , Adding Additional data to Response

  Github repository for more styled code    https://github.com/MohamedFathiM/Blogs/blob/main/apiResource.md What is the API Resource : A transformation layer that sits between your Eloquent models and the JSON responses. First Time Using It: The first time I am using the API resource, I was confused about the difference between the two classes, you will find it in the API resource of laravel (Resource, Collection), Ex: PostReource and PostCollection. Larave Api Resource has two classes you can simply make them using artisan like that. php artisan make :resource PostResource This command create a class in App\Http\Resources extends JsonResource php artisan make:resource PostCollection --collection or php artisan make :resource PostCollection name of the class with suffix collection this command create a class in App\Http\Resources extends ResourceCollection so, what is the difference between them? Resource Class Collection Class extends JsonResource ext

Laravel Project does not need apache

من الحاجات الغريبة الي اكتشفتها بالصدفة كدا و وقفت قدامها فترة مش فاهم حاجه ... استغربت ان زميلي يعمل run لمشروع Laravel بدون ما يعمل run لل apache server .. php artisan serve بفضل الله لما ركزت كدا شوية روحت اقرأ ملف server.php الي موجود في root folder of laravel project و لقيت السطرين دول الي في screen -------------------- لارافيل معتمد علي built-in PHP web server و بالتالي مش محتاج apache server علشان تعمل run لل project -------------------- من الأسئلة المهمة هنا : هل ممكن نستبدل apache او nginx ب php server ؟ الاجابة باختصار لا و السبب ان السيرفر دا في الاساس اتعمل من أجل developers وليس full feature .. شوف التحذير الي في أول manual هنا PHP Manual References : Github Laravel server.php https://stackoverflow.com/questions/27485505/symfony-apache-vs-built-in-php-server https://www.php.net/manual/en/features.commandline.webserver.php