GitHub - Saiganesh224212/Advanced_Java_Lab: This repository contains all assignments, projects, and Java code for the Advanced Java Lab course, following SOLID principles, design patterns, and coding practices.
This folder contains all the assignments for the Advanced Java Lab (UCSH-605) course, focusing on SOLID principles, Object-Oriented Design, and Java Coding practices.
๐ List of Assignments
| Assignment | Description | Topics Covered |
|---|---|---|
| Assignment 1 | Refactor a Poorly Designed Code (Apply SRP & OCP) | Single Responsibility Principle (SRP), Open/Closed Principle (OCP) |
| Assignment 2 | Implement Liskov Substitution Principle (LSP) | Liskov Substitution Principle (LSP), Class Hierarchy Design |
| Assignment 3 | Payment Processing System (Applying All SOLID Principles) | SOLID Principles, Interface Segregation, Dependency Inversion |
| Assignment 4 | Chat App using Socket Programming in Java | 1) One-to-One 2) One-to-Many |
๐น Assignment 1: Refactor a Poorly Designed Code (SRP & OCP)
๐ Problem Statement
The given Java code violates SRP (Single Responsibility Principle) and OCP (Open/Closed Principle).
Refactor the code to:
- Separate concerns properly (SRP)
- Make it extensible for new storage types without modifying the base class (OCP)
๐ Files
easy1.javaOriginal code violating SOLID principles โ Refactored version following SRP & OCP.
๐ Topics Covered
โ
Single Responsibility Principle (SRP) โ Ensure each class has a single responsibility.
โ
Open/Closed Principle (OCP) โ Allow extension without modifying existing code.
๐น Assignment 2: Implement Liskov Substitution Principle (LSP)
๐ Problem Statement
A Penguin class extends Bird, but Bird has a fly() method. This violates LSP because not all birds can fly.
๐ Task
- Identify the issue in the hierarchy.
- Refactor the design to follow LSP.
- Ensure subclasses can replace the base class without breaking behavior.
๐ Files
easy2.java- Before Refactoring โ Penguin inherits
fly(), violating LSP. - After Refactoring โ Introduces
Birdas an abstract class andCanFlyinterface.
- Before Refactoring โ Penguin inherits
๐ Topics Covered
โ
Liskov Substitution Principle (LSP) โ Subclasses must be replaceable without altering system correctness.
โ
Proper Class Hierarchy Design โ Use abstraction to define capabilities correctly.
๐น Assignment 3: Design a Payment Processing System (SOLID)
๐ Problem Statement
Create a scalable and maintainable payment processing system supporting:
- Credit Card
- PayPal
- Google Pay
๐ Requirements
โ
Follow SOLID Principles
โ
Allow adding new payment methods without modifying existing code
โ
Use dependency injection for flexibility
๐ Class Structure
PaymentService (Interface)
โโโ CreditCardPayment (Implements PaymentService)
โโโ PayPalPayment (Implements PaymentService)
โโโ GooglePayPayment (Implements PaymentService)
PaymentProcessor
PaymentLogger
PaymentServiceManager
Main
๐ Files
diffass3.java Implements all SOLID principles in a payment system.
๐ Topics Covered
โ
Single Responsibility Principle (SRP) โ Separate payment processing, logging, and transaction handling.
โ
Open/Closed Principle (OCP) โ Allow new payment methods without modifying existing code.
โ
Liskov Substitution Principle (LSP) โ Ensure each payment method behaves correctly as a PaymentService.
โ
Interface Segregation Principle (ISP) โ Keep interfaces minimal and focused.
โ
Dependency Inversion Principle (DIP) โ Depend on abstractions (PaymentService), not concrete implementations.
how_to_run: steps:
- step: Clone the repository
command: |
git clone https://github.com/Saiganesh224212/Advanced_Java_Lab.git
- step: Compile Java files
commands:
- javac easy1.java
- javac easy2.java
- javac diffass3.java
- step: Run Java programs
commands:
- java easy1
- java easy2
- java diffass3