Professional Documents
Culture Documents
Lab Session 10 (Sda)
Lab Session 10 (Sda)
Lab Session 10 (Sda)
while (true) {
// Wait for a client connection
Socket clientSocket = serverSocket.accept();
System.out.println("Connection from: " + clientSocket);
while (true) {
Socket clientSocket = serverSocket.accept();
System.out.println("Connection from: " + clientSocket);
clientSocket.close();
}
} catch (IOException e) {
System.err.println("Error: " + e.getMessage());
}
}
}
while (true) {
Socket clientSocket = serverSocket.accept();
System.out.println("Connection from: " + clientSocket);
@Override
public void run() {
try {
BufferedReader in = new BufferedReader(new
InputStreamReader(clientSocket.getInputStream()));
PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
clientSocket.close();
} catch (IOException e) {
System.err.println("Error: " + e.getMessage());
}
}
}
Layered Architecture:
Exercise:
You are tasked with designing a web application for an online bookstore. The application should
allow users to browse books, add them to their cart, and proceed to checkout. Design the
architecture of the application following a layered architecture pattern.
Instructions:
1. Define the three layers of the application: presentation layer, business logic layer,
and data access layer(code)
public BookRepository() {
// Initialize books (e.g., from a database)
}
DOMAIN MODEL:
public class Book {
private int id;
private String title;
private String author;
private double price;
ANSWER:
The responsibilities of each layer are as follows:
Presentation Layer:
Is responsible of managing user interactions and providing information to the
user. In this instance, it shows the user interface for the bookstore and relays user
input to the business logic layer.
3. Identify the interactions between the layers and define the interfaces between them.
ANSWER:
The presentation layer interacts with the business logic layer by calling methods of
the BookService class.
The business logic layer interacts with the data access layer by calling methods of the
BookRepository class.
The data access layer interacts with the database to perform CRUD (Create, Read,
Update, Delete) operations on book data.
4. Discuss how changes in one layer may affect other layers and how the layered
architecture promotes modularity and maintainability.
ANSWER:
To deal with new user interactions, adjustments in the business logic layer may be
necessary in response to presentation layer modifications like UI redesigns or
feature additions.
The presentation layer may need to be updated to reflect changes in user interface
behaviour resulting from modifications or additions to business rules made in the
business logic layer.
Changes to the display layer and business logic layer may be necessary to deal
with modifications to the data access layer, such as moving to an other ORM
framework or database.
ANSWER:
Presentation Layer: JavaFX, Java Servlets, Thymeleaf, Angular, React.
Business Logic Layer: Spring Framework, Java EE, EJB (Enterprise JavaBeans).
Data Access Layer: JDBC (Java Database Connectivity), JPA (Java Persistence
API), Hibernate, Spring Data.
These technologies and frameworks can be used to implement each layer efficiently,
providing various features and tools to facilitate development and maintainability.