Factory Pattern

Factory Pattern က Creational Pattern တစ်ခု ဖြစ်ပါတယ်။ Factory ဆိုသည့် အတိုင်း စက်ရုံကနေ ပစ္စည်း ထုတ် သလို object တွေကို ဖန်တီးပေးသည့် pattern တစ်ခုပါ။ Factory pattern မသုံးခင်မှာ Object တွေကို လက်ရှိ code တွေထဲကနေ ရောရေးပြီး ဖန်တီးပါတယ်။ Factory pattern က single responbility ဖြစ်ပြီး separation of concern အရ object ဖန်တီး မှု ကို ခွဲထုတ်ရေးသားလိုက်ခြင်း မျိုးပါပဲ။ Factory Pattern မသုံးခင် java code ကို ကြည့်ရအောင်။ public class Shape…More

Builder Pattern

Builder Pattern က Creational Pattern တစ်ခု ဖြစ်ပါတယ်။ Builder ဆိုသည့် အတိုင်း object ကို ဆောက်သည့် နေရာမှာ အသုံးပြုပါတယ်။ Builder Pattern က object ကို immutable လုပ်ချင်သည့် အခါမှာ အသုံးပြုပါတယ်။ ပုံမှန် အားဖြင့် object ကို immutable လုပ်ချင်သည့် အခါမှာ Consturctor မှာ pass လုပ်ပေးရပါတယ်။ public class Person { private String firstName; private String lastName; private int age; private String email; private String phone; private…More

Proxy Pattern

Proxy Pattern က structural pattern တစ်ခုပါ။ Proxy ဆိုတာကတော့ ကြားခံ ပြီး အတုအယောင် လုပ်ပေးသည့် သဘောပါ။ ဥပမာ Database နဲ့ တွဲပြီး ရေးသည့် အခါမှာ Query လုပ်လိုက်တယ်။ Result ပြန်လာတယ်။ ဒါပေမယ့် ကျွန်တော်တို့တွေက cache ထည့်လိုက်ချင်တယ်။ Cache ထည့်ဖို့ အတွက် လက်ရှိ Database code တွေလည်း မထိချင်သည့် အခါမှာ Proxy Pattern ကို အသုံးပြုလို့ ရပါတယ်။ အခု ပုံမှာဆိုရင် Cache ကို Proxy နဲ့ အသုံးပြုလိုက်တာပါ။ လက်ရှိ code တွေကို ထိခိုက်မှု မရှိပဲ cache ထည့်ပြီးသား…More

Adapter Pattern

Adapter Pattern ဆိုတာကတော့ Structural Pattern တစ်ခုပါ။ Adapter ဆိုတာနဲ့ ပလပ်ပေါက်တွေ မှာ ထပ်မရရင် သုံးသည့် adapter ကို တန်းမြင်ကြမှာပါ။ Adapter Pattern က အဲဒီ အတိုင်းပါပဲ။ မတူညီသည့် class နှစ်ခုကို တစ်ခု နဲ့ တစ်ခု သုံးလို့ ရအောင် ပြောင်းပေးတာပါ။ ဥပမာ XML ကနေ JOSN object ပြောင်းပေးသလိုပေါ့။ Class Diagram ကို ကြည့်ရအောင်။ အခု Mile to KM ပြောင်းသည့် ဥပမာ ကြည့်ရအောင်။ Java အနေနဲ့ ရေးရင် interface MileConverter { double convertMilesToKilometers(double miles);…More

Chain of Responsibility

Chain of Responsibility Pattern က Behaviour Pattern တစ်ခုပါ။ Chain Of Responbility က chain တွေလိုမျိုး အဆင့် တွေ ကို တစ်ခု ပြီး တစ်ခု အလုပ်လုပ်သွားသည့် ပုံစံမျိုးပါ။ အောက်က ပုံလေးကို ကြည့်ကြည့်ပါ။ ဒီပုံလေးကို မြင်လိုက်တာ နဲ့ backend developer တွေ ဆိုရင် Middleware ပဲ ဆိုတာ မြင်သွားပါလိမ့်မယ်။ Request တစ်ခု ရောက်လာရင် middleware ခံပြီးတော့ မှန် ခဲ့ ရင် next ကို ခေါ်ခေါ်သွားတာကို သတိရမှာပါ။ backend request ရောက်လာရင် login ဝင်ထားလား။ မှန်ရင် next…More

Iterator Pattern

Iterator Pattern က behaviour pattern တစ်ခုပါ။​ Composite Pattern လိုမျိုး code တွေမှာ ဆိုရင် အဆုံးကို မသိနိုင်ပါဘူး။ Directory အောက်မှာ Directory တွေက တောက်လျှောက် ရှိနိုင်တယ်။ Tree ကို traversal သွားရင် BFS နဲ့ DFS algorithm နှစ်ခု ရှိပါတယ်။ နှစ်သက်ရာနဲ့ သွားလို့ ရအောင်လည်း လုပ်ချင်တယ် ဆိုရင် Iterator pattern က ပို အဆင်ပြေပါတယ်။ Iterator Pattern က loop လုပ်ရသည့် အခါတွေ မှာ သုံးလို့ရပါတယ်။ Class Diagram ကို ကြည့်ရအောင်။ ကျွန်တော်တို့ Directory နဲ့…More

Composite Pattern

Composite Pattern ကတော့ structural design pattern ဖြစ်ပါတယ်။ Composite က Tree Structure တွေ မှာ အသုံးများပါတယ်။ Tree Structure ပြဿနာတွေ ဆိုရင် Composite လို့ ဆိုလို့ရတယ်။ ဥပမာ File Structure တစ်ခုကို ကြည့်ရအောင်။ Folder တစ်ခု အောက်မှာ Folder လည်း ရှိတယ်။ File လည်း ရှိနိုင်ပါတယ်။ Linux က file system တွေမှာ ဆိုရင် root(/) အောက်မှာ အခါ folder နဲ့ file တွေ ရှိပြီး အဆင့်ဆင့် ခွဲ သွားတာ မျိုးပေါ့။ / /var/…More

State Pattern

State Pattern ကတော့ Behaviour Pattern တစ်ခုပါ။ State Pattern ကတော့ strategy pattern နဲ့ တူသလို နဲ့ မှားတတ်ပါတယ်။ State Pattern ကတော့ strategy pattern လိုပါပဲ။ ဒါပေမယ့် သူက state တစ်ခု ကနေ တစ်ခု ပြောင်းလဲ သွားတာ ရှိပါတယ်။ ဥပမာ။ Level 1 မှာ play 1 point ရမယ်။ Level 1 မှာ point 100 ရရင် Level 2 ကို ပြောင်းမယ်။ Level 2 မှာ play တစ်ခါ လုပ်တိုင်း 2…More