Skip to content

Commit 2e65fd8

Browse files
committed
Initial
1 parent 03c36dc commit 2e65fd8

File tree

13 files changed

+179
-0
lines changed

13 files changed

+179
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import custom.PaymentStatus;
2+
import customExceptions.PaymentException;
3+
4+
public class BankTransfer implements Payment{
5+
@Override
6+
public boolean validatePayment() throws PaymentException {
7+
return false;
8+
}
9+
10+
@Override
11+
public PaymentStatus processPayment(double amount) throws PaymentException {
12+
return null;
13+
}
14+
15+
@Override
16+
public PaymentStatus refundPayment(String transactionId) throws PaymentException {
17+
return null;
18+
}
19+
20+
@Override
21+
public PaymentStatus getPaymentStatus(String transactionId) {
22+
return null;
23+
}
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import custom.PaymentStatus;
2+
import customExceptions.PaymentException;
3+
4+
public class CreditCardPayment implements Payment{
5+
@Override
6+
public boolean validatePayment() throws PaymentException {
7+
return false;
8+
}
9+
10+
@Override
11+
public PaymentStatus processPayment(double amount) throws PaymentException {
12+
return null;
13+
}
14+
15+
@Override
16+
public PaymentStatus refundPayment(String transactionId) throws PaymentException {
17+
return null;
18+
}
19+
20+
@Override
21+
public PaymentStatus getPaymentStatus(String transactionId) {
22+
return null;
23+
}
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import custom.PaymentStatus;
2+
import customExceptions.PaymentException;
3+
4+
public class PayPal implements Payment{
5+
@Override
6+
public boolean validatePayment() throws PaymentException {
7+
return false;
8+
}
9+
10+
@Override
11+
public PaymentStatus processPayment(double amount) throws PaymentException {
12+
return null;
13+
}
14+
15+
@Override
16+
public PaymentStatus refundPayment(String transactionId) throws PaymentException {
17+
return null;
18+
}
19+
20+
@Override
21+
public PaymentStatus getPaymentStatus(String transactionId) {
22+
return null;
23+
}
24+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import custom.PaymentStatus;
2+
import customExceptions.PaymentException;
3+
4+
public interface Payment {
5+
boolean validatePayment() throws PaymentException;
6+
PaymentStatus processPayment(double amount) throws PaymentException;
7+
PaymentStatus refundPayment(String transactionId) throws PaymentException;
8+
PaymentStatus getPaymentStatus(String transactionId);
9+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
public class PaymentFactory {
2+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
public class PaymentService {
2+
public static void main(String[] args) {
3+
4+
}
5+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
## Payment Processing System
2+
3+
Imagine you're building a payment processing system that needs to handle multiple payment methods (Credit Card, PayPal, Stripe, Bank Transfer). Different clients (web app, mobile app, POS systems) need to process payments, but:
4+
5+
1. The payment processing system shouldn't know the specific details of how each payment method works (Dependency Inversion)
6+
2. Payment methods may change or new ones may be added in the future
7+
3. Each payment method has different validation rules and processing flows
8+
4. The system needs to handle different payment flows while keeping the core business logic separate from payment implementation details
9+
10+
Specific requirements that make this a good scenario:
11+
- Each payment method needs to validate payment details differently:
12+
- Credit Card needs card number, CVV, expiry validation
13+
- PayPal needs email and PayPal token validation
14+
- Bank Transfer needs account number and routing number validation
15+
- Stripe needs Stripe token and customer ID validation
16+
17+
- Each payment has common operations but different implementations:
18+
- validatePayment()
19+
- processPayment()
20+
- refundPayment()
21+
- getPaymentStatus()
22+
23+
This scenario demonstrates both Factory Pattern and Dependency Inversion because:
24+
1. Factory Pattern: Creates different payment processors without exposing instantiation logic
25+
2. Dependency Inversion: High-level modules (payment processing) depend on abstractions (payment interface), not concrete implementations
26+
27+
The client code should be able to process payments without knowing the specific payment method implementation
28+
29+
This is a real-world scenario because:
30+
- Payment processing is a common requirement
31+
- It has clear separation of concerns
32+
- It demonstrates practical use of interfaces and abstractions
33+
- It's easily extendable for new payment methods
34+
- It reflects actual business requirements in financial systems
35+
36+
Would you like me to provide the implementation for this scenario?
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import custom.PaymentStatus;
2+
import customExceptions.PaymentException;
3+
4+
public class Stripe implements Payment{
5+
@Override
6+
public boolean validatePayment() throws PaymentException {
7+
return false;
8+
}
9+
10+
@Override
11+
public PaymentStatus processPayment(double amount) throws PaymentException {
12+
return null;
13+
}
14+
15+
@Override
16+
public PaymentStatus refundPayment(String transactionId) throws PaymentException {
17+
return null;
18+
}
19+
20+
@Override
21+
public PaymentStatus getPaymentStatus(String transactionId) {
22+
return null;
23+
}
24+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package custom;
2+
3+
public enum PaymentStatus {
4+
PENDING,
5+
SUCCESSFUL,
6+
FAILED,
7+
REFUNDED
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package custom;
2+
3+
public enum PaymentType {
4+
CREDIT_CARD,
5+
PAYPAL,
6+
STRIPE,
7+
BANK_TRANSFER
8+
}

0 commit comments

Comments
 (0)