Book Review
Head First Design Patterns: A Software Engineer’s Book Review

“Design pattern” software engineer-দের পরিচিত প্রথম architecture term-গুলোর একটি। আমরা tutorial দেখি, blog পড়ি, class diagram মুখস্থ করি। কিন্তু কোনো pattern-এর structure জানা আর কোন design pressure থেকে pattern-টি দরকার হয়েছে—এই দুইটি এক বিষয় নয়।
এটি Strategy, Factory বা Observer নিয়ে আরেকটি tutorial নয়। এটি এমন একটি বইয়ের review, যেটি design pattern শেখার ক্ষেত্রে আমাকে সবচেয়ে পরিষ্কার শুরু দিয়েছিল: Eric Freeman এবং Elisabeth Robson-এর Head First Design Patterns।
The Book at a Glance
এখানে দেখানো copy-টি Java 8-এর জন্য updated 10th Anniversary edition, যা O’Reilly-এর 2004 সালে প্রকাশিত original title-এর ওপর ভিত্তি করে তৈরি। Java example modernize করা হলেও বইটির জনপ্রিয় visual এবং conversational teaching style একই রাখা হয়েছে।
Authors
Eric Freeman এবং Elisabeth Robson; Head First learning approach তৈরি করেছিলেন Kathy Sierra এবং Bert Bates।
Edition
Original O’Reilly edition-এর Java 8 updated 10th Anniversary version।
Format
Quick reference নয়; active study-এর জন্য তৈরি substantial visual learning guide।
Examples
Example-গুলো Java-তে, কিন্তু design idea PHP, Laravel, C#, TypeScript এবং অন্য object-oriented environment-এ apply করা যায়।
Why the Teaching Style Works
বইটি সাধারণত formal definition দিয়ে chapter শুরু করে না। প্রথমে একটি ছোট application দেখায়, তারপর realistic change request যোগ করে, existing design-কে uncomfortable হতে দেয়, এবং সেই pressure-এর response হিসেবে একটি pattern develop করে।
Opening SimUDuck example-টি এর ভালো illustration। Different duck-এর flying এবং quacking behavior আলাদা হওয়ার আগে inheritance reasonable মনে হয়। বইটি সরাসরি Strategy Pattern ঘোষণা করে না। প্রথম design কেন rigid হয়ে যাচ্ছে সেটি দেখায়, যে behavior change হয় সেটিকে আলাদা করে, তারপর resulting design-টির একটি নাম দেয়।
Problem-first sequence-টি বইটির সবচেয়ে বড় strength। Pattern তখন আর memorization-এর diagram থাকে না; নিজের codebase-এ একই pressure এলে recognize করার মতো একটি solution হয়ে ওঠে।
Visual Explanations and UML Diagrams
Head First series ইচ্ছাকৃতভাবে visual। Illustration, dialogue, annotated code, exercise, question এবং simple UML-like diagram একই chapter-এ একসঙ্গে ব্যবহার করা হয়েছে। শুরুতে layout unconventional মনে হতে পারে, কিন্তু একই idea বারবার ভিন্ন representation-এ দেখানো হয়।
Design pattern শেখার জন্য এটি কার্যকর। Class diagram static relationship দেখায়, story বলে relationship কেন তৈরি হলো, আর code দেখায় runtime-এ object-গুলো কীভাবে collaborate করে। ফলে “UML চিনতে পারি” থেকে “design apply করতে পারি”—এই gap ছোট হয়।
The Patterns Covered
Main chapter-গুলো frequently discussed object-oriented pattern-এর একটি practical path তৈরি করে। কিছু chapter related pattern pair করে শেখায়, আর Compound Patterns chapter দেখায় pattern-গুলো isolated recipe না হয়ে কীভাবে একসঙ্গে collaborate করে।
- Strategy — interchangeable behavior encapsulate করা।
- Observer — tight coupling ছাড়া dependent object update রাখা।
- Decorator — object wrap করে responsibility যোগ করা।
Factory MethodএবংAbstract Factory— object creation stable interface-এর পেছনে নেওয়া।Singleton— একটি instance-এর access control করা এবং এর trade-off বোঝা।Command— request-কে object হিসেবে represent করে queue, logging, macro এবং undo support করা।AdapterএবংFacade— interface translate করা অথবা subsystem simplify করা।Template Method— algorithm structure fix রেখে selected step vary করতে দেওয়া।IteratorএবংComposite— collection traverse করা ও part-whole tree represent করা।State— বড় conditional block থেকেstate-specific behavior আলাদা করা।Proxy— remote, virtual এবং protectionproxyদিয়ে access control করা।- Compound Patterns — একাধিক pattern combine করা;
Model-View-Controllercentral example।
Appendix-এ Bridge, Builder, Chain of Responsibility, Flyweight, Interpreter, Mediator, Memento, Prototype এবং Visitor-সহ আরও কিছু pattern সংক্ষেপে introduce করা হয়েছে। অর্থাৎ focused core pattern-গুলো detail-এ শেখানো হয়েছে, বাকিগুলো further study-এর direction হিসেবে রাখা হয়েছে।
The Principles Underneath the Patterns
বইটির আসল value শুধু pattern name-এর catalog নয়। Pattern কেন কাজ করে, সেটি বোঝাতে বইটি বারবার গুরুত্বপূর্ণ object-oriented design principle-এ ফিরে যায়।
- Application-এর যে অংশ vary করে সেটিকে stable অংশ থেকে আলাদা করা।
- Implementation নয়, interface-এর জন্য program করা।
- Inheritance-এর বদলে composition prefer করা।
- Loose coupling-এর মাধ্যমে object interaction design করা।
- Class-কে extension-এর জন্য open কিন্তু modification-এর জন্য closed রাখা।
- Concrete class-এর বদলে abstraction-এর ওপর depend করা।
- শুধু close collaborator-এর সঙ্গে কথা বলা—Principle of Least Knowledge।
- Framework-কে application component call করতে দেওয়া—Hollywood Principle।
- একটি class-কে change হওয়ার একটি কারণ দেওয়া।
এই principle-গুলোর কয়েকটি SOLID-এর সঙ্গে directly overlap করে—বিশেষ করে Open-Closed Principle, Dependency Inversion এবং Single Responsibility। তবে বইটিকে complete SOLID reference বলা ঠিক হবে না। Concrete design problem-এর context-এ principle শেখানোর কাজটি বইটি খুব ভালো করে; পাঁচটি SOLID principle systematicভাবে পড়তে চাইলে additional source দরকার হবে।
What the Book Does Especially Well
- Pattern introduce করার আগে design কেন change করা দরকার তা দেখায়।
- Code, object collaboration এবং UML-কে আলাদা topic না বানিয়ে একসঙ্গে connect করে।
- Abstract definition-এর বদলে মনে রাখার মতো recurring story ও example ব্যবহার করে।
- Pattern vocabulary-কে engineering team-এর communication tool হিসেবে দেখায়।
- Trade-off নিয়ে আলোচনা করে এবং pattern কোনো magic bullet নয়—এটি মনে করিয়ে দেয়।
- Exercise ও “Brain Power” question active reading encourage করে।
Shared vocabulary-এর বিষয়টি professional team-এ বিশেষভাবে useful। “এই boundary-তে Adapter দরকার” অথবা “varying behavior-টি Strategy-এর পেছনে থাকা উচিত”—এমন বাক্য দ্রুত design direction communicate করতে পারে, যদি team pattern-এর পেছনের trade-off-ও বোঝে।
Where the Book Has Limitations
কোনো technical book সবার reading preference-এর সঙ্গে match করবে না। Visual style বইটিকে accessible করেছে, কিন্তু dense reference পছন্দ করা developer-এর কাছে page busy মনে হতে পারে। Repetition intentional, তবে pattern আগে থেকেই জানা থাকলে pace slow লাগতে পারে।
- Code Java-centric; PHP বা Laravel developer-কে syntax ও framework context নিজে translate করতে হবে।
- কিছু example-এর API বা application style underlying principle-এর তুলনায় পুরোনো মনে হতে পারে।
- সব design pattern সমান depth-এ cover করা হয়নি।
- Pattern recognize করা শেখায়, কিন্তু কখন pattern ব্যবহার না করতে হবে সেটি real refactoring experience থেকেই আসে।
- Architecture, distributed system বা functional pattern খুঁজলে অন্য বই দরকার হবে।
Who Should Read It
যেসব developer class, interface, inheritance এবং composition বোঝেন, কিন্তু object-oriented design-এর reliable mental model এখনো তৈরি হয়নি—তাদের জন্য বইটি সবচেয়ে বেশি recommend করব।
- Feature implementation থেকে design decision-এর দিকে এগোতে থাকা junior developer।
- Framework abstraction-এর পেছনের idea বুঝতে চাওয়া Laravel বা PHP developer।
- Pattern definition-কে বেশি academic বা code থেকে disconnected মনে করা self-taught developer।
- Visual refresher বা mentoring resource খুঁজছেন এমন experienced developer।
Benefit পেতে Java developer হতে হবে না। Syntax নয়, role translate করুন: Java interface PHP contract হতে পারে, concrete class Laravel container দিয়ে resolve হতে পারে, আর Observer event ও listener হিসেবে দেখা দিতে পারে। Implementation বদলাবে, design pressure একই থাকবে।
How I Recommend Reading It
Definition-এর list শেষ করার জন্য বইটি দ্রুত পড়া উচিত নয়। Activity-গুলো teaching method-এর অংশ। ধীরে এবং code-এর পাশাপাশি পড়লে value অনেক বেশি পাওয়া যায়।
- একবারে একটি pattern পড়ুন এবং class structure-এর আগে এটি কোন problem solve করে লিখুন।
- শুধু Java code পড়ে না থেকে নিজের primary language-এ example rebuild করুন।
- Existing project-এ একই design pressure আছে এমন একটি জায়গা খুঁজুন।
- Pattern-এর cost জিজ্ঞেস করুন: extra object, indirection, configuration বা debugging effort কতটা বাড়ছে?
- Real code-এ pattern use করার পর chapter আবার পড়ুন; second reading আলাদা হবে।
Final Verdict
Design pattern শেখার জন্য Head First Design Patterns ছিল আমার first choice, এবং এখনো সহজে recommend করতে পারি। বইটির সবচেয়ে বড় achievement pattern-কে simple দেখানো নয়; pattern-এর পেছনের reason visible করা।
Story, diagram, code এবং intentionally repeated principle abstract architecture vocabulary-কে design instinct-এ convert করতে সাহায্য করে। এরপরও production experience, code review, refactoring এবং advanced reference দরকার হবে। কিন্তু pattern কখন useful হয় সেটি বুঝতে চাইলে—শুধু UML কেমন দেখায় তা নয়—এই বইটি excellent starting point।
এই article-এর লেখা পরিমার্জন, formatting এবং Bangla translation-এ ChatGPT সহায়তা করেছে।
