mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-14 16:58:47 +00:00
task: Add Composite Entity pattern (#1705)
* add composite entity pattern * add composite entity pattern * Update ReactorTest.java * resolve some code quality problems * modified a lot * remove some extra codes * modified README * removed the author name and adjusted the spacing Co-authored-by: zwebrain <11811721@mail.sustech.edu.cn> Co-authored-by: Subhrodip Mohanta <hello@subho.xyz>
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
package com.iluwatar.compositeentity;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
/**
|
||||
* A coarse-grained object is an object with its own life cycle manages its own relationships to
|
||||
* other objects. It can be an object contained in the composite entity, or, composite entity itself
|
||||
* can be the coarse-grained object which holds dependent objects.
|
||||
*/
|
||||
|
||||
public abstract class CoarseGrainedObject<T> {
|
||||
|
||||
DependentObject<T>[] dependentObjects;
|
||||
|
||||
public void setData(T... data) {
|
||||
IntStream.range(0, data.length).forEach(i -> dependentObjects[i].setData(data[i]));
|
||||
}
|
||||
|
||||
public T[] getData() {
|
||||
return (T[]) Arrays.stream(dependentObjects).map(DependentObject::getData).toArray();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user