একটা বিয়ের প্রোগ্রাম আয়োজন করতে হলে Mandatory যে কাজগুলো করতে হয় :
- খাবার আয়োজন (বাবুর্চির কাজ)
- চেয়ার টেবিল সাজানো, খাবার পরিবেশন (ডেকোরেটরের কাজ)
- বউ সাজানো (পার্লারের কাজ)
ইত্যাদি আরো অনেকগুলো আলাদা আলাদা Company এর সাথে কথা বলে চুক্তি ঠিক করতে হয় । যা খুবই কষ্টকর এবং খরচ সাপেক্ষ্য। কিন্তু এখন অনেক Event Management Company আছে যারা ঐসব আলাদা আলাদা Company এর সাথে চুক্তিবদ্ধ। তাই যে কেউ শুধুমাত্র Event Management Company এর সাথে চুক্তি করেই সবগুলো Service পেতে পারে।
Façade Pattern ঠিক এই কাজটাই করে একটা Object অন্য আরো অনেকগুলো Object এর সাথে Associated থাকে । এভাবে আমরা একটা Object এর সাথে অন্য আরো কিছু Object জুড়ে দিয়ে Centralized Structure দাঁড় করাতে পারি। যেটা দিয়ে আলাদা অনেক গুলো সুবিধা একসাথে পেতে পারি।
উদাহরণ হিসাবে যদি আমরা TeamPossible ইভেন্ট ম্যানেজমেন্ট ফার্মকে দিয়ে বিয়ের অনুষ্ঠানের কাজ গুলো করিয়ে নেই Class Diagram টা দাঁড়ায়
Façade Pattern ঠিক এই কাজটাই করে একটা Object অন্য আরো অনেকগুলো Object এর সাথে Associated থাকে । এভাবে আমরা একটা Object এর সাথে অন্য আরো কিছু Object জুড়ে দিয়ে Centralized Structure দাঁড় করাতে পারি। যেটা দিয়ে আলাদা অনেক গুলো সুবিধা একসাথে পেতে পারি।
উদাহরণ হিসাবে যদি আমরা TeamPossible ইভেন্ট ম্যানেজমেন্ট ফার্মকে দিয়ে বিয়ের অনুষ্ঠানের কাজ গুলো করিয়ে নেই Class Diagram টা দাঁড়ায়
Facade Pattern Class Diagram |
এখানে TeamPossibleEventManagement কোম্পানি Cook, BeautyParlor, Decorator এই সার্ভিস গুলো দিয়ে থাকে । তাই TeamPossibleEventManagement এর মধ্যে Cook, BeautyParlor, Decorator কে Composition করা হয়েছে । উপরের ডায়াগ্রামের রম্বসের মতো ঐ চিহ্নই Composition । Composition যেহেতু স্ট্রং রিলেশন বোঝায় । তাই যতক্ষণ TeamPossibleEventManagement এর Object থাকবে ততক্ষণ Cook, BeautyParlor, Decorator কেও ব্যবহার করতে পারবো । যাতে করে আমরা শুধুমাত্র TeamPossibleEventManagement এর মাধ্যমেই সকল সুবিধা পেতে পারি ।
এবার কোড লিখার পালা -
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BeautyParlor { | |
public void brideGrooming(){ | |
System.out.println("BEAUTYPARLOR: Bride make over is ready. She ready to photoshoot"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Cook { | |
public void cooking(){ | |
System.out.println("COOK: All menu are ready to decorate"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Decorator { | |
public void setEnvironment(){ | |
System.out.println("DECORATOR: Full set is in our control, please take your seat."); | |
} | |
} |
TeamPossibleEventManagement এর মধ্যে Cook, BeautyParlor, Decorator অবজেক্ট গুলোকে Composition করে দিবো -
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TeamPossibleEventManagement { | |
Cook cook; | |
Decorator decorator; | |
BeautyParlor beautyParlor; | |
public TeamPossibleEventManagement() { | |
cook = new Cook(); | |
decorator = new Decorator(); | |
beautyParlor = new BeautyParlor(); | |
} | |
public void arrangeWeddingProgram() | |
{ | |
cook.cooking(); | |
decorator.setEnvironment(); | |
beautyParlor.brideGrooming(); | |
System.out.println("Thanks for inviting us to arrange such a beautiful wedding like this"); | |
} | |
} |
InviteAEventManagement থেকে TeamPossibleEventManagement এর মাধ্যমে আমাদের প্রোগ্রাম আরেঞ্জ করিয়ে নিবো । লক্ষ্য করুন TeamPossibleEventManagement এর অবজেক্ট করলে Cook, BeautyParlor, Decorator এগুলোরও অবজেক্ট তৈরি হয়ে যাবে ।
আউটপুটঃ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class InviteAEventManagement { | |
public static void main(String[] args) { | |
TeamPossibleEventManagement tpEventManagement = new TeamPossibleEventManagement(); | |
// calling team possible to arrange wedding | |
tpEventManagement.arrangeWeddingProgram(); | |
} | |
} |
আউটপুটঃ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
COOK: All menu are ready to decorate | |
DECORATOR: Full set is in our control, please take your seat. | |
BEAUTYPARLOR: Bride make over is ready. She ready to photoshoot | |
Thanks for inviting us to arrange such a beautiful wedding |
THE END
Facade Pattern
Reviewed by hnjaman
on
July 05, 2018
Rating:
No comments: