0% found this document useful (0 votes)
2 views32 pages

Software Engineering Unit 3 Answers

The document discusses key concepts in software design, specifically Coupling and Cohesion, emphasizing that good design aims for low coupling and high cohesion for maintainability and reusability. It also explains the Model-View-Controller (MVC) design pattern, detailing its components and advantages in web applications, and the Client-Server architecture used in distributed systems for resource sharing and centralized management. Additionally, it covers the Publish-Subscribe pattern's role in event-driven systems, highlighting its benefits in modularity and communication.

Uploaded by

mohamedbasi930
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views32 pages

Software Engineering Unit 3 Answers

The document discusses key concepts in software design, specifically Coupling and Cohesion, emphasizing that good design aims for low coupling and high cohesion for maintainability and reusability. It also explains the Model-View-Controller (MVC) design pattern, detailing its components and advantages in web applications, and the Client-Server architecture used in distributed systems for resource sharing and centralized management. Additionally, it covers the Publish-Subscribe pattern's role in event-driven systems, highlighting its benefits in modularity and communication.

Uploaded by

mohamedbasi930
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

1.

Coupling and Cohesion in Software Design (15 Marks)

In Software Engineering, good software design focuses on dividing a


system into modules that interact properly. Two important concepts used
to measure the quality of design are Coupling and Cohesion.

 Coupling → Relationship between different modules

 Cohesion → Relationship between elements inside a module

A good design always aims for Low Coupling and High Cohesion.

1. Coupling
2.

Definition

Coupling is the degree of dependency between two modules. It


indicates how strongly one module is connected to another module.

 High Coupling → Poor Design

 Low Coupling → Good Design

If one module change affects many other modules, the system becomes
difficult to maintain.

High Coupling Example


In high coupling, modules depend heavily on each other.

Example:

 Module A directly accesses Module B data.

 If Module B changes, Module A must also change.

Problems of High Coupling

 Difficult to modify system

 Hard to maintain

 Difficult to test modules separately

 Low reusability

Low Coupling Example


In low coupling, modules communicate only through interfaces or
parameters.

Example:

 Order module sends payment request to Payment module

 Payment module processes independently

Advantages of Low Coupling

 Easy maintenance

 Independent modules

 Better testing

 High flexibility

Types of Coupling (Worst to Best)

Type Description

Content One module modifies internal data of


Coupling another

Common Modules share global data


Type Description

Coupling

Control
One module controls logic of another
Coupling

Stamp Coupling Modules share complex data structures

Modules share only required data


Data Coupling
(Best)

2. Cohesion

Definition

Cohesion refers to how closely related the functions inside a


module are.

 High Cohesion → Good Design

 Low Cohesion → Poor Design

A module should perform one specific task only.

Low Cohesion Example


4

Example module performing many tasks:

 Print report

 Send email

 Calculate salary

This creates confusion and makes maintenance difficult.

Problems of Low Cohesion

 Hard to understand module

 Difficult to reuse

 Maintenance becomes complex

High Cohesion Example


4

In high cohesion, each module performs only one related task.

Example:

 Email Module → sends emails

 Payment Module → processes payments


 Report Module → generates reports

Advantages of High Cohesion

 Easy to maintain

 Easy to understand

 Better reusability

 Reliable system

Types of Cohesion (Worst to Best)

Type Description

Unrelated tasks grouped


Coincidental Cohesion
together

Logical Cohesion Similar tasks grouped

Temporal Cohesion Tasks executed at same time

Procedural Cohesion Tasks follow specific sequence

Communicational
Tasks operate on same data
Cohesion

Output of one task used by


Sequential Cohesion
another

Module performs single function


Functional Cohesion
(Best)

Relationship Between Coupling and Cohesion

Cohesio Coupli
Result
n ng

Best
High Low
Design

Acceptabl
High High
e

Poor
Low High
Design

Good software design aims for:


✔ Low Coupling
✔ High Cohesion

Real Life Example (Online Shopping System)

Modules:

 User Module

 Product Module

 Order Module

 Payment Module

Good design:

 Each module performs a single task (High Cohesion)

 Modules communicate through methods or APIs (Low Coupling)

This makes the system easy to maintain, scalable, and reusable.

Conclusion

Coupling and cohesion are fundamental principles of modular software


design.

 Low Coupling ensures modules are independent.

 High Cohesion ensures each module performs a specific function.

By applying these principles, software becomes more maintainable,


reusable, flexible, and reliable.

2. Model–View–Controller (MVC) Design Pattern for a Web-Based


Application

The Model–View–Controller (MVC) pattern is a software


architectural design pattern used to separate an application into three
main components. This separation improves maintainability,
scalability, and modularity, especially in web applications.

The three components are:

1. Model – Manages data and business logic

2. View – Displays the user interface


3. Controller – Handles user input and controls the interaction
between Model and View

MVC Architecture
4

Working Principle

1. User interacts with the View (web page).

2. The Controller receives the request.

3. Controller processes the request and communicates with the


Model.

4. The Model updates or retrieves data.

5. The Controller sends the data to the View.

6. The View displays the result to the user.

Components of MVC

1. Model

The Model represents the data and business logic of the application.

Functions:

 Stores application data

 Performs database operations


 Applies business rules

Example (Web Application):

User Model
---------
User ID
Name
Email
Password

Example in Java:

public class User {


private String name;
private String email;

public String getName() {


return name;
}

public void setName(String name) {


[Link] = name;
}
}

2. View

The View represents the presentation layer (User Interface).

Functions:

 Displays information to the user

 Sends user input to the controller

 Does not contain business logic

Examples:

 HTML page

 JSP page

 React UI page

Example (HTML View):


<h2>User Profile</h2>
<p>Name: ${[Link]}</p>
<p>Email: ${[Link]}</p>

3. Controller

The Controller acts as the intermediary between Model and View.

Functions:

 Receives user requests

 Calls Model methods

 Sends results to the View

Example in Java (Servlet Controller):

@WebServlet("/user")
public class UserController extends HttpServlet {

protected void doGet(HttpServletRequest request,


HttpServletResponse response)
throws ServletException, IOException {

User user = new User();


[Link]("Harish");
[Link]("harish@[Link]");

[Link]("user", user);
[Link]("[Link]").forward(request,response);
}
}

MVC Flow in a Web Application


4
Step-by-Step Flow

1. User sends request through browser.

2. Request reaches the Controller.

3. Controller processes request and calls Model.

4. Model interacts with Database.

5. Model returns data to Controller.

6. Controller selects appropriate View.

7. View displays the response to the User.

Example: Online Shopping Website

Model

 Product

 Order

 Customer

 Payment data

View

 Product page

 Cart page

 Checkout page

Controller

 Handles add-to-cart request

 Processes payment

 Updates order information

Example Flow:

User clicks "Buy Product"



Controller receives request

Model fetches product details

Controller sends data to View

View displays order confirmation

Advantages of MVC

1. Separation of concerns – UI, business logic, and data are


separated

2. Easy maintenance – Changes in UI do not affect business logic

3. Code reusability – Components can be reused

4. Parallel development – Developers can work on Model, View, and


Controller separately

5. Scalability – Easy to extend large web applications

Disadvantages of MVC

 Increased complexity for small applications

 Requires proper design and planning

 More files and classes to manage

Conclusion

The MVC design pattern separates a web application into Model, View,
and Controller, improving modularity and maintainability. It is widely
used in modern web frameworks such as Spring MVC, Django, Ruby on
Rails, and [Link] MVC to build scalable and organized web
applications.

3. Client–Server Architectural Style and its Use in Distributed


Systems

The Client–Server architecture is one of the most widely used


architectural styles in distributed systems. In this model, the system is
divided into two main components: Client and Server that
communicate through a network.

 Client → Requests services or resources

 Server → Provides services or resources


This architecture is commonly used in web applications, email
systems, database systems, and cloud services.

Client–Server Architecture Diagram


4

Basic Concept of Client–Server Architecture

In a client–server system:

1. Client sends a request to the server through a network.

2. Server receives and processes the request.

3. Server accesses data or services.

4. Server sends response back to the client.

Example:

 A web browser (client) sends a request to a web server.

 The server processes the request and sends the web page back to
the browser.

Components of Client–Server Architecture

1. Client

The client is a device or application that requests services from the


server.
Examples:

 Web browsers (Chrome, Firefox)

 Mobile apps

 Desktop applications

Functions of Client:

 Sends requests to server

 Displays results to user

 Provides user interface

Example:
User searches "product price" on a website using a browser.

2. Server

The server is a system that provides services or resources to clients.

Examples:

 Web server

 Database server

 File server

 Application server

Functions of Server:

 Processes client requests

 Manages resources

 Stores and retrieves data

 Sends responses to clients

Example:
The web server retrieves product information from database and
sends it to the client.

Working of Client–Server Model


4

Steps:

1. User interacts with the client application.

2. Client sends a request message to the server.

3. Server processes the request.

4. Server may access database or files.

5. Server sends response back to client.

6. Client displays the result to the user.


Types of Client–Server Architecture

1. Two-Tier Architecture

Structure:
Client ↔ Server (Database)

Example:
Desktop application directly connecting to a database server.

2. Three-Tier Architecture

Structure:
Client → Application Server → Database Server

Example:
Web applications.

Example flow:

 Browser → Web Server → Database → Response to Browser

Advantages:

 Better security

 Better scalability

Use of Client–Server in Distributed Systems

A distributed system consists of multiple computers connected through


a network that work together to achieve a common goal.

The client–server model helps distributed systems by:

1. Resource Sharing

Servers provide resources such as:

 Files

 Databases

 Applications

Example:
Company employees accessing a central database server.

2. Centralized Data Management


Data is stored in a central server which ensures:

 Data consistency

 Easy backup

 Security control

Example:
Bank database servers.

3. Scalability

Servers can handle many clients simultaneously.

Example:
Thousands of users accessing Amazon website at the same time.

4. Network Communication

Client–server architecture supports communication using protocols such


as:

 HTTP

 FTP

 SMTP

Example:
Email systems using mail servers.

Advantages of Client–Server Architecture

 Centralized control of resources

 Easy maintenance

 Better security

 Supports large number of clients

 Efficient resource sharing

Disadvantages

 Server failure can affect the whole system


 High server load if many clients connect

 Network dependency

Real Life Examples

Application Client Server

Web
Web browsing Browser
Server

Mail
Email system Email client
Server

Banking Bank
ATM
system Server

Online Mobile app / Web


shopping Browser Server

Conclusion

The Client–Server architectural style is a fundamental architecture


used in distributed systems. It separates the system into clients that
request services and servers that provide services. This model enables
efficient communication, centralized management, scalability, and
resource sharing, making it suitable for modern distributed applications.

5. Role of Publish–Subscribe and MVC Design Patterns in Event-


Driven Systems

Event-driven systems are systems where the flow of the program is


determined by events such as user actions, sensor outputs, or
messages from other programs.

Examples of events:

 Mouse click

 Button press

 Message received

 Data update

Two important design patterns used in event-driven systems are:


 Publish–Subscribe Pattern

 Model–View–Controller (MVC) Pattern

These patterns help in managing events, improving modularity, and


reducing dependencies between components.

1. Publish–Subscribe (Pub-Sub) Design Pattern

Definition

The Publish–Subscribe pattern is a messaging pattern where:

 Publishers send messages or events.

 Subscribers receive those events.

 A message broker/event bus distributes events.

The publisher does not know who the subscribers are, which reduces
coupling.

Publish–Subscribe Architecture
4

Working of Publish–Subscribe

1. Publisher creates an event/message.

2. The event is sent to a message broker or event bus.

3. Subscribers register for specific events.

4. The broker distributes the event to all subscribers.

Example:

Weather Station (Publisher)



Event Broker
↓ ↓
Mobile App Display Board
(Subscribers)

When temperature changes, the publisher sends an event, and all


subscribers receive updates.

Applications of Publish–Subscribe

 Notification systems

 Stock market updates

 Chat applications

 IoT systems

 Microservices communication
Advantages

 Loose coupling between components

 Scalability

 Real-time communication

 Easy addition of new subscribers

2. Model–View–Controller (MVC) Pattern in Event-Driven Systems

Definition

The MVC design pattern divides an application into three components:

1. Model – Manages data and business logic

2. View – Displays data to the user

3. Controller – Handles user input and events

MVC is commonly used in GUI and web applications, which are


naturally event-driven.

MVC Architecture
4

Working of MVC in Event-Driven Systems

1. User performs an action (click, input).

2. The Controller captures the event.

3. Controller updates the Model.

4. Model processes the data.

5. The View displays updated information.

Example:

User clicks "Submit"



Controller receives event

Model updates database

View displays updated result

Example: Online Shopping Website

Model

 Product data

 Order information

 Customer details

View

 Product page

 Shopping cart

 Checkout page

Controller

 Handles add-to-cart events

 Processes payment requests

 Updates order information

Role of These Patterns in Event-Driven Systems

Pattern Role in Event-Driven System

Publish– Handles event communication between


Subscribe components

Organizes application structure and user


MVC
interaction

Comparison of Publish–Subscribe and MVC

Publish–
Feature MVC
Subscribe

Architecture Messaging Structural design


Type pattern pattern
Publish–
Feature MVC
Subscribe

Communicatio Event User interaction


n broadcasting handling

Very low
Coupling Moderate coupling
coupling

Distributed GUI and web


Usage
systems applications

Advantages in Event-Driven Systems

Using these patterns provides:

 Better modularity

 Improved scalability

 Reduced coupling

 Easier maintenance

 Clear separation of responsibilities

Conclusion

Both Publish–Subscribe and MVC design patterns play important roles


in event-driven systems.

 Publish–Subscribe enables efficient communication between


independent components through events.

 MVC organizes application structure by separating data, user


interface, and control logic.

Together, these patterns help build scalable, maintainable, and


responsive event-driven applications.

You might also like