Software EngineeringUnit 1313 min read
Component-Based Software Engineering: Reuse, Architecture, and Integration
Unit 13 of Software Engineering explores how to build software systems by assembling pre-built components (COTS, libraries, frameworks) instead of coding from scratch. Covers component classification, interfaces, middleware, reuse strategies, and challenges like versioning and licensing. Includes real-world examples fr
TAKEAWAYS:
- Components are reusable, self-contained software units with well-defined interfaces (e.g., APIs, libraries) that can be combined like Lego blocks.
- COCOMO model (from Unit 1) applies here: larger projects benefit more from reuse, reducing effort and time.
- Middleware (e.g., message brokers, ORMs) acts as the "glue" between components, handling communication and data translation.
- Reuse strategies (white-box, black-box, gray-box) determine how much internal knowledge of a component is needed.
- Licensing and versioning are critical challenges—mismatched versions or incompatible licenses can break systems.
- Design patterns (e.g., Adapter, Facade) help integrate components with mismatched interfaces.
1. What is Component-Based Software Engineering (CBSE)?
CBSE is a paradigm where software systems are built by assembling pre-existing components (instead of writing everything from scratch). These components can be:
- COTS (Commercial Off-The-Shelf): Purchased software (e.g., payment gateways like Khalti API or eSewa SDK).
- Libraries/Frameworks: Pre-written code (e.g., React.js, Django, Spring Boot).
- Microservices: Independent services (e.g., Pathao’s ride-matching service, Daraz’s inventory service).
Why Use CBSE?
| Advantage | Disadvantage |
|---|---|
| ✅ Faster development | ❌ Vendor lock-in (e.g., switching from Khalti to eSewa may require rewrites) |
| ✅ Reduced costs | ❌ Licensing complexities (e.g., open-source GPL vs. proprietary licenses) |
| ✅ Proven reliability | ❌ Version conflicts (e.g., a new React update breaking your app) |
| ✅ Easier maintenance | ❌ Limited customization (e.g., COTS ERP systems like SAP) |
2. Key Concepts in CBSE
A. Components and Interfaces
A component is a deployable unit with:
- Encapsulation: Hides internal logic (e.g., WhatsApp’s encryption library).
- Well-defined interfaces: Contracts for interaction (e.g., REST API for Daraz’s order status).
- Reusability: Used across multiple systems (e.g., Firebase Auth in mobile apps).
Example: eSewa Payment Component
- Request:
POST /api/paymentwithamount,user_id,merchant_id. - Response:
{"status": "success", "transaction_id": "TX12345"}. - Hidden logic: Fraud detection, bank integration, SMS alerts.
B. Component Classification
| Type | Description | Example |
|---|---|---|
| Black-box | Used without knowing internals. | Google Maps API (you don’t see how routing works). |
| White-box | Internals modified or extended. | Customizing WordPress plugins. |
| Gray-box | Partial knowledge of internals. | Modifying a React component’s state logic. |
3. Middleware: The Glue Between Components
Middleware mediates communication between components. Types:
Message-Oriented Middleware (MOM)
- Uses message queues (e.g., RabbitMQ, Kafka).
- Example: Pathao’s ride requests → driver assignment → payment processing.
sequenceDiagram participant User as User (Mobile App) participant MQ as Message Queue (RabbitMQ) participant Driver as Driver Service participant Payment as Payment Gateway (Khalti) User->>MQ: "Request ride (JSON)" MQ->>Driver: "Assign nearest driver" Driver->>MQ: "Driver accepted" MQ->>Payment: "Process payment" Payment-->>User: "Confirm ride"
Remote Procedure Call (RPC) Middleware
- Example: gRPC (used by Google for internal services).
- Lets components call each other like local functions.
Database Middleware (ORM)
- Example: Hibernate (Java) or SQLAlchemy (Python).
- Translates SQL queries to component calls.
4. Component Reuse Strategies
| Strategy | When to Use | Example |
|---|---|---|
| Black-box reuse | No need to modify internals. | Using Bootstrap CSS in a web app. |
| White-box reuse | Need to extend or fix internals. | Forking an open-source library (e.g., React Router). |
| Gray-box reuse | Partial customization needed. | Overriding a Django model’s save() method. |
Worked Example: Reusing a Payment Component Scenario: A Nepalese e-commerce site (like Daraz) wants to integrate Khalti for payments.
- Black-box reuse:
- Use Khalti’s pre-built SDK without modifying its code.
- Call
Khalti.init()and handle the response.
- Gray-box reuse:
- Extend Khalti’s webhook listener to log transactions in your database.
- White-box reuse (rare):
- Fork Khalti’s open-source parts (e.g., its fraud detection logic) to add custom rules.
5. Challenges in CBSE
A. Versioning and Compatibility
- Problem: A component update (e.g., React 18) may break your app.
- Solution:
- Use semantic versioning (
major.minor.patch). - Example: Daraz freezes Node.js versions for critical services.
- Use semantic versioning (
B. Licensing Issues
| License Type | Restrictions | Example |
|---|---|---|
| GPL | Derivative works must be open-source. | Linux kernel. |
| MIT | No restrictions (even for proprietary use). | React.js. |
| Apache 2.0 | Requires license notice in docs. | Android. |
Real-World Case:
- WhatsApp uses MIT-licensed libraries (e.g., OpenSSL) but keeps its core proprietary.
- Nepal’s NTC uses GPL-licensed software for network monitoring, forcing them to open-source modifications.
C. Performance Overhead
- Example: Daraz’s microservices add latency due to inter-service calls.
- Solution: Use caching (Redis) or edge computing (Cloudflare).
6. Design Patterns for Component Integration
| Pattern | Purpose | Example |
|---|---|---|
| Adapter | Bridge incompatible interfaces. | Legacy bank API → Modern REST API. |
| Facade | Simplify complex component interactions. | Stripe’s unified payment API. |
| Proxy | Control access to a component. | Lazy-loading images in YouTube. |
Example: Adapter Pattern in eSewa
")
- Problem: Old bank systems use SOAP, but your app needs REST.
- Solution: Write an Adapter to convert REST → SOAP.
7. Component-Based Architecture in Nepalese Systems
A. eSewa’s Component Architecture
| Component | Technology | Role |
|---|---|---|
| User Auth | Firebase Auth | Handles login via phone/email. |
| Payment Processing | Khalti API | Routes money to banks. |
| Transaction DB | PostgreSQL | Stores all payments. |
| Notification | Twilio/SMS Gateway | Sends OTPs and alerts. |
B. Daraz’s Order Fulfillment System
stateDiagram-v2 [*] --> OrderReceived: User places order OrderReceived --> InventoryCheck: Check stock InventoryCheck --> StockAvailable: Yes StockAvailable --> PaymentProcess: Redirect to Khalti PaymentProcess --> OrderConfirmed: Success OrderConfirmed --> Dispatch: Notify warehouse Dispatch --> [*] InventoryCheck --> StockUnavailable: No StockUnavailable --> [*]
- Components:
- Inventory Service (MongoDB + Node.js).
- Payment Service (Khalti API).
- Dispatch Service (SMS + GPS tracking).
In the Real World
eSewa (Nepal)
- Component: Khalti Payment Gateway (black-box reuse).
- How it works: When you pay a bill, eSewa’s backend calls Khalti’s API with
amount,user_id, andmerchant_id. Khalti handles bank integration, fraud checks, and SMS confirmations. - Challenge: eSewa had to freeze Khalti’s API version to avoid breaking changes during updates.
Pathao (Ride-Hailing)
- Components:
- Driver Matching (optimization algorithm).
- Payment (Khalti/eSewa integration).
- Maps (Google Maps API).
- Middleware: Kafka for real-time ride updates.
- Real Example: When you book a ride, Pathao’s driver service publishes a message to Kafka → payment service subscribes and processes the fare.
- Components:
Nepal Stock Exchange (NEPSE)
- Component: Bloomberg Terminal API (white-box reuse).
- How it works: NEPSE uses Bloomberg’s market data feeds but customizes the alert system to send SMS in Nepali.
- Challenge: Licensing costs for Bloomberg’s data are high (~$24,000/year).
NTC’s Network Monitoring
- Component: OpenNMS (GPL-licensed).
- How it works: NTC uses OpenNMS to monitor fiber networks but must open-source their modifications (due to GPL).
- Real Example: During the 2023 internet outages, NTC’s custom scripts (built on OpenNMS) helped isolate faults faster.
Exam Tip
COCOMO Model (from Unit 1) is often tested with CBSE:
- Example Question: "A project uses 50% COTS components. Estimate effort for Organic mode."
- Solution:
- Organic mode formula:
Effort (PM) = 2.4 × (KLOC)^1.05. - If original KLOC = 320, and 50% is reused, new KLOC = 160.
Effort = 2.4 × (160)^1.05 ≈ 2.4 × 168.1 ≈ 403.44 person-months.- Answer: ~403 person-months (mention reuse reduces effort).
- Organic mode formula:
Component vs. Service:
- Component: Deployable unit (e.g., Khalti SDK).
- Service: Network-accessible component (e.g., Pathao’s ride service).
- Exam Trick: Always ask "Is it self-contained or network-dependent?"
Licensing is a hot topic:
- GPL: "Copyleft" (derivatives must be open).
- MIT: No restrictions.
- Example Question: "Can a proprietary app use a GPL library?"
- Answer: No (unless the library is dynamically linked and not modified).
Draw diagrams for integration:
- For questions on middleware or component interactions, always sketch a:
- Sequence diagram (for message flows, e.g., Daraz order processing).
- Layered architecture (e.g., eSewa’s auth → payment → DB layers).
- For questions on middleware or component interactions, always sketch a:
Real-world mapping:
- If asked about reuse, relate to:
- eSewa + Khalti (black-box).
- Daraz + Firebase (white-box for custom rules).
- NTC + OpenNMS (gray-box modifications).
- If asked about reuse, relate to:
Practice Questions (Exam-Style)
Short Answer:
- "Differentiate between black-box and white-box component reuse with an example from Nepalese software."
- Answer:
Aspect Black-Box White-Box Example eSewa using Khalti’s SDK. Daraz modifying Firebase security rules. Knowledge Only interface details. Full internal logic. Modification Not allowed. Allowed (forking, extending).
Calculation:
- "A project has 200 KLOC, with 60% reused components. Estimate effort in Embedded mode using COCOMO."
- Solution:
- Embedded formula:
Effort = 3.6 × (KLOC)^1.20. - New KLOC = 200 × (1 - 0.6) = 80.
Effort = 3.6 × (80)^1.20 ≈ 3.6 × 167.7 ≈ 604 person-months.
- Embedded formula:
Diagram-Based:
- "Draw a sequence diagram for Pathao’s ride request flow using middleware."
- Answer: Use the Kafka example from earlier (show User → MQ → Driver → Payment).
Key Formulas to Remember
| Concept | Formula |
|---|---|
| COCOMO (Organic) | Effort = 2.4 × (KLOC)^1.05 |
| COCOMO (Embedded) | Effort = 3.6 × (KLOC)^1.20 |
| Development Time | Time = Effort / (5 × Team Size) |
Final Checklist for Full Marks
- Define component, interface, and middleware.
- Compare black-box vs. white-box reuse with Nepalese examples.
- Explain versioning and licensing challenges.
- Draw a sequence diagram for a real system (e.g., Daraz order).
- Calculate effort reduction due to reuse using COCOMO.
- Discuss one middleware (e.g., Kafka, ORM) in detail.
Based on the TU BSc CSIT syllabus for Software Engineering (CSC364), unit 13.
Discussion
Loading…