Skip to content

Commit 0dc87ed

Browse files
authored
Merge branch 'master' into master
2 parents a53c5d9 + e17f138 commit 0dc87ed

28 files changed

+1529
-13
lines changed

Diff for: .all-contributorsrc

+18
Original file line numberDiff line numberDiff line change
@@ -3393,6 +3393,24 @@
33933393
"contributions": [
33943394
"code"
33953395
]
3396+
},
3397+
{
3398+
"login": "MohanedAtef238",
3399+
"name": "Mohaned Atef",
3400+
"avatar_url": "https://avatars.githubusercontent.com/u/105852138?v=4",
3401+
"profile": "https://github.com/MohanedAtef238",
3402+
"contributions": [
3403+
"code"
3404+
]
3405+
},
3406+
{
3407+
"login": "maximevtush",
3408+
"name": "Maxim Evtush",
3409+
"avatar_url": "https://avatars.githubusercontent.com/u/154841002?v=4",
3410+
"profile": "https://github.com/maximevtush",
3411+
"contributions": [
3412+
"code"
3413+
]
33963414
}
33973415
],
33983416
"contributorsPerLine": 6,

Diff for: README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=iluwatar_java-design-patterns&metric=coverage)](https://sonarcloud.io/dashboard?id=iluwatar_java-design-patterns)
77
[![Join the chat at https://gitter.im/iluwatar/java-design-patterns](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/iluwatar/java-design-patterns?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
88
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
9-
[![All Contributors](https://img.shields.io/badge/all_contributors-372-orange.svg?style=flat-square)](#contributors-)
9+
[![All Contributors](https://img.shields.io/badge/all_contributors-374-orange.svg?style=flat-square)](#contributors-)
1010
<!-- ALL-CONTRIBUTORS-BADGE:END -->
1111

1212
<br/>
@@ -556,6 +556,10 @@ This project is licensed under the terms of the MIT license.
556556
<td align="center" valign="top" width="16.66%"><a href="https://github.com/clintaire"><img src="https://avatars.githubusercontent.com/u/111376518?v=4?s=100" width="100px;" alt="Clint Airé"/><br /><sub><b>Clint Airé</b></sub></a><br /><a href="https://github.com/iluwatar/java-design-patterns/commits?author=clintaire" title="Code">💻</a></td>
557557
<td align="center" valign="top" width="16.66%"><a href="https://github.com/darkhyper24"><img src="https://avatars.githubusercontent.com/u/132711528?v=4?s=100" width="100px;" alt="darkhyper24"/><br /><sub><b>darkhyper24</b></sub></a><br /><a href="https://github.com/iluwatar/java-design-patterns/commits?author=darkhyper24" title="Code">💻</a></td>
558558
</tr>
559+
<tr>
560+
<td align="center" valign="top" width="16.66%"><a href="https://github.com/MohanedAtef238"><img src="https://avatars.githubusercontent.com/u/105852138?v=4?s=100" width="100px;" alt="Mohaned Atef"/><br /><sub><b>Mohaned Atef</b></sub></a><br /><a href="https://github.com/iluwatar/java-design-patterns/commits?author=MohanedAtef238" title="Code">💻</a></td>
561+
<td align="center" valign="top" width="16.66%"><a href="https://github.com/maximevtush"><img src="https://avatars.githubusercontent.com/u/154841002?v=4?s=100" width="100px;" alt="Maxim Evtush"/><br /><sub><b>Maxim Evtush</b></sub></a><br /><a href="https://github.com/iluwatar/java-design-patterns/commits?author=maximevtush" title="Code">💻</a></td>
562+
</tr>
559563
</tbody>
560564
</table>
561565

Diff for: bloc/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<dependency>
1919
<groupId>org.testng</groupId>
2020
<artifactId>testng</artifactId>
21-
<version>7.7.1</version>
21+
<version>7.11.0</version>
2222
<scope>test</scope>
2323
</dependency>
2424
<dependency>

Diff for: caching/etc/caching.urm.puml

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ package com.iluwatar.caching {
1313
- LOGGER : Logger {static}
1414
+ App()
1515
+ main(args : String[]) {static}
16-
+ useCacheAsideStategy()
16+
+ useCacheAsideStrategy()
1717
+ useReadAndWriteThroughStrategy()
1818
+ useReadThroughAndWriteAroundStrategy()
1919
+ useReadThroughAndWriteBehindStrategy()
@@ -116,4 +116,4 @@ Node --> "-previous" Node
116116
AppManager --> "-cachingPolicy" CachingPolicy
117117
Node --> "-userAccount" UserAccount
118118
CacheStore --> "-cache" LruCache
119-
@enduml
119+
@enduml

Diff for: caching/src/main/java/com/iluwatar/caching/App.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public static void main(final String[] args) {
133133
LOGGER.info(splitLine);
134134
app.useReadThroughAndWriteBehindStrategy();
135135
LOGGER.info(splitLine);
136-
app.useCacheAsideStategy();
136+
app.useCacheAsideStrategy();
137137
LOGGER.info(splitLine);
138138
}
139139

@@ -224,7 +224,7 @@ public void useReadThroughAndWriteBehindStrategy() {
224224
/**
225225
* Cache-Aside.
226226
*/
227-
public void useCacheAsideStategy() {
227+
public void useCacheAsideStrategy() {
228228
LOGGER.info("# CachingPolicy.ASIDE");
229229
appManager.initCachingPolicy(CachingPolicy.ASIDE);
230230
LOGGER.info(appManager.printCacheContent());

Diff for: caching/src/test/java/com/iluwatar/caching/CachingTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,6 @@ void testReadThroughAndWriteBehindStrategy() {
6868
@Test
6969
void testCacheAsideStrategy() {
7070
assertNotNull(app);
71-
app.useCacheAsideStategy();
71+
app.useCacheAsideStrategy();
7272
}
7373
}

Diff for: money/src/main/java/com/iluwatar/CannotSubtractException.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.iluwatar;
22
/**
3-
* An exception for when the user tries to subtract two diffrent currencies or subtract an amount he doesn't have.
3+
* An exception for when the user tries to subtract two different currencies or subtract an amount he doesn't have.
44
*/
55
public class CannotSubtractException extends Exception {
66
/**
@@ -12,4 +12,4 @@ public CannotSubtractException(String message) {
1212
super(message);
1313
}
1414

15-
}
15+
}

Diff for: monolithic-architecture/README.md

+150
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
---
2+
title: "Monolithic Ecommerce App: A Cohesive Application Model"
3+
shortTitle: Monolithic Ecommerce
4+
description: "Explore the Monolithic Ecommerce application structure, its design intent, benefits, limitations, and real-world applications. Understand its simplicity and practical use cases."
5+
category: Architectural
6+
language: en
7+
tag:
8+
- Cohesion
9+
- Simplicity
10+
- Scalability
11+
- Deployment
12+
- Maintainability
13+
---
14+
15+
## Monolithic-Ecommerce App
16+
* A Monolithic Ecommerce example to showcase Monolithic Architecture
17+
18+
## The Intent of Monolithic Design pattern
19+
> the Monolithic Design Pattern structures an application as a single, cohesive unit where all components—such as business logic, user interface, and data access are tightly integrated and operate as part of a single executable.
20+
21+
## Detailed Explanation of the Monolithic Architecture
22+
Real-world Example
23+
> A traditional E-commerce website is the most straightforward example for a monolithic application as it is comprised of a catalogue of products, orders to be made, shopping carts, and payment processes that are all inseperable of each other.
24+
25+
In Plain words
26+
>The monolithic design pattern structures an application as a single unified unit, where all components are tightly coupled and run within a single process.
27+
28+
GeeksforGeeks states
29+
> Monolithic architecture, a traditional approach in system design, which contains all application components into a single codebase. This unified structure simplifies development and deployment processes, offering ease of management and tight integration. However, because of its rigidity, it is difficult to scale and maintain, which makes it difficult to adjust to changing needs.
30+
31+
Why use MVC for a Monolithic Application ?
32+
>The Model-View-Controller (MVC) pattern is not inherently tied to microservices or distributed systems. It's a software design pattern that organizes the codebase by separating concerns into three distinct layers:
33+
>* Model
34+
>* View
35+
>* Controller
36+
>
37+
> this also helps maintain the principles of a Monolithic Architecture which are:
38+
>
39+
> Simple to
40+
>* Develop
41+
>* Test
42+
>* Deploy
43+
>* Scale
44+
>
45+
## We can clearly see that this is a Monolithic application through the main class
46+
This is a simplified version of the main application that shows the main interaction point with the CLI and how a user is registered
47+
```java
48+
@SpringBootApplication
49+
public class EcommerceApp implements CommandLineRunner {
50+
51+
private static final Logger log = LogManager.getLogger(EcommerceApp.class);
52+
private final UserCon userService;
53+
private final ProductCon productService;
54+
private final OrderCon orderService;
55+
public EcommerceApp(UserCon userService, ProductCon productService, OrderCon orderService) {
56+
this.userService = userService;
57+
this.productService = productService;
58+
this.orderService = orderService;
59+
}
60+
public static void main(String... args) {
61+
SpringApplication.run(EcommerceApp.class, args);
62+
}
63+
@Override
64+
public void run(String... args) {
65+
Scanner scanner = new Scanner(System.in, StandardCharsets.UTF_8);
66+
67+
log.info("Welcome to the Monolithic E-commerce CLI!");
68+
while (true) {
69+
log.info("\nChoose an option:");
70+
log.info("1. Register User");
71+
log.info("2. Add Product");
72+
log.info("3. Place Order");
73+
log.info("4. Exit");
74+
log.info("Enter your choice: ");
75+
76+
int userInput = scanner.nextInt();
77+
scanner.nextLine();
78+
79+
switch (userInput) {
80+
case 1 -> registerUser(scanner);
81+
case 2 -> addProduct(scanner);
82+
case 3 -> placeOrder(scanner);
83+
case 4 -> {
84+
log.info("Exiting the application. Goodbye!");
85+
return;
86+
}
87+
default -> log.info("Invalid choice! Please try again.");
88+
}
89+
}
90+
}
91+
protected void registerUser(Scanner scanner) {
92+
log.info("Enter user details:");
93+
log.info("Name: ");
94+
String name = scanner.nextLine();
95+
log.info("Email: ");
96+
String email = scanner.nextLine();
97+
log.info("Password: ");
98+
String password = scanner.nextLine();
99+
100+
User user = new User(null, name, email, password);
101+
userService.registerUser(user);
102+
log.info("User registered successfully!");
103+
}
104+
105+
}
106+
```
107+
### We can clearly reach the conclusion that all of these classes reside under the same module and are essential for each other's functionality, this is supported by the presence of all relevant classes as parts of the main application class.
108+
109+
## When should you resort to a Monolithic Architecture ?
110+
>* An enterprise Starting off with a relatively small team
111+
>* Simplicity is the most important factor of the project
112+
>* Maintaining less entry points to the system is cruical
113+
>* Prototyping ideas
114+
>
115+
## Pros & Cons of using Monolithic Architecture
116+
>### Pros:
117+
>* Simple Development: Easy to develop and deploy.
118+
>* Unified Codebase: All code in one place, simplifying debugging.
119+
>* Better Performance: No inter-service communication overhead.
120+
>* Lower Costs: Minimal infrastructure and tooling requirements.
121+
>* Ease of Testing: Single application makes end-to-end testing straightforward.
122+
> * This is also assisted by the MVC structure employed in this example.
123+
>### Cons:
124+
>* Scalability Issues: Cannot scale individual components.
125+
>* Tight Coupling: Changes in one area may impact the whole system.
126+
>* Deployment Risks: A single failure can crash the entire application.
127+
>* Complex Maintenance: Harder to manage as the codebase grows.
128+
>* Limited Flexibility: Difficult to adopt new technologies for specific parts.
129+
130+
## Real-World Applications of Monolithic architecture Pattern in Java
131+
>* E-Commerce Platforms
132+
>* Content Management Systems (CMS)
133+
>* Banking and Financial Systems
134+
>* Enterprise Resource Planning (ERP) Systems
135+
>* Retail Point of Sale (POS) Systems
136+
137+
## References
138+
>* [GeeksforGeeks](https://www.geeksforgeeks.org/monolithic-architecture-system-design/)
139+
>* [Wikipedia](https://en.wikipedia.org/wiki/Monolithic_application)
140+
>* [vFunction](https://vfunction.com/blog/what-is-monolithic-application/#:~:text=A%20traditional%20e%2Dcommerce%20platform,inseparable%20components%20of%20the%20system.) Blog post
141+
>* [Microservices.io](https://microservices.io/patterns/monolithic.html)
142+
>* [IBM](https://www.ibm.com/think/topics/monolithic-architecture)
143+
>#### References used to create the code
144+
>* [Mockito](https://site.mockito.org/) -Testing
145+
>* [Junit](https://junit.org/junit5/docs/current/user-guide/) -Testing
146+
>* [Springboot](https://docs.spring.io/spring-boot/index.html) -Web Application Initiation (implemented but not utilized in this example)
147+
>* [Sprint Data Jpa](https://docs.spring.io/spring-data/jpa/reference/index.html) -Database connection
148+
>* [Lombok](https://projectlombok.org/) -Simplifying Classes
149+
>* [Log4j](https://logging.apache.org/log4j/2.x/index.html) -Capturing Logs
150+
>* [H2 Databse](https://www.h2database.com/html/tutorial.html) -Efficient, Simple, Dynamic Databse
+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
@startuml
2+
package com.iluwatar.monolithic.model {
3+
class Orders {
4+
- id : Long
5+
- product : Products
6+
- quantity : Integer
7+
- totalPrice : Double
8+
- user : User
9+
+ Orders()
10+
+ Orders(id : Long, user : User, product : Products, quantity : Integer, totalPrice : Double)
11+
# canEqual(other : Object) : boolean
12+
+ equals(o : Object) : boolean
13+
+ getId() : Long
14+
+ getProduct() : Products
15+
+ getQuantity() : Integer
16+
+ getTotalPrice() : Double
17+
+ getUser() : User
18+
+ hashCode() : int
19+
+ setId(id : Long)
20+
+ setProduct(product : Products)
21+
+ setQuantity(quantity : Integer)
22+
+ setTotalPrice(totalPrice : Double)
23+
+ setUser(user : User)
24+
+ toString() : String
25+
}
26+
class Products {
27+
- description : String
28+
- id : Long
29+
- name : String
30+
- price : Double
31+
- stock : Integer
32+
+ Products()
33+
+ Products(id : Long, name : String, description : String, price : Double, stock : Integer)
34+
# canEqual(other : Object) : boolean
35+
+ equals(o : Object) : boolean
36+
+ getDescription() : String
37+
+ getId() : Long
38+
+ getName() : String
39+
+ getPrice() : Double
40+
+ getStock() : Integer
41+
+ hashCode() : int
42+
+ setDescription(description : String)
43+
+ setId(id : Long)
44+
+ setName(name : String)
45+
+ setPrice(price : Double)
46+
+ setStock(stock : Integer)
47+
+ toString() : String
48+
}
49+
class User {
50+
- email : String
51+
- id : Long
52+
- name : String
53+
- password : String
54+
+ User()
55+
+ User(id : Long, name : String, email : String, password : String)
56+
# canEqual(other : Object) : boolean
57+
+ equals(o : Object) : boolean
58+
+ getEmail() : String
59+
+ getId() : Long
60+
+ getName() : String
61+
+ getPassword() : String
62+
+ hashCode() : int
63+
+ setEmail(email : String)
64+
+ setId(id : Long)
65+
+ setName(name : String)
66+
+ setPassword(password : String)
67+
+ toString() : String
68+
}
69+
}
70+
package com.iluwatar.monolithic.repository {
71+
interface OrderRepo {
72+
}
73+
interface ProductRepo {
74+
}
75+
interface UserRepo {
76+
+ findByEmail(String) : User {abstract}
77+
}
78+
}
79+
package com.iluwatar.monolithic.controller {
80+
class OrderCon {
81+
- orderRepository : OrderRepo
82+
- productRepository : ProductRepo
83+
- userRepository : UserRepo
84+
+ OrderCon(orderRepository : OrderRepo, userRepository : UserRepo, productRepository : ProductRepo)
85+
+ placeOrder(userId : Long, productId : Long, quantity : Integer) : Orders
86+
}
87+
class ProductCon {
88+
- productRepository : ProductRepo
89+
+ ProductCon(productRepository : ProductRepo)
90+
+ addProduct(product : Products) : Products
91+
+ getAllProducts() : List<Products>
92+
}
93+
class UserCon {
94+
- userRepository : UserRepo
95+
+ UserCon(userRepository : UserRepo)
96+
+ registerUser(user : User) : User
97+
}
98+
}
99+
package com.iluwatar.monolithic {
100+
class EcommerceApp {
101+
- log : Logger {static}
102+
- orderService : OrderCon
103+
- productService : ProductCon
104+
- userService : UserCon
105+
+ EcommerceApp(userService : UserCon, productService : ProductCon, orderService : OrderCon)
106+
# addProduct(scanner : Scanner)
107+
+ main(args : String[]) {static}
108+
# placeOrder(scanner : Scanner)
109+
# registerUser(scanner : Scanner)
110+
+ run(args : String[])
111+
}
112+
}
113+
UserCon --> "-userRepository" UserRepo
114+
Orders --> "-user" User
115+
OrderCon --> "-productRepository" ProductRepo
116+
OrderCon --> "-userRepository" UserRepo
117+
OrderCon --> "-orderRepository" OrderRepo
118+
EcommerceApp --> "-userService" UserCon
119+
EcommerceApp --> "-productService" ProductCon
120+
ProductCon --> "-productRepository" ProductRepo
121+
Orders --> "-product" Products
122+
EcommerceApp --> "-orderService" OrderCon
123+
@enduml

0 commit comments

Comments
 (0)