Skip to content

Commit ebc4282

Browse files
author
Araf Karsh Hamid
committed
Added Java 23 SOLID Examples
1 parent eb5e7ea commit ebc4282

51 files changed

Lines changed: 4128 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

images/Java-Logo.webp

9.9 KB
Loading

images/Java-SOLID-Bank-Ex.jpg

214 KB
Loading
160 KB
Loading

images/Java-SOLID-ISP-1.jpg

146 KB
Loading

images/Java-SOLID-LSP-1.jpg

104 KB
Loading

images/Java-SOLID-LSP-2.jpg

107 KB
Loading

images/Java-SOLID-OCP-1.jpg

78.8 KB
Loading

images/Java-SOLID.jpg

175 KB
Loading
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/**
2+
* (C) Copyright 2024 Araf Karsh Hamid
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package designPatterns.core;
17+
18+
import java.util.List;
19+
20+
/**
21+
* SOLID Examples
22+
*
23+
* Dependency Inversion Principle (DIP):
24+
* High-level modules should not depend on low-level modules. Both should depend on
25+
* abstractions (e.g., interfaces), not on concretions (e.g., classes).
26+
*
27+
* Handle all Bank Account related Activities
28+
*
29+
* The refactored Code has 1 Responsibility
30+
* 1. Deposit and Withdrawal
31+
*
32+
* Finally, DIP ensures that both high-level and low-level modules depend on abstractions.
33+
* - Notification implementation is completely abstracted away.
34+
* - Notification is loaded based on the Conditions defined in the Property File.
35+
* - Check the BankNotificationConfiguration class for conditional loading.
36+
*
37+
* @author: Araf Karsh Hamid
38+
* @version:
39+
* @date:
40+
*/
41+
public interface BankAccountRepositoryInterface {
42+
43+
/**
44+
* Save Account Details
45+
* @param notification
46+
*/
47+
public void saveBankDetails(Object accountDetails);
48+
49+
/**
50+
* Get the Statement of Records
51+
*
52+
* @param accountNumber
53+
* @param fromTime
54+
* @param toTime
55+
* @return
56+
*/
57+
public List getStatements(String accountNumber, Object fromTime, Object toTime);
58+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/**
2+
* (C) Copyright 2024 Araf Karsh Hamid
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package designPatterns.core;
17+
18+
import java.util.List;
19+
20+
/**
21+
* SOLID Examples
22+
*
23+
* Single Responsibility Principle (SRP)
24+
* A class should have only one reason to change, meaning it should have only one j
25+
* ob or responsibility.
26+
*
27+
* The refactored Code has 1 Responsibility
28+
* 1. Save Account Details
29+
* 2. Get Account Statements
30+
*
31+
* With Single Responsibility Pattern the Handling of Save Account Details
32+
* and sending Notification must be done in separate classes.
33+
*
34+
* @author: Araf Karsh Hamid
35+
* @version:
36+
* @date:
37+
*/
38+
public class BankAccountRepositoryService implements BankAccountRepositoryInterface {
39+
40+
// This is pseudo code to explain the Single Responsibility Principle
41+
42+
/**
43+
* Save Account Details
44+
*
45+
* @param accountDetails
46+
*/
47+
@Override
48+
public void saveBankDetails(Object accountDetails) {
49+
// Code to Save
50+
}
51+
52+
/**
53+
* Get the Statement of Records
54+
*
55+
* @param accountNumber
56+
* @param fromTime
57+
* @param toTime
58+
* @return
59+
*/
60+
@Override
61+
public List getStatements(String accountNumber, Object fromTime, Object toTime) {
62+
// pseudo code to return data
63+
return List.of();
64+
}
65+
}

0 commit comments

Comments
 (0)