mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-10-03 09:13:27 +00:00
docs: update composite entity
This commit is contained in:
1 parent
1029c02993
commit
518ffa4d4d
1 file changed
+21
-9
@@ -5,7 +5,11 @@ language: en
|
|||||||
tag:
|
tag:
|
||||||
- Client-server
|
- Client-server
|
||||||
- Data access
|
- Data access
|
||||||
|
- Decoupling
|
||||||
- Enterprise patterns
|
- Enterprise patterns
|
||||||
|
- Object composition
|
||||||
|
- Persistence
|
||||||
|
- Resource management
|
||||||
---
|
---
|
||||||
|
|
||||||
## Also known as
|
## Also known as
|
||||||
@@ -20,14 +24,20 @@ The Composite Entity design pattern is aimed at managing a set of interrelated p
|
|||||||
|
|
||||||
Real world example
|
Real world example
|
||||||
|
|
||||||
> For a console, there may be many interfaces that need to be managed and controlled. Using the composite entity pattern, dependent objects such as messages and signals can be combined and controlled using a single object.
|
> Consider a university registration system where a "Student" entity is a composite entity. Each "Student" object includes several dependent objects: personal details, course enrollments, grades, and payment information. Instead of managing each of these aspects separately, the Composite Entity pattern allows the university system to treat the "Student" as a single entity. This simplifies operations such as enrolling a student in a new course, updating grades, and processing payments, since all related actions can be managed through the composite "Student" object.
|
||||||
|
|
||||||
In plain words
|
In plain words
|
||||||
|
|
||||||
> Composite entity pattern allows a set of related objects to be represented and managed by a unified object.
|
> Composite entity pattern allows a set of related objects to be represented and managed by a unified object.
|
||||||
|
|
||||||
|
Wikipedia says
|
||||||
|
|
||||||
|
> Composite entity is a Java EE Software design pattern and it is used to model, represent, and manage a set of interrelated persistent objects rather than representing them as individual fine-grained entity beans, and also a composite entity bean represents a graph of objects.
|
||||||
|
|
||||||
**Programmatic Example**
|
**Programmatic Example**
|
||||||
|
|
||||||
|
For a console, there may be many interfaces that need to be managed and controlled. Using the composite entity pattern, dependent objects such as messages and signals can be combined and controlled using a single object.
|
||||||
|
|
||||||
We need a generic solution for the problem. To achieve this, let's introduce a generic Composite Entity Pattern.
|
We need a generic solution for the problem. To achieve this, let's introduce a generic Composite Entity Pattern.
|
||||||
|
|
||||||
```java
|
```java
|
||||||
@@ -103,17 +113,19 @@ public class CompositeEntity {
|
|||||||
Now managing the assignment of message and signal objects with the composite entity `console`.
|
Now managing the assignment of message and signal objects with the composite entity `console`.
|
||||||
|
|
||||||
```java
|
```java
|
||||||
var console=new CompositeEntity();
|
public App(String message, String signal) {
|
||||||
console.init();
|
var console = new CompositeEntity();
|
||||||
console.setData("No Danger","Green Light");
|
console.init();
|
||||||
Arrays.stream(console.getData()).forEach(LOGGER::info);
|
console.setData(message, signal);
|
||||||
console.setData("Danger","Red Light");
|
Arrays.stream(console.getData()).forEach(LOGGER::info);
|
||||||
Arrays.stream(console.getData()).forEach(LOGGER::info);
|
console.setData("Danger", "Red Light");
|
||||||
|
Arrays.stream(console.getData()).forEach(LOGGER::info);
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Class diagram
|
## Class diagram
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
## Applicability
|
## Applicability
|
||||||
|
|
||||||
@@ -149,7 +161,7 @@ Trade-offs:
|
|||||||
|
|
||||||
## Credits
|
## Credits
|
||||||
|
|
||||||
* [Composite Entity Pattern in wikipedia](https://en.wikipedia.org/wiki/Composite_entity_pattern)
|
|
||||||
* [Core J2EE Patterns: Best Practices and Design Strategies](https://amzn.to/4cAbDap)
|
* [Core J2EE Patterns: Best Practices and Design Strategies](https://amzn.to/4cAbDap)
|
||||||
* [Enterprise Patterns and MDA: Building Better Software with Archetype Patterns and UML](https://amzn.to/49mslqS)
|
* [Enterprise Patterns and MDA: Building Better Software with Archetype Patterns and UML](https://amzn.to/49mslqS)
|
||||||
* [Patterns of Enterprise Application Architecture](https://amzn.to/3xjKdpe)
|
* [Patterns of Enterprise Application Architecture](https://amzn.to/3xjKdpe)
|
||||||
|
* [Composite Entity Pattern (Wikipedia)](https://en.wikipedia.org/wiki/Composite_entity_pattern)
|
||||||
Reference in new issue
Block a user