IITM BS · Software Engineering · Revision Notes

Software Architecture, SOLID Principles & Design Patterns

Lecture transcripts + slides ko combine karke banaye gaye extensive Hinglish notes — with animated diagrams, easy examples (Amazon Seller Portal wale hi!), aur end me assignment-style practice questions with answers.

4 Architecture Styles 5 SOLID Principles 7 Design Patterns 18 Practice Questions
Lecture 1 · Introduction

01Software Architecture kya hai?

Pichle weeks me humne design banana seekha — modular design, layered design, UML diagrams. Ab jab code likhna shuru ho gaya hai, toh big picture view lena zaroori hai — yahi kaam software architecture karta hai.

Definition (exam ke liye ratta maar lo) Software architecture is a way of organising your code. It defines the software elements/modules, the relations among them, and the properties of both the elements and the relations.
Samjho aise Jaise ek building banane se pehle architect decide karta hai ki rooms kahan honge, kitchen kahan hoga, pipes kaise jayengi — waise hi software architecture decide karta hai ki classes/modules kaise organise honge aur aapas me kaise baat karenge. Space ki efficiency, functionality ki efficiency — sab planned.
📍 Reflection Spot (lecture wala)

Google Search Engine aur ek Compiler — dono software systems hain. Inme key differences kya hain? (Pause karke socho... answer neeche hai 👇)

Architecture Styles — 4 types yaad rakhne hain

Jab components ke beech information flow ka pattern alag hota hai, toh use hum alag architecture style kehte hain. Yahi upar wale reflection spot ka answer hai — Google Search aur compiler ka information flow bilkul alag hai.

① Client-Server

Data is transacted in response to requests. User (client) request bhejta hai, server response deta hai. Example: Google Search — aap query type karte ho, request Google ke server pe jaati hai, server pages return karta hai. Aaj ka Internet predominantly aise hi kaam karta hai.

CLIENT SERVER request → ← response

② Pipe and Filter

Data is passed from component to component, and transformed & filtered along the way. Example: Compiler — source code → assembly code → executable file. Har stage pe data transform hota hai, jaise pipeline me paani filter hota jaata hai.

Source Code Assembly Executable

③ Model-View-Controller (MVC)

Is style me views of the data are separated from the manipulations of data. Teen components hote hain (Amazon Seller Portal example ke saath):

  • Model — data ko model karta hai. Seller portal me: database ki tables ko model karne wali classes/objects.
  • ViewGUI objects / presentation layer — Model ka visual representation. Model se data retrieve karke user ko dikhata hai, aur user ↔ model ke beech requests pass karta hai.
  • Controller — screen pe multiple views ko coordinate karta hai aur users ko model manipulate karne me help karta hai. Example: seller portal me "filter catalogue items by name" — controller user input receive karne wale module ko message bhejta hai, aur underlying views ko appropriate messages deta hai.
CONTROLLER MODEL VIEW manipulates coordinates data →

④ Peer-to-Peer (P2P)

Distributed application — alag-alag systems nodes bante hain aur ek-dusre ke saath resources share karte hain. Sabse badi baat: koi centralised system nahi hota jo saare transactions monitor kare. Nodes apni processing power, disk storage etc. directly baaki nodes ko available karate hain — bina kisi central server ya stable host ke.

Client-server se difference: wahan ek central server hota hai; yahan sab barabar (peers) hain.

Components, Connectors, Protocols — architecture ki building blocks

Component A well-defined functionality or behaviour, separate from other functionality/behaviour. Example: client-server system me client software ek component hai (aapka browser jo request bhejta hai) aur server dusra component (jo respond karta hai).
Connector Code that transmits information between components — components akele kaam nahi kar sakte, unko baat karni padti hai. Connectors hi unke interactions ko regulate karte hain. Most common connectors: function calls aur REST API calls.
Protocol Set of pre-defined rules jo describe karte hain ki components ek-dusre se kaise interact karein. Client aur server dono ko message format pe agree karna padta hai — aisa nahi ho sakta ki client ek format me bheje aur server dusre format me process kare.

Design Patterns, Anti-patterns, Design Smells, Refactoring

Components kaise banaye jaate hain? Purane zamane me experienced designers past me kaam kar chuke solutions ko consciously reuse karte the (module libraries). Baad me ye solutions standardise ho gaye — inhe hi design patterns kehte hain (famous book: "Design Patterns: Elements of Reusable Object-Oriented Software").

  • Design Pattern — description of communicating objects and classes, customised to solve a general design problem in a particular context.
  • Anti-pattern — jab achhe intentions ke bawajood pattern galat use ho jaaye ya naya code aate-aate design bigad jaaye. Code me bahut problems create karta hai.
  • Design Smellwarning signs ki aapka code anti-pattern ki taraf jaa raha hai. (Naam funny hai but exam me aata hai! 😄)
  • SOLID Guidelines — design smells se bachne ke effective guidelines.
  • Refactoring — design smell dikhe toh wapas achhe design ki taraf jaana. Isme 3 cheezein: (a) moving code between classes, (b) creating new classes/modules, (c) removing classes that aren't required.
Ek line me chain yaad rakho Design smell dikha → matlab anti-pattern aa raha hai → SOLID follow karo → zaroorat pade toh refactor karo. ✅
Lectures 2–3 · SOLID Principles I & II

02SOLID Principles

Object-oriented principles for effective software design — inhe conceptualise kiya Robert Martin (Uncle Bob) ne, jo Agile Manifesto ke founders me se ek hain. Ye principles code ko easy to understand aur modular banate hain, aur good cohesion + loose coupling ko support karte hain.

S
Single Responsibility
O
Open-Closed
L
Liskov Substitution
I
Interface Segregation
D
Dependency Inversion

S — Single Responsibility Principle (SRP)

PrincipleEvery class should have a single responsibility / purpose.

Lecture example (violation): Ek hi Seller class me sab kuch bhara hai — seller ki info (sellerID, name, address), product ki info, aur inventory ke functions (addSeller, deleteSeller, addProduct, addItemsToInventory, viewInventory...). Yeh SRP ko violate karta hai kyunki ek class 3 kaam kar rahi hai.

Refactor (fix): Badi Seller class ko 3 alag classes me split karo:

  • Seller — sirf seller details + addSeller, deleteSeller
  • Product — sirf product details + product functions
  • Inventory — sellerID leta hai, products seller ki inventory me add hote hain
Fayda kya hua? Product me change karna ho toh Seller/Inventory ka code chhedna nahi padega. Aur bug dhundhna easy — product ka error hai toh sirf Product class dekho. Isolation = easy debugging.

O — Open-Closed Principle (OCP)

PrincipleSoftware entities should be open for extension, but closed for modification.

Matlab: class ka behaviour extend karo (subclass banao), par existing class ko modify mat karo.

Lecture example: Product class hai (id, name, type, cost). Ab naya product type Clothing add karna hai jisme size aur colour bhi chahiye.

  • ❌ Galat tareeka: Product class me hi size, colour attributes aur naya addProduct() ghusa do → existing class modify ho gayi → OCP violated.
  • ✅ Sahi tareeka: Clothing naam ki nayi class banao jo Product ko inherit kare. Clothing ko parent ke saare attributes milenge + apne specialised (size, colour). Product class untouched rahi!
// OCP applied — Product ko chhua hi nahi
class Clothing extends Product {
    String size, colour;              // specialised attributes
    void addProduct(id, name, type, cost, size, colour) { ... }
}
class Book extends Product {      // kal ko Book aaya? bas nayi class!
    String author, publisher;
}

L — Liskov Substitution Principle (LSP)

PrincipleDerived classes should be substitutable by their base class. Agar class D, class B ka subtype hai → toh B ko D se replace karne par program ka behaviour break nahi hona chahiye. (Inheritance hierarchies pe apply hota hai.)

Lecture example: Feature — sellers ko product feedback ki notification bhejni hai.

  • Abstract class FeedbackNotification me method: notify(product, feedback, email). EmailNotification ise extend karke email bhejta hai — sab theek. ✅
  • Ab SMS bhi bhejna hai. SMSNotification banaya... par problem! Base class ke notify() me teesra parameter email hai, jabki SMS ko mobile number chahiye. Derived class ka method base class se substitute nahi ho sakta → ❌ LSP violated.
  • ✅ Fix: Email parameter ko abstract class se hata do — notify() sirf (product, feedback) le. Email/mobile number jaisi specific cheezein derived classes apne constructor se set karein: EmailNotification(email), SMSNotification(mobileNo, carrier). Ab dono ka notify() same signature — fully substitutable. ✅
Yaad rakhne ka trick Parent ka promise, bachcha nibhaye. 😄 Jo method signature/behaviour base class promise karti hai, derived class ko bina tode follow karna chahiye.

I — Interface Segregation Principle (ISP)

Pehle interface kya hai?Group of related methods with empty bodies. Interface batata hai kya karna hai, kaise nahi. Dusri classes interface implement karti hain — matlab uske saare methods ki definition likhni padti hai.

Principle"Do not force any client to implement an interface which is irrelevant to them."

Lecture example: DeliveryProcessing interface me 4 methods: placeOrder, notifySeller, packageOrder, deliver. Physical orders ke liye theek hai. Par digital product (e-book) ke order me packaging aur physical delivery irrelevant hai — phir bhi client ko woh methods implement karne padenge (bekaar/meaningless implementations). ❌ ISP violated.

✅ Fix — interface ko segregate (split) karo:

  • PhysicalDeliveryProcessing — placeOrder, notifySeller, packageOrder, deliver (chaaron)
  • OnlineDeliveryProcessing — sirf placeOrder, notifySeller

Ab jo client jo delivery implement karna chahe, wahi interface use kare. Har interface ek specific function perform kare — koi bhi client ko faltu methods implement na karne padein.

D — Dependency Inversion Principle (DIP)

PrincipleAlways prefer abstractions/interfaces over specific implementations. Classes ko interfaces se associate karo, concrete implementation se nahi.

Lecture example: Feature — seller ko portal pe beche gaye products ka payment milna chahiye.

  • ❌ Problem: Seller class ka ek attribute hai BankAccount object → seller tightly coupled hai bank account se. Ab seller S2 ko UPI se payment chahiye? Toh Seller me UPI ka bhi attribute add karo... phir Google Pay, Paytm... har payment method ke liye Seller class me coupling badhti jayegi → code unnecessarily complex.
  • ✅ Fix: Ek interface banao PaymentAccount (method: payment()). Ab Seller sirf is interface se coupled hai. BankAccount, UPI, GooglePay, Paytm — sab is interface ko implement karte hain.
// DIP applied
interface PaymentAccount { void payment(); }
class BankAccount implements PaymentAccount { ... }
class UPI implements PaymentAccount { ... }

// main me: jo bhi option chahiye, wahi object banao aur seller ko de do
PaymentAccount pa = new UPI();
seller.setPaymentAccount(pa);   // seller ko fark nahi padta andar kya hai
Fayda Kal ko naya payment option aaye — bas nayi class banao jo interface implement kare. Seller ka code zero change. Loose coupling FTW. ✅
Lectures 4–6 · Design Patterns

03Design Patterns

DefinitionDesign patterns are descriptions of communicating objects and classes that are customised to solve a general design problem in a particular context. Experienced developers ne notice kiya ki kuch patterns code me baar-baar aate hain — unhe generalise karke likha gaya. (Total ~23 classic patterns hain; course me kuch hi cover hote hain.)

Elements of a Design Pattern (3 cheezein)

  • 1. Problem — pattern kab apply karna hai, kis context me.
  • 2. Solution — design ke elements, unke relationships, responsibilities aur collaborations. Ye ek template hai jo alag-alag situations me apply ho sakta hai.
  • 3. Consequences — results, trade-offs, cost-benefit. Pattern lagane se pehle socho: fayda hai bhi ya nahi?
Golden rule (summary slide se, exam favourite) Design patterns should NOT be used blindly. Pattern exist karta hai iska matlab ye nahi ki har jagah use karo — benefit dikhe tabhi use karo, warna code faltu me complex ho jaata hai.

3 Types of Design Patterns

Type Kya karta hai Is course me covered
Creational Object creation ke process me use hota hai — flexibility + code reuse Factory, Builder
Structural Objects/classes ko larger structures me assemble karna — flexible & efficient rakhte hue Facade, Adapter
Behavioral Objects ke beech effective communication + responsibilities ka distribution Iterator, Observer, Strategy

🏭 Creational Patterns

Problem: Seller portal me feature — "package ko ek courier service se deliver karna hai." Simple code: Delivery class (method: deliver(courier)) + Courier class; main me courier object banao, delivery ko pass karo. Ab business bada hua — international courier bhi chahiye. Aasan (par galat) fix: Courier me courierType rakho aur deliver() me if national ... else international ... likho. Ye Open-Closed Principle violate karta hai — hum existing class modify kar rahe hain!

Solution: Replace direct object construction calls (new operator) with calls to a special factory method.

  • Delivery aur Courier ko abstract banao.
  • Har type ke liye subclasses: NationalCourier, InternationalCourier (Courier extend karte hain) aur NationalDelivery, InternationalDelivery (Delivery extend karte hain).
  • Delivery me abstract method createCourier() — yehi factory method hai. NationalDelivery ka createCourier() → NationalCourier object return karta hai; InternationalDelivery ka → InternationalCourier.
  • Object banane ki responsibility delegate ho gayi in classes ke factory method ko. Main me: delivery object banao, d.createCourier() bulao, jo courier mile use deliver() me do.
// Factory pattern ka core idea
abstract class Delivery {
    abstract Courier createCourier();   // ← FACTORY METHOD
    void deliver(Courier c) { ... }
}
class InternationalDelivery extends Delivery {
    Courier createCourier() { return new InternationalCourier(); }
}

Naya type (local courier) add karna ho? Bas nayi classes banao + factory method — koi existing class modify nahi hoti.

✓ Pros
  • SRP follow hota hai — har class ek kaam, creation delegate
  • OCP follow hota hai — extension by new classes, no modification
✗ Cons
  • Code complicated ho sakta hai — bahut saari nayi subclasses banani padti hain
  • Context dekh ke trade-off decide karo

Problem: Book object banana hai — kuch parameters mandatory (ISBN, title, cost) aur kuch optional (author, published, description). Har combination ke liye alag constructor likhna padta hai — is problem ko Telescoping Constructors kehte hain (exam keyword!). Code ganda + complicated.

Solution: Extract the object construction code out of its own class and move it to a separate object called a builder.

  • Builder class banao (Book ke andar static class) — same fields.
  • Builder ka constructor sirf mandatory params leta hai (ISBN, title, cost).
  • Har optional field ke liye alag method: author(), published(), description() — jo field set karke builder return karti hai.
  • Last me build() method — final Book object return karta hai. Book ka ab ek hi constructor hai jo builder leta hai.
// step-by-step object banao
Book b1 = new Book.Builder("978-93", "SE Notes", 450)
                 .author("Iyer").published(2024).description("...")
                 .build();
Book b2 = new Book.Builder("978-94", "DSA", 300)
                 .description("desc only").build();  // baaki null
✓ Pros
  • Objects step by step construct hote hain — lambi constructor calls nahi
  • SRP — object creation ka kaam builder ka, baaki class apna kaam kare
✗ Cons
  • Code complicated — same params wali extra Builder class + methods
  • Mandatory/optional params kam hain toh pattern skip kar sakte ho

🧱 Structural Patterns

Problem: Buyer order place kare toh system ko 4 kaam karne hain: create order → notify seller → prepare packaging → send for delivery. Client ko 4 classes ke objects banane + sahi order me methods bulane padte hain. Client ko itni details kyun pata honi chahiye? Complicated library functions use karne walon ka bhi yahi dard hai.

Solution: Facade provides a simple interface to a library or a complex set of classes. Ek nayi class banao — DeliveryFacade — jiska ek method (deliver()) saare object creation + function calls apne andar kar leta hai. Client bas facade ka ek method bulaye, kaam done!

class DeliveryFacade {
    void deliver(product, sellerName) {
        new Order().placeOrder(product);
        new Seller().notifySeller(sellerName);
        new Package().packageOrder();
        new Delivery().deliverOrder();   // sab ek jagah
    }
}
✓ Pros
  • Code/libraries ki complexity isolate ho jaati hai — client ko sirf ek simple method dikhata hai
✗ Cons
  • Facade baaki objects se tightly coupled hota hai — kisi bhi class me change hua toh facade bhi update karna padega → maintenance difficult

Problem: Seller portal me kuch products ki cost dollars/euros me hai — rupees me conversion chahiye. Ek existing library/class hai ConversionCalculator jis par hamara control nahi hai, aur uska interface Product class ke saath incompatible hai — Product directly use nahi kar sakta.

Solution: Beech me ek adapter class daalo — ye ek wrapper hai jo client aur adaptee ke beech link provide karta hai. Client adapter ka method bulata hai → adapter andar hi andar adaptee ka (incompatible) method bulata hai. Incompatibility ka saara jhanjhat adapter handle karta hai — client ko complexity pata hi nahi chalti.

// CostCalculatorAdapter = bridge between Product & ConversionCalculator
class CostCalculatorAdapter {
    double getCostInRupees(Product p) {
        ConversionCalculator cc = new ConversionCalculator();
        return cc.dollarToRupee(p.cost);   // $300 → ₹ me convert
    }
}

Product ko ConversionCalculator ki koi detail nahi pata — woh sirf adapter se baat karta hai. (Real life analogy: charger ka plug adapter — US plug ko Indian socket me lagane wala!)

✓ Pros
  • SRP — currency conversion ka code, product ke business logic se alag
  • OCP — nayi currencies ke liye naye adapters easily add ho jaate hain
✗ Cons
  • Code complexity badhti hai — naya class + methods; agar Product ya calculator me hi change kar sakte toh adapter ki zaroorat nahi thi

🤝 Behavioral Patterns

Problem: Hum alag-alag collections use karte hain — lists, queues, stacks, trees (products ki list, orders ki list, deliveries ki list...). Common operation: elements ko access aur iterate karna. Client ko sirf elements chahiye — elements kaise store hain (underlying data structure), usse client ko matlab nahi.

Solution: Elements ko access karne ka behaviour ek alag object — iterator — me nikaal do. Java ka Iterator interface ke 2 key methods:

  • hasNext() — true return karta hai agar iteration me aur elements hain
  • next() — iteration ka agla element return karta hai

ArrayList ho ya LinkedList — dono in methods ki apni implementation dete hain. Client ko implementation details jaanne ki zaroorat nahi; woh bas hasNext()/next() use kare. Collection badal do, client ka loop same rahega!

✓ Pros
  • SRP — element access ka kaam alag iterator class me
  • OCP — naye type ka iterator banake naye collections iterate kar sakte ho
✗ Cons
  • Simple collections (jaise chhota array) ke liye alag iterator class overkill hai

Problem: Naya product launch ho toh sirf subscribed buyers ko notify karna hai — saare users ko nahi. (YouTube analogy: channel subscribe + bell icon 🔔 → naya video aate hi notification.)

Solution: Subject object ek list of observers maintain karta hai; jab bhi update ho, subject saare observers ko notify kar deta hai.

  • Subject class — observers ka collection; methods: registerObserver(), unregisterObserver(), notifyObservers()
  • Observer — interface/abstract class with update() method
  • notifyObservers() bas collection pe iterate karke har observer ka update() bula deta hai
  • Lecture example: NormalUser aur PrimeUser dono Observer extend karte hain — normal user ko "naya product aaya" message, prime user ko extra "aapko additional discount bhi milega" 😎 — har type apna update() implement karta hai
SUBJECT Observer u1 Observer u2 Observer u3 notifyObservers() → update()
✓ Pros
  • Sirf interested (subscribed) observers ko hi updates jaate hain
  • Naye types ke observers easily add — bas update() implement karo
✗ Cons
  • Subject-observer management ka extra structure maintain karna padta hai

Problem: Shopping orders ko alag-alag strategies se process karna hai — (a) First In First Out (FIFO): jo order pehle aaya, pehle process; (b) Priority: prime/super users ke orders pehle. Bina pattern ke: OrderManager me har strategy ka apna method (deliverFIFO(), deliverPriority()...). Nayi strategy aayi? Class me naya method add karo → OCP violated (existing class modify ho rahi hai).

Solution: Alag-alag strategies/algorithms ko separate classes me extract karo. Original class (context) algorithm ka kaam strategy object ko delegate kar deti hai.

  • Interface: OrderDeliveryStrategy — method deliverOrders()
  • FIFOOrderDelivery aur PriorityOrderDelivery — dono interface implement karte hain, apna-apna logic deliverOrders() me
  • Runtime pe strategy switch kar sakte ho: pehle FIFO se deliver kiya, phir priority se — bas naya strategy object do
  • Nayi strategy? Nayi class banao jo interface implement kare — existing code me zero changes
✓ Pros
  • Algorithm ki implementation details isolate — har class me ek specific strategy ka logic
  • OCP — nayi strategies bina existing classes/methods badle add hoti hain
✗ Cons
  • Agar sirf 1-2 hi strategies hain toh pattern lagana zaroori nahi — overkill
Assignment-style Practice

04Practice Questions (with answers)

Lecture content ke basis pe assignment-style questions banaye hain — MCQ + short answer, IITM graded assignment ke pattern me. "Show Answer" pe click karke check karo. ⚠️ Note: official graded assignment ka PDF project files me nahi tha — woh upload kar doge toh exact questions ke solutions bhi add kar dunga.

Q1 · Architecture Styles

Ek compiler source code ko assembly me, phir executable me transform karta hai. Ye kaunsa architecture style hai?

  1. Client-Server
  2. Pipe and Filter
  3. Peer-to-Peer
  4. MVC
Answer: (b) Pipe and Filter

Data ek component se dusre me pass, transform aur filter hota hai. Google Search jaisa request-response nahi hai — isliye client-server nahi.

Q2 · Architecture Styles

Google Search Engine kis architecture style ka example hai, aur kyun?

Answer: Client-Server

User query type karta hai → request Google ke server pe jaati hai → server related pages ka response return karta hai. "Data transacted in response to requests" — classic client-server. Internet aaj predominantly aise hi chalta hai.

Q3 · MVC

Amazon Seller Portal me database ki tables ko model karne wali classes MVC ke kis component me aati hain?

  1. View
  2. Controller
  3. Model
  4. Connector
Answer: (c) Model

Model = service ke liye required data ko model karne wala component. View = GUI/presentation, Controller = views coordinate + user ko model manipulate karne me help.

Q4 · Components & Connectors

Fill in the blanks: Components ke beech information transmit karne wala code ______ kehlata hai, aur unke interaction ke pre-defined rules ______ kehlate hain.

Answer: Connector, Protocol

Common connectors: function calls, REST API calls. Protocol ensure karta hai ki client aur server message format pe agree karein.

Q5 · Design Smells

"Warning signs that your code may be heading towards an anti-pattern" — is definition ko kya kehte hain? Aur isse bachne ke liye kya follow karte hain?

Answer: Design Smell; SOLID guidelines

Smell dikhe toh refactoring karo: code move karo classes ke beech, nayi classes/modules banao, ya faltu classes hatao.

Q6 · SRP

Ek Seller class me addSeller(), addProduct(), viewInventory() — teeno methods hain. Kaunsa principle violate ho raha hai, aur fix kya hai?

Answer: Single Responsibility Principle

Class ke paas 3 responsibilities hain (seller, product, inventory). Fix: 3 alag classes me split karo — Seller, Product, Inventory — har class ek hi kaam kare.

Q7 · OCP

Product class me clothing ke liye size/colour attributes directly add kar diye. Kaunsa principle toota? Sahi approach kya thi?

Answer: Open-Closed Principle

Existing class ko modify kiya — jabki OCP kehta hai "open for extension, closed for modification". Sahi approach: Clothing extends Product — nayi subclass, parent untouched.

Q8 · LSP

Base class ke notify(product, feedback, email) ko SMSNotification override nahi kar paa raha kyunki use mobile number chahiye. Ye kis principle ka violation hai? Fix batao.

Answer: Liskov Substitution Principle

Derived class base class se substitutable nahi rahi. Fix: email param base class se hatao — notify(product, feedback) rakho; email/mobileNo har derived class apne constructor se set kare.

Q9 · ISP

DeliveryProcessing interface me packageOrder() aur deliver() hain, par e-book (digital product) wale client ke liye ye irrelevant hain. Principle + fix?

Answer: Interface Segregation Principle

"Do not force any client to implement an interface which is irrelevant to them." Fix: interface ko split karo — PhysicalDeliveryProcessing (chaaron methods) aur OnlineDeliveryProcessing (sirf placeOrder + notifySeller).

Q10 · DIP

Seller class ke paas directly BankAccount object hai. Naye payment methods (UPI, GPay) add karne me problem aa rahi hai. Kaunsa principle apply karein aur kaise?

Answer: Dependency Inversion Principle

"Prefer abstractions over implementations." PaymentAccount interface banao; Seller sirf interface se couple ho; BankAccount/UPI/GPay/Paytm sab interface implement karein. Naya option = bas nayi class.

Q11 · SOLID Recall

SOLID ka full form likho aur ye kisne conceptualize kiye?

Answer

Single Responsibility, Open-Closed, Liskov Substitution, Interface Segregation, Dependency Inversion — by Robert Martin (Uncle Bob), Agile Manifesto ke founders me se ek. Ye good cohesion + loose coupling support karte hain.

Q12 · Factory

Factory design pattern ka core idea kya hai, aur ye kaunse 2 SOLID principles follow karta hai?

Answer

Core idea: direct object construction (new) ko replace karo special factory method ki calls se — object creation ki responsibility delegate ho jaati hai. Follows: SRP + OCP. Con: bahut saari subclasses se code complicated ho sakta hai.

Q13 · Builder

"Telescoping constructors" problem kya hai aur kaunsa pattern ise solve karta hai?

Answer: Builder pattern

Mandatory + optional params ke har combination ke liye alag constructor likhna padta hai — yehi telescoping constructors. Builder pattern construction code ko alag builder object me le jaata hai: mandatory params constructor me, optional fields individual methods se, aur build() final object return karta hai.

Q14 · Facade

Facade pattern ka main disadvantage kya hai?

  1. Client ko zyada methods yaad rakhne padte hain
  2. Facade baaki objects se tightly coupled hota hai → maintenance difficult
  3. Ye OCP violate karta hai hamesha
  4. Iterator ki zaroorat padti hai
Answer: (b)

Facade order/seller/package/delivery sab se coupled hai — kisi me bhi change hua toh facade bhi badalna padega. (Advantage yaad rakho: complexity isolate karke client ko simple interface dena.)

Q15 · Adapter

Product class ek existing ConversionCalculator library use karna chahti hai par interfaces incompatible hain aur library pe control nahi hai. Kaunsa pattern lagega?

Answer: Adapter pattern

Adapter (e.g. CostCalculatorAdapter) wrapper ki tarah client aur adaptee ke beech link banata hai — incompatibility adapter handle karta hai, client ko details pata nahi chalti. Follows SRP + OCP.

Q16 · Iterator

Java ke Iterator interface ke 2 key methods aur unka kaam batao.

Answer

hasNext() — true agar iteration me aur elements hain; next() — agla element return karta hai. Point: client ko underlying data structure (ArrayList/LinkedList) se matlab nahi — access ka behaviour alag iterator object me hai.

Q17 · Observer

YouTube channel subscribe karke bell dabane pe naye video ki notification aati hai. Is scenario me subject kaun hai, observer kaun, aur kaunsa method sabko update karta hai?

Answer

Subject = channel, Observers = subscribed users. Subject observers ki list rakhta hai (register/unregister) aur notifyObservers() list pe iterate karke har observer ka update() bulata hai — sirf subscribed logon ko hi update jaata hai.

Q18 · Strategy

OrderManager me deliverFIFO() aur deliverPriority() methods hain; nayi strategy ke liye har baar naya method add karna padta hai. Pattern + fix batao.

Answer: Strategy pattern

Ye approach OCP violate karti hai. Fix: OrderDeliveryStrategy interface (deliverOrders()) banao; FIFOOrderDelivery / PriorityOrderDelivery alag classes me apna algorithm implement karein; context strategy object ko kaam delegate kare. Nayi strategy = nayi class, existing code untouched. (Con: 1-2 strategies ke liye overkill.)

Last-minute Revision

05Ek-Line Cheat Sheet

Concept Ek line me
Software Architecture Code organise karne ka tareeka — elements, relations, aur dono ki properties define karta hai
Client-Server Request → Response (Google Search, internet)
Pipe & Filter Data component-to-component transform hota hai (Compiler)
MVC Model = data, View = GUI, Controller = coordinator
P2P Nodes resources share karte hain, no central system
Component / Connector / Protocol Functionality / info transmit karne wala code / interaction ke rules
Design Smell Anti-pattern ki taraf jaane ka warning sign
SRP Ek class = ek kaam (Seller → Seller + Product + Inventory)
OCP Extend karo, modify mat karo (Clothing extends Product)
LSP Derived class, base class se substitutable ho (email vs mobile param)
ISP Client pe irrelevant interface mat thopo (physical vs online delivery)
DIP Interface se couple karo, implementation se nahi (PaymentAccount)
Factory new ki jagah factory method se object creation delegate (createCourier)
Builder Telescoping constructors ka ilaaj — step-by-step build()
Facade Complex classes ke aage simple interface (DeliveryFacade.deliver())
Adapter Incompatible interfaces ke beech wrapper (currency converter)
Iterator hasNext()/next() — access ko storage se alag karo
Observer Subject notify kare registered observers ko (YouTube 🔔)
Strategy Algorithms alag classes me, context delegate kare (FIFO vs Priority)
Exam tip Har pattern ke liye 4 cheezein ready rakho: problem → solution → example → pros/cons (+ kaunse SOLID principles follow hote hain). Assignment me mostly scenario dekar puchte hain "kaunsa pattern/principle?" — upar wale Q6–Q18 isi format ke hain.