Skip to content

Commit f6e1518

Browse files
committed
docs: update composite view
1 parent 8189457 commit f6e1518

File tree

3 files changed

+18
-23
lines changed

3 files changed

+18
-23
lines changed

composite-view/README.md

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ title: Composite View
33
category: Structural
44
language: en
55
tag:
6+
- Abstraction
67
- Enterprise patterns
8+
- Object composition
79
- Presentation
810
---
911

@@ -13,20 +15,22 @@ The primary goal of the Composite View design pattern is to compose objects into
1315

1416
## Explanation
1517

16-
Real World Example
18+
Real-world example
1719

18-
> A news site wants to display the current date and news to different users based on that user's preferences. The news site will substitute in different news feed components depending on the user's interest, defaulting to local news.
20+
> A real-world example of the Composite View design pattern is the layout of a dashboard in a web application. Consider a financial dashboard that displays various widgets such as stock charts, recent transactions, account balances, and news feeds. Each of these widgets is a separate view component that can be independently updated and managed. By using the Composite View pattern, these individual widgets are composed into a single unified dashboard view. This approach allows for easy reorganization of the dashboard, the addition of new widgets without disrupting existing ones, and consistent management of the overall layout. This hierarchical composition of views mirrors how different sections of the dashboard are treated both as individual entities and as part of a larger whole.
1921
20-
In Plain Words
22+
In plain words
2123

2224
> Composite View Pattern is having a main view being composed of smaller subviews. The layout of this composite view is based on a template. A View-manager then decides which subviews to include in this template.
2325
24-
Wikipedia Says
26+
Wikipedia says
2527

2628
> Composite views that are composed of multiple atomic subviews. Each component of the template may be included dynamically into the whole and the layout of the page may be managed independently of the content. This solution provides for the creation of a composite view based on the inclusion and substitution of modular dynamic and static template fragments. It promotes the reuse of atomic portions of the view by encouraging modular design.
2729
2830
**Programmatic Example**
2931

32+
A news site wants to display the current date and news to different users based on that user's preferences. The news site will substitute in different news feed components depending on the user's interest, defaulting to local news.
33+
3034
Since this is a web development pattern, a server is required to demonstrate it. This example uses Tomcat 10.0.13 to run the servlet, and this programmatic example will only work with Tomcat 10+.
3135

3236
Firstly, there is `AppServlet` which is an `HttpServlet` that runs on Tomcat 10+.
@@ -285,11 +289,6 @@ Here are two examples of the mock atomic subviews used in the composite: `busine
285289
</html>
286290
```
287291

288-
The results are as such:
289-
290-
1) The user has put their name as `Tammy` in the request parameters and no preferences: ![alt text](./etc/images/noparam.png)
291-
2) The user has put their name as `Johnny` in the request parameters and has a preference for world, business, and science news: ![alt text](./etc/images/threeparams.png)
292-
293292
The different subviews such as `worldNews.jsp`, `businessNews.jsp`, etc. are included conditionally based on the request parameters.
294293

295294
**How To Use**
@@ -302,12 +301,6 @@ Under `Run` and `edit configurations` Make sure Tomcat server is one of the run
302301

303302
Ensure that the artifact is being built from the content of the `web` directory and the compilation results of the module. Point the output of the artifact to a convenient place. Run the configuration and view the landing page, follow instructions on that page to continue.
304303

305-
## Class diagram
306-
307-
![alt text](./etc/composite_view.png)
308-
309-
The class diagram here displays the Javabean which is the view manager. The views are JSP's held inside the web directory.
310-
311304
## Applicability:
312305

313306
Use the Composite View design pattern when:
@@ -316,6 +309,10 @@ Use the Composite View design pattern when:
316309
* You expect that the composite structures might include any new components in the future.
317310
* You want clients to be able to ignore the difference between compositions of objects and individual objects. Clients will treat all objects in the composite structure uniformly.
318311

312+
## Tutorials
313+
314+
* [Composite View Design Pattern – Core J2EE Patterns (Dinesh on Java)](https://www.dineshonjava.com/composite-view-design-pattern/)
315+
319316
## Known Uses
320317

321318
* Graphical User Interfaces (GUIs) where widgets can contain other widgets (e.g., a window containing panels, buttons, and text fields).
@@ -335,15 +332,13 @@ Trade-offs:
335332

336333
## Related Patterns
337334

338-
* [Decorator](https://java-design-patterns.com/patterns/decorator/): While Decorator is used to add responsibilities to objects, Composite is meant for building structures of objects.
339-
* [Flyweight](https://java-design-patterns.com/patterns/flyweight/): Composite can often be combined with Flyweight to implement shared leaf nodes in a composite structure, reducing the memory footprint.
340-
* [Chain of Responsibility](https://java-design-patterns.com/patterns/chain-of-responsibility/): Can be used with Composite to let components pass requests through the hierarchy.
341-
* [Composite](https://java-design-patterns.com/patterns/composite/)
342-
* [View Helper](https://www.oracle.com/java/technologies/viewhelper.html)
335+
* [Composite](https://java-design-patterns.com/patterns/composite/): General structural pattern that is the foundation for Composite View, used for treating individual objects and compositions uniformly.
336+
* [Decorator](https://java-design-patterns.com/patterns/decorator/): Enhances the behavior of individual views without modifying the underlying view.
337+
* [Flyweight](https://java-design-patterns.com/patterns/flyweight/): Can be used to manage memory consumption of large numbers of similar view objects.
338+
* View Helper: Separates the view logic from business logic, aiding in the clean organization and management of view components.
343339

344340
## Credits
345341

346-
* [Core J2EE Patterns - Composite View](https://www.oracle.com/java/technologies/composite-view.html)
347-
* [Composite View Design Pattern – Core J2EE Patterns](https://www.dineshonjava.com/composite-view-design-pattern/)
348-
* [Patterns of Enterprise Application Architecture](https://amzn.to/49jpQG3)
349342
* [Head First Design Patterns: Building Extensible and Maintainable Object-Oriented Software](https://amzn.to/3xfntGJ)
343+
* [Patterns of Enterprise Application Architecture](https://amzn.to/49jpQG3)
344+
* [Core J2EE Patterns - Composite View (Oracle)](https://www.oracle.com/java/technologies/composite-view.html)

composite-view/etc/images/noparam.png

-70.8 KB
Binary file not shown.
-76.8 KB
Binary file not shown.

0 commit comments

Comments
 (0)