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.
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 |
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)
easy1.java
Original code violating SOLID principles β Refactored version following SRP & OCP.
β
Single Responsibility Principle (SRP) β Ensure each class has a single responsibility.
β
Open/Closed Principle (OCP) β Allow extension without modifying existing code.
A Penguin
class extends Bird
, but Bird
has a fly()
method. This violates LSP because not all birds can fly.
- Identify the issue in the hierarchy.
- Refactor the design to follow LSP.
- Ensure subclasses can replace the base class without breaking behavior.
easy2.java
- Before Refactoring β Penguin inherits
fly()
, violating LSP. - After Refactoring β Introduces
Bird
as an abstract class andCanFly
interface.
- Before Refactoring β Penguin inherits
β
Liskov Substitution Principle (LSP) β Subclasses must be replaceable without altering system correctness.
β
Proper Class Hierarchy Design β Use abstraction to define capabilities correctly.
Create a scalable and maintainable payment processing system supporting:
- Credit Card
- PayPal
- Google Pay
β
Follow SOLID Principles
β
Allow adding new payment methods without modifying existing code
β
Use dependency injection for flexibility
PaymentService (Interface)
βββ CreditCardPayment (Implements PaymentService)
βββ PayPalPayment (Implements PaymentService)
βββ GooglePayPayment (Implements PaymentService)
PaymentProcessor
PaymentLogger
PaymentServiceManager
Main
diffass3.java Implements all SOLID principles in a payment system.
β
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