Software Engineering & Information Systems DesignSoftware Engineering & Information Systems Design
How we build software step by step: process models, requirements, UML, testing, architecture, and system design basics.ধাপে ধাপে software বানানোর নিয়ম: process model, requirements, UML, testing, architecture আর system design-এর basic।
- Software Lifecycle & Process ModelsSoftware Lifecycle & Process Models
- Requirements EngineeringRequirements Engineering
- UML and DesignUML and Design
- Software TestingSoftware Testing
- Architecture & Design PrinciplesArchitecture & Design Principles
- Information Systems Design BasicsInformation Systems Design Basics
- Practice QuestionsPractice Questions
1. Software Lifecycle & Process Models1. Software Lifecycle & Process Models
Software is not built in one shot. It goes through a lifecycle: a series of phases from the first idea to the final retirement of the product. This is called the SDLC (Software Development Life Cycle).
The standard SDLC phases are:
- Requirements analysis — find out WHAT the customer needs.
- Design — plan HOW the software will be built (architecture, modules, data).
- Implementation (coding) — write the actual code.
- Testing — check that the software works and matches the requirements.
- Deployment — deliver the software to the users.
- Maintenance — fix bugs and add changes after release. This is often the longest and most costly phase.
A process model is a plan that says in which order and in what style we do these phases. Different projects need different models.
Software একবারে বানানো হয় না। এটা একটা lifecycle-এর মধ্যে দিয়ে যায়: প্রথম idea থেকে শুরু করে product বাতিল হওয়া পর্যন্ত কিছু ধাপ। এটাকেই বলে SDLC (Software Development Life Cycle)।
Standard SDLC phase গুলো হলো:
- Requirements analysis — customer আসলে কী চায়, সেটা বের করা।
- Design — software কীভাবে বানানো হবে তার plan (architecture, module, data)।
- Implementation (coding) — আসল code লেখা।
- Testing — software ঠিকমতো কাজ করে কি না আর requirement মেলে কি না, তা check করা।
- Deployment — user-দের কাছে software পৌঁছে দেওয়া।
- Maintenance — release-এর পরে bug fix আর নতুন change যোগ করা। এটা প্রায়ই সবচেয়ে লম্বা আর সবচেয়ে বেশি খরচের phase।
Process model হলো একটা plan, যেটা বলে দেয় এই phase গুলো কোন order-এ, কোন style-এ করা হবে। আলাদা আলাদা project-এর জন্য আলাদা model লাগে।
Waterfall modelWaterfall model
The Waterfall model is the oldest and simplest model. Phases run one after another, like water falling down steps. You finish one phase completely, get it approved, then move to the next. Going back is very hard.
Waterfall model হলো সবচেয়ে পুরনো আর সবচেয়ে simple model। Phase গুলো একটার পর একটা চলে, সিঁড়ি দিয়ে পানি পড়ার মতো। একটা phase পুরো শেষ করে approve করিয়ে তারপর পরের phase-এ যাওয়া হয়। পেছনে ফেরা খুব কঠিন।
Pros:
- Very simple to understand and manage.
- Each phase has a clear output (document, code, test report).
- Works well when requirements are fixed and well understood.
Cons:
- Working software appears only at the very end.
- Very hard to handle changing requirements.
- A mistake found late (in testing) is very costly to fix.
- Customer sees the product only at the end — big risk of "this is not what I wanted".
Pros:
- বোঝা আর manage করা খুব সহজ।
- প্রতিটা phase-এর একটা clear output থাকে (document, code, test report)।
- Requirement fixed আর ভালোভাবে জানা থাকলে ভালো কাজ করে।
Cons:
- কাজ করা software একদম শেষে পাওয়া যায়।
- Requirement বদলালে সামলানো খুব কঠিন।
- দেরিতে (testing-এ) ভুল ধরা পড়লে ঠিক করতে অনেক খরচ হয়।
- Customer product দেখে একদম শেষে — "আমি তো এটা চাইনি" হওয়ার বড় risk।
V-modelV-model
The V-model is Waterfall bent into a V shape. Each development phase on the left side has a matching testing phase on the right side. Test plans are written EARLY, while the matching left-side phase is running.
- Requirements ↔ Acceptance testing
- System design ↔ System testing
- Module (detailed) design ↔ Integration testing
- Coding ↔ Unit testing
Good for safety-critical projects (medical, avionics) where testing must be planned very carefully. Same weakness as Waterfall: rigid, bad with changes.
V-model হলো Waterfall-কে V আকারে ভাঁজ করা। বাম পাশের প্রতিটা development phase-এর সাথে ডান পাশে একটা matching testing phase থাকে। Test plan আগেভাগেই লেখা হয়, যখন বাম পাশের phase চলছে।
- Requirements ↔ Acceptance testing
- System design ↔ System testing
- Module (detailed) design ↔ Integration testing
- Coding ↔ Unit testing
Safety-critical project-এর জন্য ভালো (medical, avionics), যেখানে testing খুব যত্ন করে plan করতে হয়। দুর্বলতা Waterfall-এর মতোই: rigid, change সামলাতে পারে না।
Incremental modelIncremental model
In the Incremental model, the product is built and delivered in pieces called increments. The first increment is usually the core product (most important features). Each new increment adds more features on top.
Customer gets working software early, and feedback from one increment improves the next. Needs good planning so the pieces fit together.
Incremental model-এ product ছোট ছোট টুকরোয় বানিয়ে deliver করা হয়, প্রতিটা টুকরোকে বলে increment। প্রথম increment সাধারণত core product (সবচেয়ে জরুরি feature গুলো)। প্রতিটা নতুন increment তার উপরে আরও feature যোগ করে।
Customer আগেভাগে কাজ করা software পায়, আর এক increment-এর feedback পরের increment-কে ভালো করে। টুকরোগুলো যেন ঠিকমতো জোড়া লাগে, তার জন্য ভালো planning লাগে।
Spiral model (risk-driven)Spiral model (risk-driven)
The Spiral model (by Barry Boehm) combines iteration with risk analysis. The project moves in loops (spirals). Each loop has 4 quadrants:
- Determine objectives — set goals and constraints for this loop.
- Risk analysis — find risks, analyze them, build prototypes to reduce them.
- Develop and test — build the next version of the product.
- Plan next iteration — review with customer and plan the next loop.
Its key word is risk-driven: before every loop, the biggest risks are attacked first. Good for large, expensive, high-risk projects. Downside: costly, needs risk experts, too heavy for small projects.
Spiral model (Barry Boehm-এর দেওয়া) iteration-এর সাথে risk analysis মেলায়। Project টা loop (spiral) আকারে এগোয়। প্রতিটা loop-এ ৪টা quadrant থাকে:
- Determine objectives — এই loop-এর goal আর constraint ঠিক করা।
- Risk analysis — risk খুঁজে বের করা, analyze করা, risk কমাতে prototype বানানো।
- Develop and test — product-এর পরের version বানানো।
- Plan next iteration — customer-এর সাথে review করে পরের loop-এর plan করা।
এর মূল কথা risk-driven: প্রতিটা loop-এর আগে সবচেয়ে বড় risk গুলো আগে ধরা হয়। বড়, দামি, high-risk project-এর জন্য ভালো। খারাপ দিক: খরচ বেশি, risk expert লাগে, ছোট project-এর জন্য অতিরিক্ত ভারী।
Prototyping modelPrototyping model
When the customer is not sure what they want, we build a quick, rough prototype (often just the UI, with fake logic). The customer plays with it and gives feedback. We refine or rebuild until requirements become clear, then build the real system.
- Throwaway prototype: the prototype is discarded; only the learned requirements are kept.
- Evolutionary prototype: the prototype slowly grows into the final system.
Risk: the customer may think the rough prototype is the real product and expect delivery too soon.
Customer নিজেই যখন sure না সে কী চায়, তখন আমরা তাড়াতাড়ি একটা মোটামুটি prototype বানাই (অনেক সময় শুধু UI, ভেতরে fake logic)। Customer সেটা ব্যবহার করে feedback দেয়। Requirement clear না হওয়া পর্যন্ত ঠিক করতে থাকি, তারপর আসল system বানাই।
- Throwaway prototype: prototype ফেলে দেওয়া হয়; শুধু শেখা requirement গুলো রাখা হয়।
- Evolutionary prototype: prototype ধীরে ধীরে final system-এ বদলে যায়।
Risk: customer ভাবতে পারে মোটামুটি prototype-টাই আসল product, আর খুব তাড়াতাড়ি delivery আশা করতে পারে।
Agile & ScrumAgile & Scrum
Agile is a family of methods based on the Agile Manifesto (2001). Core ideas: deliver working software in short cycles, welcome changing requirements, talk to the customer all the time, prefer people and working software over heavy documents and rigid plans.
Scrum is the most popular Agile framework. Work happens in fixed short cycles called sprints (usually 2–4 weeks). Each sprint ends with a potentially shippable product increment.
Scrum roles (only 3):
- Product Owner — owns the product backlog, decides WHAT to build and in what priority.
- Scrum Master — coach and protector of the process; removes blockers. NOT a boss/manager.
- Development Team — 3–9 people who actually build the product; self-organizing.
Scrum artifacts: Product Backlog (all wanted features, prioritized), Sprint Backlog (items chosen for this sprint), Increment (working product at sprint end).
Scrum events: Sprint Planning, Daily Scrum (15-minute stand-up), Sprint Review (demo to stakeholders), Sprint Retrospective (how can WE work better).
XP (Extreme Programming) is another Agile method focused on engineering practices: pair programming, test-driven development (write tests first), continuous integration, small frequent releases, refactoring.
Agile হলো Agile Manifesto (2001)-এর উপর দাঁড়ানো কিছু method-এর পরিবার। মূল কথা: ছোট ছোট cycle-এ কাজ করা software deliver করা, requirement বদলালে স্বাগত জানানো, customer-এর সাথে সবসময় কথা বলা, ভারী document আর rigid plan-এর চেয়ে মানুষ আর কাজ করা software-কে বেশি দাম দেওয়া।
Scrum হলো সবচেয়ে জনপ্রিয় Agile framework। কাজ হয় fixed ছোট cycle-এ, যাকে বলে sprint (সাধারণত ২–৪ সপ্তাহ)। প্রতিটা sprint শেষে একটা shippable product increment পাওয়া যায়।
Scrum role (মাত্র ৩টা):
- Product Owner — product backlog-এর মালিক, ঠিক করে কী বানানো হবে আর কোনটা আগে।
- Scrum Master — process-এর coach আর রক্ষক; blocker সরায়। কোনো boss/manager না।
- Development Team — ৩–৯ জন, যারা আসলে product বানায়; self-organizing।
Scrum artifact: Product Backlog (সব চাওয়া feature, priority অনুযায়ী সাজানো), Sprint Backlog (এই sprint-এর জন্য বাছাই করা item), Increment (sprint শেষের কাজ করা product)।
Scrum event: Sprint Planning, Daily Scrum (১৫ মিনিটের stand-up), Sprint Review (stakeholder-দের demo), Sprint Retrospective (আমরা কীভাবে আরও ভালো কাজ করতে পারি)।
XP (Extreme Programming) আরেকটা Agile method, engineering practice-এ focus করে: pair programming, test-driven development (আগে test লেখা), continuous integration, ছোট ছোট ঘন ঘন release, refactoring।
Comparison of process modelsProcess model-দের comparison
| ModelModel | StyleStyle | Handles change?Change সামলায়? | Working software when?কাজ করা software কখন? | Best forকার জন্য ভালো |
|---|---|---|---|---|
| Waterfall | Linear, one passLinear, এক pass | Very poorlyখুব খারাপভাবে | Only at the endএকদম শেষে | Small projects, fixed clear requirementsছোট project, fixed আর clear requirement |
| V-model | Linear + matched testingLinear + matched testing | Poorlyখারাপভাবে | At the endশেষে | Safety-critical systems needing strong testingSafety-critical system, যেখানে কড়া testing দরকার |
| Incremental | Pieces (increments)টুকরো (increment) | Moderatelyমোটামুটি | Early (first increment)আগেভাগে (প্রথম increment) | Core features needed fast, full team not availableCore feature দ্রুত দরকার, পুরো team নেই |
| Spiral | Iterative + risk analysisIterative + risk analysis | Wellভালোভাবে | Each loop gives a versionপ্রতিটা loop-এ একটা version | Large, expensive, high-risk projectsবড়, দামি, high-risk project |
| Prototyping | Build rough → feedback → refineমোটামুটি বানাও → feedback → ঠিক করো | Well (early)ভালোভাবে (শুরুতে) | Prototype very earlyPrototype খুব আগে | Unclear/uncertain requirementsRequirement অস্পষ্ট হলে |
| Agile / Scrum | Short sprints, continuous feedbackছোট sprint, continuous feedback | Very wellখুব ভালোভাবে | Every sprint (2–4 weeks)প্রতি sprint-এ (২–৪ সপ্তাহ) | Changing requirements, close customer contactRequirement বদলায়, customer কাছে থাকে |
Why Software Projects Fail (Real Exam Question!)Software Project কেন Fail করে (Real Exam Question!)
Many software projects finish late, cost too much, or get cancelled. In the exam, you should be able to LIST the main reasons and say one line about each:
- Unclear or changing requirements — the team never really knew what to build, or the target kept moving.
- Poor estimation of time and cost — the schedule and budget were guesses that were too optimistic.
- Lack of user involvement — users were not asked during development, so the final product did not fit their real work.
- Poor communication — team members, managers, and the customer did not share the same understanding.
- Inadequate testing — bugs reached the users because testing was rushed or skipped.
- Scope creep — new features kept getting added without adding time or people.
- Weak project management — no clear plan, no progress tracking, wrong people on wrong tasks.
- Technical debt — quick-and-dirty code piled up until every new change became slow and risky.
- No risk management — nobody asked "what can go wrong?" early, so problems arrived as surprises.
অনেক software project দেরিতে শেষ হয়, খরচ বেশি হয়ে যায়, বা বাতিল হয়। Exam-এ মূল কারণগুলো LIST করে প্রতিটা নিয়ে এক লাইন বলতে পারতে হবে:
- Unclear বা changing requirements — team আসলে জানতই না কী বানাতে হবে, বা target বারবার সরে গেছে।
- Time আর cost-এর poor estimation — schedule আর budget ছিল বেশি আশাবাদী আন্দাজ।
- User involvement-এর অভাব — development-এর সময় user-দের জিজ্ঞেস করা হয়নি, তাই final product তাদের আসল কাজের সাথে মেলেনি।
- Poor communication — team member, manager আর customer একই জিনিস বোঝেনি।
- Inadequate testing — testing তাড়াহুড়ায় বা বাদ পড়ায় bug user-দের কাছে পৌঁছে গেছে।
- Scope creep — সময় বা মানুষ না বাড়িয়েই নতুন নতুন feature যোগ হতে থেকেছে।
- Weak project management — clear plan নেই, progress track হয় না, ভুল মানুষ ভুল কাজে।
- Technical debt — তাড়াহুড়ার নোংরা code জমতে জমতে প্রতিটা নতুন change slow আর risky হয়ে গেছে।
- Risk management নেই — শুরুতে কেউ জিজ্ঞেস করেনি "কী কী ভুল হতে পারে?", তাই সমস্যাগুলো surprise হয়ে এসেছে।
Software Maintenance and the SMLCSoftware Maintenance আর SMLC
Maintenance is everything done to the software AFTER delivery. It is usually the longest and most expensive part of the lifecycle (often 60% or more of total cost). There are four types of maintenance:
- Corrective — fix bugs that users find after release. (Reactive: something is broken.)
- Adaptive — change the software so it keeps working in a NEW environment: new OS, new hardware, new database, new law or tax rule.
- Perfective — improve the software for users: add requested features, make it faster, make reports nicer.
- Preventive — clean up NOW to avoid problems LATER: restructure messy code, update documentation, remove dead code.
The SMLC (Software Maintenance Life Cycle) has six phases, in order:
- Identification — receive change requests and identify what kind of modification is needed.
- Analysis — study the feasibility, impact, and cost of the change.
- Design — design the modification using the current system's documents and structure.
- Implementation — actually code the change into the system.
- System testing — test the changed module, its integration, and run regression tests so old features still work.
- Delivery — release the updated software to users (with updated manuals/training if needed).
Maintenance হলো delivery-র PORE software-এ করা সব কাজ। এটা সাধারণত lifecycle-এর সবচেয়ে লম্বা আর সবচেয়ে খরচের অংশ (মোট খরচের প্রায়ই 60% বা তার বেশি)। Maintenance-এর চারটা type:
- Corrective — release-এর পরে user-দের পাওয়া bug ঠিক করা। (Reactive: কিছু একটা ভেঙে আছে।)
- Adaptive — নতুন environment-এ software চালু রাখার জন্য বদলানো: নতুন OS, নতুন hardware, নতুন database, নতুন আইন বা tax-এর নিয়ম।
- Perfective — user-দের জন্য software ভালো করা: চাওয়া feature যোগ করা, আরও fast করা, report সুন্দর করা।
- Preventive — পরের সমস্যা এড়াতে এখনই পরিষ্কার করা: এলোমেলো code restructure করা, documentation update করা, dead code সরানো।
SMLC (Software Maintenance Life Cycle)-এর ছয়টা phase, order অনুযায়ী:
- Identification — change request নেওয়া আর কী ধরনের modification লাগবে তা identify করা।
- Analysis — change-টার feasibility, impact আর cost study করা।
- Design — চালু system-এর document আর structure দেখে modification-টা design করা।
- Implementation — change-টা আসলেই system-এ code করা।
- System testing — বদলানো module, তার integration test করা, আর পুরনো feature ঠিক আছে কি না দেখতে regression test চালানো।
- Delivery — updated software user-দের কাছে release করা (দরকার হলে updated manual/training সহ)।
2. Requirements Engineering2. Requirements Engineering
Requirements engineering is the process of finding out, writing down, checking, and managing what the software must do. Most failed projects fail here — the team built the wrong thing.
Main activities: elicitation (gathering), analysis (making sense, removing conflicts), specification (writing the SRS), validation (checking the requirements themselves), and management (handling changes later).
Requirements engineering হলো software-কে কী করতে হবে তা খুঁজে বের করা, লিখে রাখা, check করা আর manage করার process। বেশিরভাগ fail করা project এখানেই fail করে — team ভুল জিনিস বানিয়ে ফেলে।
মূল কাজগুলো: elicitation (তথ্য সংগ্রহ), analysis (বোঝা, conflict সরানো), specification (SRS লেখা), validation (requirement গুলোই ঠিক আছে কি না check করা), আর management (পরে change সামলানো)।
Functional vs Non-functional requirementsFunctional vs Non-functional requirements
Functional requirements (FR) say WHAT the system must do — its features and behaviors. Non-functional requirements (NFR) say HOW WELL it must do it — quality attributes like speed, security, usability. NFRs are often called quality requirements or "-ilities".
Functional requirement (FR) বলে system-কে কী করতে হবে — তার feature আর behavior। Non-functional requirement (NFR) বলে সেটা কত ভালোভাবে করতে হবে — speed, security, usability-র মতো quality। NFR-কে অনেক সময় quality requirement বা "-ilities" বলা হয়।
| Functional (WHAT)Functional (কী) | Non-functional (HOW WELL)Non-functional (কত ভালো) | |
|---|---|---|
| Meaningমানে | A service or behavior the system must provideSystem-কে যে service বা behavior দিতে হবে | A quality/constraint on how the system worksSystem কেমনভাবে কাজ করবে তার quality/constraint |
| ATM exampleATM example | "User can withdraw cash after entering a correct PIN.""সঠিক PIN দিলে user টাকা withdraw করতে পারবে।" | "Cash must be dispensed within 10 seconds.""১০ second-এর মধ্যে টাকা বের হতে হবে।" |
| E-commerce exampleE-commerce example | "System sends an email after each order.""প্রতিটা order-এর পরে system একটা email পাঠাবে।" | "Site must handle 10,000 users at once; 99.9% uptime.""Site-কে একসাথে ১০,০০০ user সামলাতে হবে; 99.9% uptime।" |
| Common typesCommon type | Login, search, report generation, paymentLogin, search, report generation, payment | Performance, security, reliability, usability, portability, maintainabilityPerformance, security, reliability, usability, portability, maintainability |
| Tested byকীভাবে test হয় | Functional testing (does the feature work?)Functional testing (feature কাজ করে?) | Performance/load/security testing (is it good enough?)Performance/load/security testing (যথেষ্ট ভালো?) |
Elicitation techniquesElicitation techniques
Elicitation = collecting requirements from stakeholders. Common techniques:
- Interviews — one-to-one talks with users/managers. Deep but slow.
- Questionnaires/surveys — many people, cheap, but shallow answers.
- Observation (ethnography) — watch users do their real work; catches things people forget to say.
- Workshops / brainstorming (JAD sessions) — all stakeholders in one room, fast agreement.
- Prototyping — show a mock version, users react to something concrete.
- Document analysis — read existing forms, reports, and old system manuals.
- Use cases / user stories — describe requirements as user–system interactions.
Elicitation = stakeholder-দের কাছ থেকে requirement সংগ্রহ করা। Common technique গুলো:
- Interview — user/manager-এর সাথে একা একা কথা বলা। গভীরে যাওয়া যায়, কিন্তু slow।
- Questionnaire/survey — অনেক মানুষ, সস্তা, কিন্তু উত্তর অগভীর।
- Observation (ethnography) — user-দের আসল কাজ করা দেখা; মানুষ যা বলতে ভুলে যায় তা ধরা পড়ে।
- Workshop / brainstorming (JAD session) — সব stakeholder এক ঘরে, দ্রুত ঐকমত্য।
- Prototyping — একটা mock version দেখানো, user concrete কিছু দেখে react করে।
- Document analysis — চালু form, report আর পুরনো system-এর manual পড়া।
- Use case / user story — user–system interaction হিসেবে requirement লেখা।
SRS — Software Requirements SpecificationSRS — Software Requirements Specification
The SRS is the official document that records all requirements. It is a contract between customer and developers. A good SRS is: correct, complete, consistent, unambiguous, verifiable, traceable, and modifiable.
Typical structure (based on IEEE 830):
- Introduction — purpose, scope, definitions, references.
- Overall description — product perspective, user classes, operating environment, constraints, assumptions.
- Specific requirements — all functional requirements (numbered, e.g., FR-1, FR-2), external interfaces, non-functional requirements (performance, security, etc.).
- Appendices and index.
SRS হলো official document যেখানে সব requirement লেখা থাকে। এটা customer আর developer-দের মধ্যে একটা contract। ভালো SRS হয়: correct, complete, consistent, unambiguous, verifiable, traceable, modifiable।
Typical structure (IEEE 830 অনুযায়ী):
- Introduction — purpose, scope, definition, reference।
- Overall description — product perspective, user class, operating environment, constraint, assumption।
- Specific requirements — সব functional requirement (number দিয়ে, যেমন FR-1, FR-2), external interface, non-functional requirement (performance, security ইত্যাদি)।
- Appendix আর index।
Requirements validationRequirements validation
Validation checks the requirements THEMSELVES before building anything. We ask: are they complete? consistent (no two requirements conflict)? realistic (can we build this with our budget/technology)? verifiable (can we test it later)?
Techniques: requirements reviews (a team reads the SRS line by line), prototyping (show users), and test-case generation (if you cannot write a test for a requirement, the requirement is too vague — e.g., "the system shall be fast" is not verifiable).
Validation-এ কিছু বানানোর আগেই requirement গুলোকেই check করা হয়। প্রশ্ন করি: complete তো? consistent তো (দুটো requirement-এ conflict নেই)? realistic তো (budget/technology দিয়ে বানানো সম্ভব)? verifiable তো (পরে test করা যাবে)?
Technique: requirements review (একটা team SRS লাইন ধরে ধরে পড়ে), prototyping (user-দের দেখানো), আর test-case generation (কোনো requirement-এর জন্য test লেখা না গেলে সেটা বেশি vague — যেমন "system fast হবে" verifiable না)।
Use cases — with a worked exampleUse case — worked example সহ
A use case describes one goal-oriented interaction between an actor (a user or external system) and the system. It has a main success flow and alternate/exception flows.
Use case হলো একজন actor (user বা বাইরের কোনো system) আর system-এর মধ্যে একটা goal-ভিত্তিক interaction-এর বর্ণনা। এতে একটা main success flow আর কিছু alternate/exception flow থাকে।
- Actors: Customer (primary), Bank server (secondary).
- Precondition: ATM has cash; customer has a valid card.
- Main flow:
- Customer inserts card.
- System asks for PIN; customer enters PIN.
- System verifies PIN with the bank server.
- Customer selects "Withdraw" and enters an amount.
- System checks balance and cash availability.
- System dispenses cash, prints receipt, returns card.
- Alternate flow A1 (wrong PIN): At step 3, if the PIN is wrong, system shows an error and re-asks. After 3 failures, system keeps the card and ends the use case.
- Alternate flow A2 (insufficient balance): At step 5, if balance is too low, system shows "insufficient funds" and returns to step 4.
- Postcondition: Account debited exactly by the dispensed amount.
- Actor: Customer (primary), Bank server (secondary)।
- Precondition: ATM-এ টাকা আছে; customer-এর valid card আছে।
- Main flow:
- Customer card ঢোকায়।
- System PIN চায়; customer PIN দেয়।
- System bank server দিয়ে PIN verify করে।
- Customer "Withdraw" select করে amount দেয়।
- System balance আর ATM-এর cash check করে।
- System টাকা দেয়, receipt print করে, card ফেরত দেয়।
- Alternate flow A1 (ভুল PIN): Step 3-এ PIN ভুল হলে system error দেখিয়ে আবার PIN চায়। ৩ বার ভুল হলে card রেখে দিয়ে use case শেষ করে।
- Alternate flow A2 (balance কম): Step 5-এ balance কম হলে system "insufficient funds" দেখিয়ে step 4-এ ফিরে যায়।
- Postcondition: ঠিক যত টাকা বের হয়েছে, account থেকে তত টাকাই কাটা হয়েছে।
3. UML and Design3. UML and Design
UML (Unified Modeling Language) is a standard set of diagrams for drawing software designs. Why model? Because a picture lets the whole team share one understanding, find design mistakes BEFORE coding, and document the system for the future. UML diagrams split into two families: structural (class, component, deployment) and behavioral (use case, sequence, activity, state).
UML (Unified Modeling Language) হলো software design আঁকার জন্য standard কিছু diagram। Model কেন করব? কারণ একটা ছবি দিয়ে পুরো team একই জিনিস বোঝে, coding-এর আগেই design-এর ভুল ধরা পড়ে, আর ভবিষ্যতের জন্য system-টা documented থাকে। UML diagram দুই দলে ভাগ হয়: structural (class, component, deployment) আর behavioral (use case, sequence, activity, state)।
Class diagramClass diagram
A class diagram shows classes and the relationships between them. Each class is a box with 3 parts: name, attributes, methods. Visibility marks: + public, - private, # protected, ~ package.
Attribute format: - balance : double. Method format: + deposit(amount : double) : void.
Class diagram দেখায় class গুলো আর তাদের মধ্যের relationship। প্রতিটা class হলো ৩ ভাগের একটা box: name, attribute, method। Visibility চিহ্ন: + public, - private, # protected, ~ package।
Attribute-এর format: - balance : double। Method-এর format: + deposit(amount : double) : void।
Relationships and their arrowsRelationship আর তাদের arrow
| RelationshipRelationship | NotationNotation | Meaningমানে | ExampleExample |
|---|---|---|---|
| Association | Plain line ——সাধারণ line —— | "knows / uses" — a general link"চেনে / ব্যবহার করে" — সাধারণ সম্পর্ক | Teacher — StudentTeacher — Student |
| Aggregation | Line with HOLLOW diamond ◇—HOLLOW diamond সহ line ◇— | "has-a", weak whole–part; part can live alone"has-a", দুর্বল whole–part; part একা বাঁচতে পারে | Team ◇— Player (player exists without team)Team ◇— Player (team ছাড়াও player থাকে) |
| Composition | Line with FILLED diamond ◆—FILLED diamond সহ line ◆— | "part-of", strong whole–part; part dies with the whole"part-of", শক্ত whole–part; whole গেলে part-ও যায় | House ◆— Room (delete house → rooms gone)House ◆— Room (house delete → room-ও শেষ) |
| Inheritance (generalization) | Line with HOLLOW triangle —▷ at parentParent-এর দিকে HOLLOW triangle —▷ | "is-a""is-a" | Dog —▷ AnimalDog —▷ Animal |
| Dependency | DASHED arrow - - ->DASHED arrow - - -> | "temporarily uses" (e.g., as a method parameter)"সাময়িকভাবে ব্যবহার করে" (যেমন method parameter হিসেবে) | OrderService - - -> EmailSenderOrderService - - -> EmailSender |
| Realization (implements) | DASHED line with hollow triangle - -▷DASHED line + hollow triangle - -▷ | Class implements an interfaceClass একটা interface implement করে | ArrayList - -▷ ListArrayList - -▷ List |
Use case diagramUse case diagram
A use case diagram gives a bird's-eye view: stick-figure actors outside a system boundary box, oval use cases inside, lines connecting actors to their use cases. Two special arrows: «include» (one use case ALWAYS uses another, e.g., "Withdraw Cash" includes "Verify PIN") and «extend» (optional extra behavior, e.g., "Print Receipt" extends "Withdraw Cash").
Use case diagram উপর থেকে পুরো ছবিটা দেখায়: system boundary box-এর বাইরে stick-figure actor, ভেতরে oval use case, আর actor-দের সাথে use case-এর সংযোগ line। দুটো special arrow: «include» (একটা use case সবসময় আরেকটা ব্যবহার করে, যেমন "Withdraw Cash" includes "Verify PIN") আর «extend» (optional বাড়তি behavior, যেমন "Print Receipt" extends "Withdraw Cash")।
Sequence diagram — worked exampleSequence diagram — worked example
A sequence diagram shows objects as vertical lifelines and messages as horizontal arrows, ordered top to bottom by TIME. Solid arrow = call, dashed arrow = return. The thin rectangles on lifelines (activation bars) show when an object is busy.
Sequence diagram-এ object গুলো লম্বালম্বি lifeline, আর message গুলো আড়াআড়ি arrow — উপরে থেকে নিচে TIME অনুযায়ী সাজানো। Solid arrow = call, dashed arrow = return। Lifeline-এর উপরের চিকন rectangle (activation bar) দেখায় object কখন busy।
Activity and State diagrams (briefly)Activity আর State diagram (সংক্ষেপে)
- Activity diagram: a flowchart of actions — rounded boxes for activities, diamond for decisions, bars for parallel (fork/join), filled circle for start, bullseye for end. Good for showing a business process or an algorithm's flow.
- State diagram (state machine): shows the STATES of ONE object and the events that move it between states. Example: an Order goes Created → Paid → Shipped → Delivered, with events like "payment received". Good for objects with clear life stages (order, connection, traffic light).
Quick memory: activity diagram = flow of a process; state diagram = life of an object; sequence diagram = messages over time between objects.
- Activity diagram: কাজের flowchart — activity-র জন্য rounded box, decision-এর জন্য diamond, parallel-এর জন্য bar (fork/join), শুরুতে ভরা circle, শেষে bullseye। Business process বা algorithm-এর flow দেখাতে ভালো।
- State diagram (state machine): একটা object-এর STATE গুলো আর কোন event-এ state বদলায় তা দেখায়। যেমন: একটা Order যায় Created → Paid → Shipped → Delivered, event যেমন "payment received"। যেসব object-এর পরিষ্কার জীবন-ধাপ আছে (order, connection, traffic light) তাদের জন্য ভালো।
সহজে মনে রাখো: activity diagram = একটা process-এর flow; state diagram = একটা object-এর জীবন; sequence diagram = object-দের মধ্যে সময় ধরে message।
Worked example: class diagram for an online shopping site (Real Exam Question!)Worked example: online shopping site-এর class diagram (Real Exam Question!)
BUET asked students to draw a class diagram for an online shopping site with classes like Customer, Order, Product, ShoppingCart, and Payment. Here is a clean model answer. First learn the relationships, then the picture:
BUET-এ online shopping site-এর class diagram আঁকতে বলা হয়েছিল — Customer, Order, Product, ShoppingCart, Payment এই class গুলো দিয়ে। নিচে একটা পরিষ্কার model answer। আগে relationship গুলো শেখো, তারপর ছবিটা:
| RelationshipRelationship | MultiplicityMultiplicity | Meaningমানে |
|---|---|---|
| Customer — Order | 1 — * | One customer places many orders; each order belongs to exactly one customer.এক customer অনেক order দেয়; প্রতিটা order ঠিক একজন customer-এর। |
| Order — Product (via OrderItem) | * — * | An order holds many products, a product appears in many orders — so we put an OrderItem class in between (with quantity and price). Order ◆— OrderItem is composition.এক order-এ অনেক product, এক product অনেক order-এ — তাই মাঝে একটা OrderItem class বসাই (quantity আর price সহ)। Order ◆— OrderItem হলো composition। |
| Customer — ShoppingCart | 1 — 1 | Each customer has exactly one active cart.প্রতিটা customer-এর ঠিক একটা active cart। |
| Order — Payment | 1 — 1 | Each order is settled by exactly one payment.প্রতিটা order ঠিক একটা payment দিয়ে মেটে। |
Worked example: state diagram for the order workflowWorked example: order workflow-এর state diagram
The same BUET question also asked for a state diagram of the shopping workflow. Model ONE object — the Order — and show its states and the events that move it:
একই BUET প্রশ্নে shopping workflow-এর একটা state diagram-ও চাওয়া হয়েছিল। একটা object — Order — ধরে তার state গুলো আর কোন event-এ state বদলায় তা দেখাও:
4. Software Testing4. Software Testing
Testing means running the software with the goal of FINDING defects. Testing can show that bugs exist — it can never prove there are zero bugs (Dijkstra's famous point).
Testing মানে defect খুঁজে বের করার লক্ষ্যে software চালানো। Testing দেখাতে পারে bug আছে — কিন্তু bug একটাও নেই, এটা কখনো প্রমাণ করতে পারে না (Dijkstra-র বিখ্যাত কথা)।
Testing levelsTesting level
- Unit testing — test one function/class alone. Done by developers. Example: test that
withdraw()rejects a negative amount. - Integration testing — test that modules work TOGETHER (interfaces between them). Approaches: big bang (join everything at once), top-down (use stubs for missing lower modules), bottom-up (use drivers for missing upper modules).
- System testing — test the whole finished system against the SRS, in an environment like production.
- Acceptance testing — the CUSTOMER tests whether the system meets their needs. Includes alpha testing (at the developer's site, controlled) and beta testing (at real users' sites, real environment).
- Unit testing — একটা function/class আলাদা করে test করা। Developer-রা করে। যেমন:
withdraw()negative amount reject করে কি না। - Integration testing — module গুলো একসাথে কাজ করে কি না (তাদের মধ্যের interface) test করা। উপায়: big bang (সব একসাথে জোড়া), top-down (নিচের missing module-এর জায়গায় stub), bottom-up (উপরের missing module-এর জায়গায় driver)।
- System testing — পুরো system-কে SRS-এর সাথে মিলিয়ে test করা, production-এর মতো environment-এ।
- Acceptance testing — CUSTOMER নিজে test করে system তার দরকার মেটায় কি না। এর মধ্যে alpha testing (developer-এর জায়গায়, controlled) আর beta testing (আসল user-দের জায়গায়, real environment)।
Black box vs White boxBlack box vs White box
| Black box testingBlack box testing | White box testingWhite box testing | |
|---|---|---|
| Looks atকী দেখে | Inputs and outputs only; code is hiddenশুধু input আর output; code দেখা যায় না | The internal code and structureভেতরের code আর structure |
| Based onভিত্তি | Requirements / specificationRequirement / specification | Source code paths and branchesSource code-এর path আর branch |
| TechniquesTechnique | Equivalence partitioning, boundary value analysis, decision tablesEquivalence partitioning, boundary value analysis, decision table | Statement / branch / path coverage, loop testingStatement / branch / path coverage, loop testing |
| Done byকারা করে | Testers (no code knowledge needed)Tester-রা (code জানা লাগে না) | DevelopersDeveloper-রা |
| Typical levelTypical level | System / acceptance testingSystem / acceptance testing | Unit testingUnit testing |
Equivalence partitioning + Boundary value analysisEquivalence partitioning + Boundary value analysis
Equivalence partitioning (EP): split the input space into groups (partitions) where every value in a group should behave the SAME. Test just one value per group — no need to test all.
Boundary value analysis (BVA): bugs love edges. Test the values AT and NEXT TO each boundary: for a range [min, max], test min−1, min, min+1, max−1, max, max+1 (a lighter version uses min, max and one middle value).
Equivalence partitioning (EP): input-এর জগৎটাকে কিছু দলে (partition) ভাগ করো, যেখানে এক দলের সব value-র behavior একই হওয়ার কথা। প্রতি দল থেকে মাত্র একটা value test করো — সব test করার দরকার নেই।
Boundary value analysis (BVA): bug থাকে কিনারায়। প্রতিটা boundary-র উপর আর ঠিক পাশের value test করো: range [min, max]-এর জন্য min−1, min, min+1, max−1, max, max+1 (হালকা version-এ min, max আর মাঝের একটা value)।
- EP partitions: P1 = valid (0–100), P2 = invalid low (< 0), P3 = invalid high (> 100). → 3 test cases, e.g., 50, −5, 150.
- BVA values: boundaries are 0 and 100 → test −1, 0, 1 and 99, 100, 101 → 6 test cases.
- Combined smart set: {−1, 0, 1, 50, 99, 100, 101}.
- EP partition: P1 = valid (0–100), P2 = invalid low (< 0), P3 = invalid high (> 100)। → ৩টা test case, যেমন 50, −5, 150।
- BVA value: boundary হলো 0 আর 100 → test করো −1, 0, 1 আর 99, 100, 101 → ৬টা test case।
- দুটো মিলিয়ে smart set: {−1, 0, 1, 50, 99, 100, 101}।
Statement, branch, and path coverageStatement, branch, path coverage
Coverage measures how much of the code your tests actually exercised.
- Statement coverage: every line runs at least once.
- Branch (decision) coverage: every decision (if/while) takes BOTH the true and false way at least once. Stronger than statement coverage.
- Path coverage: every possible route through the code runs. Strongest, but paths explode fast (2 independent ifs → 4 paths).
Coverage মাপে তোমার test আসলে কতটুকু code চালিয়েছে।
- Statement coverage: প্রতিটা line অন্তত একবার চলে।
- Branch (decision) coverage: প্রতিটা decision (if/while)-এর true আর false — দুই দিকই অন্তত একবার চলে। Statement coverage-এর চেয়ে শক্ত।
- Path coverage: code-এর ভেতর দিয়ে সম্ভব সব route চলে। সবচেয়ে শক্ত, কিন্তু path খুব দ্রুত বাড়ে (২টা আলাদা if → ৪টা path)।
int max3(int a, int b, int c) {
int m = a; // S1
if (b > m) m = b; // D1
if (c > m) m = c; // D2
return m; // S2
}
- Statement coverage: ONE test where both ifs are true covers all lines. E.g., (a,b,c) = (1,2,3). → 1 test case.
- Branch coverage: D1 and D2 each need true AND false. Test 1: (1,2,3) → D1 true, D2 true. Test 2: (3,2,1) → D1 false, D2 false. → 2 test cases.
- Path coverage: paths = TT, TF, FT, FF → 4 test cases, e.g., (1,2,3), (1,3,2), (2,1,3), (3,2,1).
- Statement coverage: দুটো if-ই true হয় এমন একটা test-এই সব line চলে। যেমন (a,b,c) = (1,2,3)। → ১টা test case।
- Branch coverage: D1 আর D2 দুটোরই true এবং false লাগবে। Test 1: (1,2,3) → D1 true, D2 true। Test 2: (3,2,1) → D1 false, D2 false। → ২টা test case।
- Path coverage: path = TT, TF, FT, FF → ৪টা test case, যেমন (1,2,3), (1,3,2), (2,1,3), (3,2,1)।
Verification vs Validation, regression, alpha/betaVerification vs Validation, regression, alpha/beta
- Verification: "Are we building the product RIGHT?" — checking the work against the design/spec at each phase (reviews, inspections, walkthroughs; mostly static, done during development).
- Validation: "Are we building the RIGHT product?" — checking the finished product against the USER's real needs (actual testing, mostly dynamic).
- Regression testing: after any change or bug fix, RE-RUN old tests to make sure previously working features did not break. Usually automated.
- Alpha testing: by internal users/testers at the developer's site, before release.
- Beta testing: by real external users at their own sites, on a near-final version.
- Verification: "আমরা কি product-টা ঠিকভাবে বানাচ্ছি?" — প্রতিটা phase-এ design/spec-এর সাথে কাজ মিলিয়ে দেখা (review, inspection, walkthrough; বেশিরভাগ static, development চলার সময়ে)।
- Validation: "আমরা কি ঠিক product-টাই বানাচ্ছি?" — শেষ হওয়া product USER-এর আসল দরকারের সাথে মেলে কি না দেখা (আসল testing, বেশিরভাগ dynamic)।
- Regression testing: কোনো change বা bug fix-এর পরে পুরনো test গুলো আবার চালানো, আগের কাজ করা feature ভাঙেনি তো — এটা দেখতে। সাধারণত automated।
- Alpha testing: developer-এর জায়গায় internal user/tester দিয়ে, release-এর আগে।
- Beta testing: বাইরের আসল user-রা নিজেদের জায়গায়, প্রায়-final version-এ।
5. Software Architecture & Design Principles5. Software Architecture & Design Principles
Software architecture is the high-level structure of a system: its main parts and how they talk to each other. Common architectural styles:
- Layered: code stacked in layers (presentation → business logic → data access → database). Each layer only calls the layer below. Easy to understand and replace layers; can be slow if a request must pass through many layers.
- Client–server: many clients request services from a central server (web browser ↔ web server). Central control and data, but the server is a bottleneck and single point of failure.
- MVC (Model–View–Controller): splits an interactive app into Model (data + business rules), View (what the user sees), Controller (receives user input, updates model, picks the view). One model can have many views; UI and logic change independently.
- Monolith vs Microservices: a monolith is one big deployable unit — simple to build/test/deploy at first, but hard to scale and one bug can crash everything. Microservices split the system into small independent services, each with its own database, talking over the network (HTTP/queues) — independent scaling and deployment, but complex operations, network latency, and hard distributed debugging.
Software architecture হলো system-এর high-level গঠন: তার প্রধান অংশগুলো আর তারা কীভাবে কথা বলে। Common architectural style:
- Layered: code স্তরে স্তরে সাজানো (presentation → business logic → data access → database)। প্রতিটা layer শুধু নিচের layer-কে ডাকে। বোঝা আর layer বদলানো সহজ; অনেক layer পার হতে হলে slow হতে পারে।
- Client–server: অনেক client একটা central server থেকে service চায় (web browser ↔ web server)। Control আর data এক জায়গায়, কিন্তু server হলো bottleneck আর single point of failure।
- MVC (Model–View–Controller): interactive app-কে তিন ভাগ করে: Model (data + business rule), View (user যা দেখে), Controller (user input নেয়, model update করে, view বাছে)। এক model-এর অনেক view হতে পারে; UI আর logic আলাদাভাবে বদলানো যায়।
- Monolith vs Microservices: Monolith মানে একটাই বড় deployable unit — শুরুতে বানানো/test/deploy সহজ, কিন্তু scale করা কঠিন আর একটা bug-এ সব crash করতে পারে। Microservices-এ system ছোট ছোট independent service-এ ভাগ হয়, প্রতিটার নিজের database, network-এ (HTTP/queue) কথা বলে — আলাদা scaling আর deployment, কিন্তু operation জটিল, network latency, আর distributed debugging কঠিন।
Coupling and cohesionCoupling আর cohesion
Coupling = how much modules depend on EACH OTHER. Cohesion = how strongly the parts INSIDE one module belong together. Design goal (memorize this): LOW coupling, HIGH cohesion. Then a change in one module barely touches others, and each module is easy to understand, test, and reuse.
Coupling = module গুলো একে অপরের উপর কতটা নির্ভর করে। Cohesion = এক module-এর ভেতরের জিনিসগুলো কতটা একসাথে মানায়। Design-এর goal (মুখস্থ করো): LOW coupling, HIGH cohesion। তাহলে এক module বদলালে অন্যরা প্রায় টেরই পায় না, আর প্রতিটা module বোঝা, test করা, reuse করা সহজ হয়।
| Coupling type (worst → best)Coupling type (খারাপ → ভালো) | Meaningমানে | ExampleExample |
|---|---|---|
| Content | One module directly edits another's internal code/dataএক module আরেকটার ভেতরের code/data সরাসরি বদলায় | Module A jumps into B's code or patches B's private variableA, B-এর code-এ ঢুকে যায় বা B-এর private variable বদলায় |
| Common | Modules share the same global dataModule-রা একই global data শেয়ার করে | Everyone reads/writes one global config variableসবাই একটা global config variable পড়ে/লেখে |
| Control | One module passes a flag that controls the other's logicএক module একটা flag পাঠায় যা অন্যটার logic ঠিক করে | print(data, mode=2) — mode decides what the function doesprint(data, mode=2) — mode ঠিক করে function কী করবে |
| Stamp | Passing a whole structure when only a part is neededশুধু একটা অংশ দরকার, তবু পুরো structure পাঠানো | Passing full Student record to a function that needs only the idশুধু id দরকার এমন function-এ পুরো Student record পাঠানো |
| Data | Modules share only simple data as parameters — BEST practical couplingModule-রা শুধু simple data parameter হিসেবে দেয় — practical-এ সবচেয়ে ভালো | add(a, b) — only the needed values are passedadd(a, b) — শুধু দরকারি value পাঠানো হয় |
Cohesion types, best → worst: functional (module does exactly one task — best), sequential (output of one part feeds the next), communicational (parts work on the same data), procedural, temporal (things done "at the same time", e.g., init), logical (similar-looking tasks lumped together), coincidental (random unrelated stuff — worst, e.g., a "Utils" class holding date parsing + email + tax math).
Cohesion type, ভালো → খারাপ: functional (module ঠিক একটা কাজ করে — best), sequential (এক অংশের output পরের অংশের input), communicational (সব অংশ একই data নিয়ে কাজ করে), procedural, temporal ("একই সময়ে" করা কাজ, যেমন init), logical (দেখতে একরকম কাজ এক জায়গায়), coincidental (এলোমেলো সম্পর্কহীন জিনিস — worst, যেমন এক "Utils" class-এ date parsing + email + tax হিসাব)।
- Write tests FIRST. Before touching anything, put tests around the current behavior (at least the important paths). Refactoring means changing structure WITHOUT changing behavior — tests prove you did not break it.
- Group by responsibility. Sort the functions by what they are about (orders, payments, users, reports...). Move each group into its own module/class → this raises cohesion.
- Remove duplication (DRY). Merge the copy-pasted functions into one shared function each — 1000 functions usually shrink a lot here.
- Layer the code. Split UI code, business logic, and data access into layers; each layer only calls the layer below.
- Put interfaces at the seams. Modules talk through small interfaces and pass only the data they need → this lowers coupling, and lets you test or swap one part alone.
- আগে test লেখো। কিছুতে হাত দেওয়ার আগে এখনকার behavior ঘিরে test বসাও (অন্তত গুরুত্বপূর্ণ path-গুলোতে)। Refactoring মানে behavior না বদলে structure বদলানো — test-ই প্রমাণ করবে কিছু ভাঙোনি।
- Responsibility অনুযায়ী group করো। Function-গুলো কী নিয়ে কাজ করে সেই হিসেবে ভাগ করো (order, payment, user, report...)। প্রতিটা group-কে নিজের module/class-এ নাও → এতে cohesion বাড়ে।
- Duplication সরাও (DRY)। Copy-paste করা function-গুলো এক করে একটা shared function বানাও — ১০০০ function এখানেই অনেক কমে যায়।
- Code-কে layer করো। UI code, business logic আর data access আলাদা layer-এ ভাগ করো; প্রতিটা layer শুধু নিচের layer-কে ডাকবে।
- জোড়ার জায়গায় interface বসাও। Module-রা ছোট interface দিয়ে কথা বলবে, শুধু দরকারি data পাঠাবে → এতে coupling কমে, আর এক-একটা অংশ আলাদা করে test বা বদলানো যায়।
SOLID principlesSOLID principles
- S — Single Responsibility: a class should have ONE reason to change. Bad:
Reportclass that computes data AND prints AND saves to DB. Good: split intoReportData,ReportPrinter,ReportSaver. - O — Open/Closed: open for extension, closed for modification. Bad: a big
if (shape == "circle") ... else if (shape == "square")that must be edited for every new shape. Good: each shape class has its ownarea(); adding a shape adds a class, touches no old code. - L — Liskov Substitution: a subclass must be usable anywhere its parent is expected, without surprises. Classic violation:
Square extends RectanglebutsetWidth()secretly changes height too — code written for Rectangle breaks. - I — Interface Segregation: many small interfaces beat one fat one. Bad:
Machineinterface withprint(), scan(), fax()forces a simple printer to implement fax. Good: separatePrinter,Scanner,Faxinterfaces. - D — Dependency Inversion: depend on abstractions (interfaces), not concrete classes. Bad:
OrderServicecreatesnew MySQLDatabase()inside. Good: it receives aDatabaseinterface — swapping MySQL for Postgres or a test mock needs no change to OrderService.
DRY — Don't Repeat Yourself: one piece of knowledge lives in ONE place; copy-pasted logic means every bug must be fixed twice. KISS — Keep It Simple, Stupid: the simplest design that works beats a clever complicated one.
- S — Single Responsibility: একটা class-এর বদলানোর কারণ একটাই হবে। খারাপ:
Reportclass একই সাথে data হিসাব করে, print করে, DB-তে save করে। ভালো: ভাগ করোReportData,ReportPrinter,ReportSaver-এ। - O — Open/Closed: extension-এর জন্য খোলা, modification-এর জন্য বন্ধ। খারাপ: বড় একটা
if (shape == "circle") ... else if (shape == "square"), নতুন shape এলেই edit করতে হয়। ভালো: প্রতিটা shape class-এর নিজেরarea(); নতুন shape মানে নতুন class, পুরনো code-এ হাত নেই। - L — Liskov Substitution: parent যেখানে চলে, subclass-ও সেখানে কোনো surprise ছাড়া চলতে হবে। Classic ভুল:
Square extends Rectangle, কিন্তুsetWidth()চুপিচুপি height-ও বদলায় — Rectangle-এর জন্য লেখা code ভেঙে যায়। - I — Interface Segregation: একটা মোটা interface-এর চেয়ে অনেকগুলো ছোট interface ভালো। খারাপ:
Machineinterface-এprint(), scan(), fax()— simple printer-কেও fax implement করতে হয়। ভালো: আলাদাPrinter,Scanner,Faxinterface। - D — Dependency Inversion: concrete class না, abstraction (interface)-এর উপর নির্ভর করো। খারাপ:
OrderServiceভেতরেnew MySQLDatabase()বানায়। ভালো: সে একটাDatabaseinterface নেয় — MySQL বদলে Postgres বা test mock দিলেও OrderService-এ হাত দিতে হয় না।
DRY — Don't Repeat Yourself: এক টুকরো knowledge এক জায়গাতেই থাকবে; copy-paste করা logic মানে প্রতিটা bug দুই জায়গায় fix করতে হবে। KISS — Keep It Simple, Stupid: কাজ করে এমন সবচেয়ে simple design-ই চালাক-জটিল design-এর চেয়ে ভালো।
Design patterns introDesign pattern-এর intro
A design pattern is a reusable, named solution to a common design problem. Three famous ones:
Singleton (creational): make sure a class has exactly ONE instance, with a global access point. Used for configs, loggers, connection pools.
Design pattern হলো common design problem-এর একটা reusable, নাম-দেওয়া সমাধান। বিখ্যাত ৩টা:
Singleton (creational): নিশ্চিত করে একটা class-এর instance ঠিক একটাই হবে, আর সেটায় global access থাকবে। Config, logger, connection pool-এ ব্যবহার হয়।
class Logger {
private static Logger instance; // the only one
private Logger() {} // nobody else can create
public static Logger getInstance() {
if (instance == null) instance = new Logger();
return instance;
}
}
Factory Method (creational): let a factory decide WHICH concrete class to create, so the caller never writes new ConcreteClass() itself.
Factory Method (creational): কোন concrete class বানানো হবে সেটা factory ঠিক করে, তাই caller-কে নিজে কখনো new ConcreteClass() লিখতে হয় না।
Shape createShape(String type) {
if (type.equals("circle")) return new Circle();
if (type.equals("square")) return new Square();
throw new IllegalArgumentException(type);
}
// caller: Shape s = createShape("circle"); s.draw();
Observer (behavioral): one subject keeps a list of observers; when the subject's state changes, it notifies all of them. This is the idea behind event listeners, notifications, and MVC's model→view updates.
Observer (behavioral): একটা subject কিছু observer-এর list রাখে; subject-এর state বদলালে সে সবাইকে notify করে। Event listener, notification, আর MVC-র model→view update-এর পেছনের idea এটাই।
interface Observer { void update(float temp); }
class WeatherStation { // subject
private List<Observer> obs = new ArrayList<>();
void attach(Observer o) { obs.add(o); }
void setTemp(float t) {
for (Observer o : obs) o.update(t); // notify all
}
}
Worked example: Strategy Pattern for sorting (Real Exam Question!)Worked example: sorting-এর জন্য Strategy Pattern (Real Exam Question!)
Strategy (behavioral): define a family of algorithms, put each one in its own class behind ONE common interface, and let the client swap them at runtime. Classic example: a Sorter that can use QuickSort or MergeSort without changing its own code.
Strategy (behavioral): একগুচ্ছ algorithm-কে একটাই common interface-এর পেছনে আলাদা আলাদা class-এ রাখো, আর client runtime-এ সেগুলো swap করতে পারে। Classic example: একটা Sorter যে নিজের code না বদলে QuickSort বা MergeSort ব্যবহার করতে পারে।
interface SortStrategy { // the common interface
void sort(int[] a);
}
class QuickSort implements SortStrategy { // concrete strategy 1
public void sort(int[] a) { /* quicksort logic */ }
}
class MergeSort implements SortStrategy { // concrete strategy 2
public void sort(int[] a) { /* mergesort logic */ }
}
class Sorter { // the CONTEXT
private SortStrategy strategy;
Sorter(SortStrategy s) { strategy = s; }
void setStrategy(SortStrategy s) { strategy = s; } // swap at runtime
void sortData(int[] a) { strategy.sort(a); }
}
// usage:
Sorter sorter = new Sorter(new QuickSort());
sorter.sortData(data); // sorts with quicksort
sorter.setStrategy(new MergeSort());
sorter.sortData(data); // now mergesort — Sorter unchanged
When to use it: (1) you need to pick the algorithm at runtime — e.g., small array → insertion sort, huge array → merge sort; (2) you want to add new algorithms WITHOUT touching old code — that is exactly the Open/Closed principle: a new algorithm is just one new class; (3) you want to replace a big if/else chain that chooses behavior.
কখন ব্যবহার করবে: (১) algorithm-টা runtime-এ বাছতে হলে — যেমন ছোট array → insertion sort, বিশাল array → merge sort; (২) পুরনো code-এ হাত না দিয়ে নতুন algorithm যোগ করতে চাইলে — এটাই Open/Closed principle: নতুন algorithm মানে শুধু একটা নতুন class; (৩) behavior বাছাই করা বড় if/else chain সরাতে চাইলে।
6. Information Systems Design Basics6. Information Systems Design Basics
An Information System (IS) is a combination of people, hardware, software, data, and processes that collects, stores, processes, and delivers information to support decisions in an organization. Software is just one part — the people and business processes matter too.
Information System (IS) হলো people, hardware, software, data আর process-এর মিলিত রূপ, যা organization-এর decision-এ সাহায্য করার জন্য information সংগ্রহ, store, process আর deliver করে। Software এর মাত্র একটা অংশ — মানুষ আর business process-ও সমান জরুরি।
Types of IS — the pyramidIS-এর type — pyramid
Different levels of an organization use different systems. From bottom (daily operations) to top (strategy):
- TPS (Transaction Processing System): records routine daily transactions — sales entry, ATM transactions, payroll, billing. Used by operational staff. Huge volume, simple decisions.
- MIS (Management Information System): takes TPS data and produces regular summary reports (weekly sales report, monthly production report) for middle managers.
- DSS (Decision Support System): interactive, model-based analysis for semi-structured decisions — "what happens to profit if we cut price 5%?". Used by managers/analysts.
- ESS / EIS (Executive Support System): dashboards of key indicators plus external data (market trends) for TOP executives making long-term strategic decisions.
Organization-এর আলাদা level আলাদা system ব্যবহার করে। নিচ (দৈনন্দিন কাজ) থেকে উপরে (strategy):
- TPS (Transaction Processing System): রোজকার routine transaction লেখে — sales entry, ATM transaction, payroll, billing। Operational staff-রা চালায়। বিশাল volume, simple decision।
- MIS (Management Information System): TPS-এর data নিয়ে নিয়মিত summary report বানায় (সাপ্তাহিক sales report, মাসিক production report) — middle manager-দের জন্য।
- DSS (Decision Support System): semi-structured decision-এর জন্য interactive, model-ভিত্তিক analysis — "দাম 5% কমালে profit-এর কী হবে?"। Manager/analyst-রা ব্যবহার করে।
- ESS / EIS (Executive Support System): key indicator-এর dashboard + বাইরের data (market trend) — TOP executive-দের long-term strategic decision-এর জন্য।
Feasibility studyFeasibility study
Before starting a project, we check whether it is even worth doing. Main feasibility types:
- Technical feasibility: can we build it with available technology and skills?
- Economic feasibility: do the benefits beat the costs? (cost–benefit analysis)
- Operational feasibility: will people actually use it? does it fit how the organization works?
- Schedule feasibility: can we finish in the required time?
- Legal feasibility: does it break any law or regulation (data privacy etc.)?
Project শুরুর আগে দেখা হয় এটা করা আদৌ ঠিক হবে কি না। মূল feasibility type:
- Technical feasibility: হাতের technology আর skill দিয়ে বানানো যাবে?
- Economic feasibility: লাভ কি খরচের চেয়ে বেশি? (cost–benefit analysis)
- Operational feasibility: মানুষ আসলেই এটা ব্যবহার করবে? Organization-এর কাজের ধরনের সাথে মিলবে?
- Schedule feasibility: দরকারি সময়ের মধ্যে শেষ করা যাবে?
- Legal feasibility: কোনো আইন বা regulation (data privacy ইত্যাদি) ভাঙছে না তো?
Cost estimation: LOC, Function Points, COCOMOCost estimation: LOC, Function Points, COCOMO
How big/costly will the software be?
- LOC (Lines of Code): estimate size in (kilo) lines of code. Simple, but depends on language and coding style, and is hard to guess early.
- Function Points (FP): measure functionality instead of lines — count inputs, outputs, user inquiries, internal files, external interfaces, weight each by complexity, then adjust. Language-independent and usable early.
- COCOMO (Constructive Cost Model), by Boehm: converts size (KLOC) into effort and time.
Basic COCOMO formulas:
Software কত বড়/কত খরচের হবে?
- LOC (Lines of Code): size মাপা হয় (kilo) line of code-এ। Simple, কিন্তু language আর coding style-এর উপর নির্ভর করে, আর শুরুতে আন্দাজ করা কঠিন।
- Function Points (FP): line না গুনে functionality মাপে — input, output, user inquiry, internal file, external interface গুনে complexity অনুযায়ী weight দিয়ে adjust করা হয়। Language-independent, আর শুরুর দিকেই ব্যবহার করা যায়।
- COCOMO (Constructive Cost Model), Boehm-এর দেওয়া: size (KLOC) থেকে effort আর time বের করে।
Basic COCOMO-র formula:
| Project typeProject type | a | b | c | d | Meaningমানে |
|---|---|---|---|---|---|
| Organic | 2.4 | 1.05 | 2.5 | 0.38 | Small team, familiar simple problemছোট team, চেনা simple problem |
| Semi-detached | 3.0 | 1.12 | 2.5 | 0.35 | Medium size, mixed experienceমাঝারি size, মিশ্র experience |
| Embedded | 3.6 | 1.20 | 2.5 | 0.32 | Tight hardware/rules constraints (e.g., avionics)কড়া hardware/নিয়মের constraint (যেমন avionics) |
- Effort \(= 2.4 \times 32^{1.05} \approx 2.4 \times 38.0 \approx 91.3\) person-months.
- Time \(= 2.5 \times 91.3^{0.38} \approx 2.5 \times 5.6 \approx 13.9\) months.
- Average staff \(= 91.3 / 13.9 \approx 6.6 \approx 7\) people.
- Effort \(= 2.4 \times 32^{1.05} \approx 2.4 \times 38.0 \approx 91.3\) person-month।
- Time \(= 2.5 \times 91.3^{0.38} \approx 2.5 \times 5.6 \approx 13.9\) month।
- গড় staff \(= 91.3 / 13.9 \approx 6.6 \approx 7\) জন।
Business Logic Design (Real Exam Question!)Business Logic Design (Real Exam Question!)
Business logic (also called domain logic) is the part of the software that encodes the REAL rules of the business: calculations, decisions, and workflows. It is NOT the UI (screens, buttons) and NOT the data access (SQL, files) — it is the "thinking" in between. Examples of business rules: "orders of 5000 Tk or more get a 10% discount", "a loan above 1 lakh needs manager approval", "stock can never go below zero".
Where it lives: in a 3-tier / layered design, business logic sits in the MIDDLE layer — the service layer / domain model — between the presentation (UI) layer and the data access layer. Kept there, you can change the UI or swap the database without rewriting the rules, and you can test the rules alone.
How it is implemented:
- Service classes: one class per workflow — e.g.,
OrderService.placeOrder()runs validation, discount, and stock update as one unit. - Domain entities: objects like
OrderorAccountcarry their own small rules — e.g.,order.subtotal()knows how to add its lines. - Rule engines / config: rules that change often (discount rates, limits) are stored as data, so they can be updated without redeploying code.
Business logic (domain logic-ও বলে) হলো software-এর সেই অংশ যেখানে business-এর আসল নিয়মগুলো থাকে: calculation, decision আর workflow। এটা UI না (screen, button), data access-ও না (SQL, file) — মাঝখানের "চিন্তা করা" অংশটা। Business rule-এর example: "৫০০০ টাকা বা তার বেশি order-এ 10% discount", "১ লাখের উপরে loan-এ manager-এর approval লাগবে", "stock কখনো শূন্যের নিচে যাবে না"।
কোথায় থাকে: 3-tier / layered design-এ business logic থাকে মাঝের layer-এ — service layer / domain model-এ — presentation (UI) layer আর data access layer-এর মাঝখানে। ওখানে রাখলে UI বদলালে বা database swap করলে নিয়মগুলো আবার লিখতে হয় না, আর নিয়মগুলো আলাদা করে test করা যায়।
কীভাবে implement হয়:
- Service class: প্রতি workflow-র জন্য একটা class — যেমন
OrderService.placeOrder()validation, discount আর stock update একসাথে চালায়। - Domain entity:
OrderবাAccount-এর মতো object নিজের ছোট নিয়ম নিজে রাখে — যেমনorder.subtotal()জানে তার line-গুলো কীভাবে যোগ হবে। - Rule engine / config: যেসব নিয়ম ঘন ঘন বদলায় (discount rate, limit), সেগুলো data হিসেবে রাখা হয়, যাতে code redeploy না করেই বদলানো যায়।
// 3-tier: UI layer -> business logic layer -> data access layer
class OrderService { // business logic (service layer)
double totalPayable(Order o) {
double sum = o.subtotal(); // domain entity does its own part
if (sum >= 5000)
sum = sum * 0.90; // business RULE: 10% discount
return sum;
}
}
// The UI layer only DISPLAYS totalPayable().
// The data layer only SAVES the order.
// The rule lives in ONE place — change the discount, touch one line.
Practice Questions (Admission Style)Practice Questions (Admission Style)
Show Answerউত্তর দেখুন
Show Answerউত্তর দেখুন
Show Answerউত্তর দেখুন
Show Answerউত্তর দেখুন
Show Answerউত্তর দেখুন
Show Answerউত্তর দেখুন
Show Answerউত্তর দেখুন
Report computes statistics, formats them as HTML, AND saves them to a database. Which SOLID principle does it break most directly?
Report class statistics হিসাব করে, HTML-এ format করে, আবার database-এও save করে। এটা সবচেয়ে সরাসরি কোন SOLID principle ভাঙছে?
Show Answerউত্তর দেখুন
Show Answerউত্তর দেখুন
Show Answerউত্তর দেখুন
Show Answerউত্তর দেখুন
- Actors: Member (primary), Librarian (primary).
- Precondition: Member has a valid membership; the book copy exists in the library.
- Main flow: 1. Member brings the book to the desk. 2. Librarian scans the member card; system shows the member's record. 3. Librarian scans the book; system checks the member's limit (max 3 books) and any unpaid fines. 4. System records the loan with a 14-day due date. 5. System marks the copy "borrowed" and prints a due-date slip.
- Alternate flow A1 (limit reached): At step 3, if the member already holds 3 books, the system rejects the loan and shows the list of books to return; use case ends.
- Postcondition: Loan is stored; book copy is marked unavailable to others.
- Actor: Member (primary), Librarian (primary)।
- Precondition: Member-এর valid membership আছে; বইয়ের copy library-তে আছে।
- Main flow: 1. Member বইটা desk-এ আনে। 2. Librarian member card scan করে; system member-এর record দেখায়। 3. Librarian বই scan করে; system member-এর limit (সর্বোচ্চ ৩টা বই) আর বাকি fine check করে। 4. System ১৪ দিনের due date দিয়ে loan record করে। 5. System copy-টাকে "borrowed" mark করে due-date slip print করে।
- Alternate flow A1 (limit শেষ): Step 3-এ member-এর কাছে আগেই ৩টা বই থাকলে system loan reject করে ফেরত দেওয়ার বইয়ের list দেখায়; use case শেষ।
- Postcondition: Loan save হয়েছে; বইয়ের copy অন্যদের জন্য unavailable।
Show Answerউত্তর দেখুন
> 18 instead of >= 18) are caught exactly here.>= 18-এর জায়গায় > 18 লেখা) ঠিক এখানেই ধরা পড়ে।void f(int x, int y) {
if (x > 0) print("A"); // D1
if (y > 0) print("B"); // D2
print("done");
}void f(int x, int y) {
if (x > 0) print("A"); // D1
if (y > 0) print("B"); // D2
print("done");
}Show Answerউত্তর দেখুন
Show Answerউত্তর দেখুন
- Effort \(= 3.0 \times 50^{1.12}\). Since \(50^{1.12} \approx 79.9\), Effort \(\approx 3.0 \times 79.9 \approx 240\) person-months.
- Time \(= 2.5 \times 240^{0.35} \approx 2.5 \times 6.8 \approx 17\) months.
- Average staff \(= 240 / 17 \approx 14\) people.
- Effort \(= 3.0 \times 50^{1.12}\)। যেহেতু \(50^{1.12} \approx 79.9\), Effort \(\approx 3.0 \times 79.9 \approx 240\) person-month।
- Time \(= 2.5 \times 240^{0.35} \approx 2.5 \times 6.8 \approx 17\) month।
- গড় staff \(= 240 / 17 \approx 14\) জন।
Utils contains date formatting, tax calculation, and email sending. It also reads a global variable appConfig that five other modules write to. (i) Name the cohesion type of Utils and the coupling type caused by appConfig. (ii) Explain why this design is bad. (iii) Propose a better design.Utils-এ আছে date formatting, tax calculation আর email পাঠানো। সে আবার একটা global variable appConfig পড়ে, যেটায় আরও পাঁচটা module লেখে। (i) Utils-এর cohesion type আর appConfig-এর কারণে হওয়া coupling type-এর নাম বলো। (ii) এই design খারাপ কেন, ব্যাখ্যা করো। (iii) আরও ভালো design প্রস্তাব করো।Show Answerউত্তর দেখুন
Utils has coincidental cohesion (the worst kind — unrelated tasks lumped together). The shared global appConfig creates common coupling. (ii) It is bad because: a change to tax rules forces retesting date and email code too; the module cannot be reused (who wants tax + email together?); and with common coupling, ANY of the six modules writing appConfig can silently break the others — bugs become very hard to trace. (iii) Better: split into three functionally cohesive modules — DateFormatter, TaxCalculator, EmailSender — and remove the global: pass each module only the config values it needs as parameters (data coupling), or inject a read-only config object through its constructor. Result: low coupling, high cohesion — the stated goal of good design.Utils-এর cohesion হলো coincidental cohesion (সবচেয়ে খারাপ — সম্পর্কহীন কাজ এক জায়গায়)। Shared global appConfig বানায় common coupling। (ii) খারাপ কারণ: tax-এর নিয়ম বদলালে date আর email-এর code-ও আবার test করতে হয়; module-টা reuse করা যায় না (tax + email একসাথে কে চায়?); আর common coupling-এ appConfig-এ লেখা ছয়টা module-এর যে কেউ চুপিচুপি বাকিদের ভাঙতে পারে — bug খুঁজে পাওয়া খুব কঠিন হয়। (iii) ভালো design: তিনটা functionally cohesive module-এ ভাগ করো — DateFormatter, TaxCalculator, EmailSender — আর global সরাও: প্রতিটা module-কে শুধু তার দরকারি config value parameter হিসেবে দাও (data coupling), বা constructor দিয়ে read-only config object inject করো। ফলাফল: low coupling, high cohesion — ভালো design-এর আসল goal।Show Answerউত্তর দেখুন
- Unclear or changing requirements — the team builds the wrong thing because nobody pinned down what was needed, or the target kept shifting.
- Poor estimation of time and cost — an over-optimistic schedule/budget guarantees the project looks "failed" even if the work is fine.
- Lack of user involvement — without user feedback during development, the delivered product does not fit real work, so users reject it.
- Poor communication — customer, managers, and developers each imagine a different product; the gaps surface only at delivery.
- Inadequate testing — rushed or skipped testing sends bugs to production, destroying user trust.
- Scope creep — features keep getting added without adding time or people, so nothing gets finished properly.
- Weak project management — no clear plan or progress tracking means problems are noticed too late to fix.
- No risk management — nobody asked "what can go wrong?" early, so predictable problems (key person leaves, technology fails) arrive as surprises.
- Unclear বা changing requirements — কী দরকার তা কেউ পাকা করেনি বা target সরতে থেকেছে, তাই team ভুল জিনিস বানায়।
- Time আর cost-এর poor estimation — বেশি আশাবাদী schedule/budget থাকলে কাজ ভালো হলেও project-টা "failed" দেখায়।
- User involvement-এর অভাব — development-এর সময় user-এর feedback না নিলে delivered product আসল কাজের সাথে মেলে না, user-রা নেয় না।
- Poor communication — customer, manager আর developer-রা যে যার মতো আলাদা product কল্পনা করে; ফারাকটা ধরা পড়ে delivery-তে।
- Inadequate testing — তাড়াহুড়ার বা বাদ দেওয়া testing bug-কে production-এ পাঠায়, user-এর বিশ্বাস নষ্ট হয়।
- Scope creep — সময় বা মানুষ না বাড়িয়ে feature যোগ হতে থাকে, কিছুই ঠিকমতো শেষ হয় না।
- Weak project management — clear plan আর progress tracking না থাকলে সমস্যা এত দেরিতে চোখে পড়ে যে ঠিক করা যায় না।
- Risk management নেই — শুরুতে "কী ভুল হতে পারে?" কেউ ভাবেনি, তাই আন্দাজ করা যেত এমন সমস্যাও (key person চলে যাওয়া, technology fail) surprise হয়ে আসে।
Show Answerউত্তর দেখুন
- Corrective — fixing bugs found after release. Example: login crashes on a special character in the password.
- Adaptive — adjusting to a changed environment. Example: updating billing because the VAT rate changed, or porting to a new OS.
- Perfective — improving for users. Example: adding a requested dark mode, making search faster.
- Preventive — cleaning up now to avoid future problems. Example: refactoring a messy module and updating its documentation.
- Identification — receive change requests and identify what modification is needed.
- Analysis — study the feasibility, impact, and cost of the change.
- Design — design the modification using the current system's documents.
- Implementation — code the change into the system.
- System testing — test the change plus regression tests so old features still work.
- Delivery — release the updated software to the users.
- Corrective — release-এর পরে পাওয়া bug ঠিক করা। Example: password-এ special character থাকলে login crash করে।
- Adaptive — বদলে যাওয়া environment-এর সাথে মানানো। Example: VAT rate বদলানোয় billing update করা, বা নতুন OS-এ port করা।
- Perfective — user-দের জন্য ভালো করা। Example: চাওয়া dark mode যোগ করা, search আরও fast করা।
- Preventive — ভবিষ্যতের সমস্যা এড়াতে এখনই পরিষ্কার করা। Example: এলোমেলো module refactor করে documentation update করা।
- Identification — change request নেওয়া আর কী modification লাগবে তা identify করা।
- Analysis — change-টার feasibility, impact আর cost study করা।
- Design — চালু system-এর document দেখে modification design করা।
- Implementation — change-টা system-এ code করা।
- System testing — change test করা + regression test, যাতে পুরনো feature ঠিক থাকে।
- Delivery — updated software user-দের কাছে release করা।
Show Answerউত্তর দেখুন
interface SortStrategy { void sort(int[] a); }
class QuickSort implements SortStrategy {
public void sort(int[] a) { /* quicksort */ }
}
class MergeSort implements SortStrategy {
public void sort(int[] a) { /* mergesort */ }
}
class Sorter { // context
private SortStrategy strategy;
Sorter(SortStrategy s) { strategy = s; }
void setStrategy(SortStrategy s) { strategy = s; }
void sortData(int[] a) { strategy.sort(a); }
}
The context (Sorter) holds a reference to the interface only — it never knows which concrete algorithm it is running. Calling setStrategy(new MergeSort()) switches the algorithm at runtime. (iii) The Open/Closed principle: adding HeapSort implements SortStrategy is a NEW class only — no old code (Sorter, QuickSort, MergeSort) is modified. It also shows low coupling: Sorter depends on an abstraction, not on concrete classes (Dependency Inversion helps here too, but Open/Closed is the main answer).interface SortStrategy { void sort(int[] a); }
class QuickSort implements SortStrategy {
public void sort(int[] a) { /* quicksort */ }
}
class MergeSort implements SortStrategy {
public void sort(int[] a) { /* mergesort */ }
}
class Sorter { // context
private SortStrategy strategy;
Sorter(SortStrategy s) { strategy = s; }
void setStrategy(SortStrategy s) { strategy = s; }
void sortData(int[] a) { strategy.sort(a); }
}
Context (Sorter) শুধু interface-এর reference রাখে — কোন concrete algorithm চলছে সে জানেই না। setStrategy(new MergeSort()) ডাকলেই runtime-এ algorithm বদলে যায়। (iii) Open/Closed principle: HeapSort implements SortStrategy যোগ করা মানে শুধু একটা NEW class — পুরনো code (Sorter, QuickSort, MergeSort) একটুও বদলাতে হয় না। এতে low coupling-ও দেখা যায়: Sorter concrete class না, abstraction-এর উপর নির্ভর করে (Dependency Inversion-ও এখানে কাজ করে, তবে মূল উত্তর Open/Closed)।Show Answerউত্তর দেখুন
OrderService.totalPayable(order) applies the rule "orders of 5000 Tk or more get 10% off": if (sum >= 5000) sum *= 0.90; — the UI only displays the result, the data layer only saves the order; (b) domain entities — the Order object itself carries small rules like subtotal(). (A third option for frequently changing rules: a rule engine/config, so rates and limits are data, not code.)OrderService.totalPayable(order) এই rule চালায়: "৫০০০ টাকা বা বেশি order-এ 10% ছাড়" → if (sum >= 5000) sum *= 0.90; — UI শুধু ফলাফল দেখায়, data layer শুধু order save করে; (b) domain entity — Order object নিজেই subtotal()-এর মতো ছোট নিয়ম রাখে। (ঘন ঘন বদলানো নিয়মের জন্য তৃতীয় উপায়: rule engine/config — rate আর limit তখন code না, data।)