mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-08-18 00:23:32 +00:00
docs: Content SEO updates (#2990)
* update yaml frontmatter format * update abstract document * update abstract factory * use the new pattern template * acyclic visitor seo * adapter seo * ambassador seo * acl seo * aaa seo * async method invocation seo * balking seo * bridge seo * builder seo * business delegate and bytecode seo * caching seo * callback seo * chain seo * update headings * circuit breaker seo * client session + collecting parameter seo * collection pipeline seo * combinator SEO * command seo * cqrs seo * commander seo * component seo * composite seo * composite entity seo * composite view seo * context object seo * converter seo * crtp seo * currying seo * dao seo * data bus seo * data locality seo * data mapper seo * dto seo * decorator seo * delegation seo * di seo * dirty flag seo * domain model seo * double buffer seo * double checked locking seo * double dispatch seo * dynamic proxy seo * event aggregator seo * event-based asynchronous seo * eda seo * event queue seo * event sourcing seo * execute around seo * extension objects seo * facade seo * factory seo * factory kit seo * factory method seo * fanout/fanin seo * feature toggle seo * filterer seo * fluent interface seo * flux seo * flyweight seo * front controller seo * function composition seo * game loop seo * gateway seo * guarded suspension seo * half-sync/half-async seo * health check seo * hexagonal seo * identity map seo * intercepting filter seo * interpreter seo * iterator seo * layers seo * lazy loading seo * leader election seo * leader/followers seo * lockable object seo * rename and add seo for marker interface * master-worker seo * mediator seo * memento seo * metadata mapping seo * microservice aggregator seo * api gw seo * microservices log aggregration seo * mvc seo * mvi seo * mvp seo * mvvm seo * monad seo * monitor seo * monostate seo * multiton seo * mute idiom seo * naked objects & notification seo * null object seo * object mother seo * object pool seo * observer seo * optimistic locking seo * page controller seo * page object seo * parameter object seo * partial response seo * pipeline seo * poison pill seo * presentation model seo * private class data seo * producer-consumer seo * promise seo * property seo * prototype seo * proxy seo * queue-based load leveling seo * reactor seo * registry seo * repository seo * RAII seo * retry seo * role object seo * saga seo * separated interface seo * serialized entity seo * serialized lob seo * servant seo * server session seo * service layer seo * service locator seo * service to worker seo * sharding seo * single table inheritance seo * singleton seo * spatial partition seo * special case seo * specification seo * state seo * step builder seo * strangler seo * strategy seo * subclass sandbox seo * table module seo * template method seo * throttling seo * tolerant reader seo * trampoline seo * transaction script seo * twin seo * type object seo * unit of work seo * update method seo * value object seo * version number seo * virtual proxy seo * visitor seo * seo enhancements * seo improvements * SEO enhancements * SEO improvements * SEO additions * SEO improvements * more SEO improvements * rename hexagonal + SEO improvements * SEO improvements * more SEO stuff * SEO improvements * SEO optimizations * SEO enhancements * enchance SEO * improve SEO * SEO improvements * update headers
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
---
|
||||
title: Collecting Parameter
|
||||
title: "Collecting Parameter Pattern in Java: Mastering Efficient Parameter Handling"
|
||||
shortTitle: Collecting Parameter
|
||||
description: "Discover how the Collecting Parameter design pattern simplifies Java method calls by aggregating multiple parameters into a single collection object. Enhance code readability and maintainability with practical examples and real-world applications."
|
||||
category: Behavioral
|
||||
language: en
|
||||
tag:
|
||||
- Accumulation
|
||||
- Data processing
|
||||
- Data transfer
|
||||
- Generic
|
||||
- Accumulation
|
||||
- Data processing
|
||||
- Data transfer
|
||||
- Generic
|
||||
---
|
||||
|
||||
## Also known as
|
||||
@@ -14,14 +16,16 @@ tag:
|
||||
* Collector
|
||||
* Accumulator
|
||||
|
||||
## Intent
|
||||
## Intent of Collecting Parameter Design Pattern
|
||||
|
||||
Aims to simplify methods that collect information by passing a single collection object through various method calls, allowing them to add results to this collection rather than each method creating its own collection.
|
||||
The Collecting Parameter pattern in Java design patterns aims to simplify method calls by aggregating multiple parameters into a single collection object. This pattern is particularly effective for methods that collect information by passing a single collection object through various method calls. Each method can then add results to this collection, instead of creating its own collection. This approach enhances code readability and maintainability, optimizing the process of information collection in Java programming.
|
||||
|
||||
## Explanation
|
||||
## Detailed Explanation of Collecting Parameter Pattern with Real-World Examples
|
||||
|
||||
Real-world example
|
||||
|
||||
> In software development, the Collecting Parameter pattern provides significant benefits by optimizing method calls and improving code maintainability.
|
||||
>
|
||||
> Imagine a scenario in a restaurant where a waiter needs to take an order from a customer. Instead of noting down each item separately (e.g., appetizer, main course, dessert, drink), the waiter uses an order form that collects all the items into a single document. This order form simplifies the communication between the waiter and the kitchen staff by aggregating all the details into one place. Similarly, in software, the Collecting Parameter pattern aggregates multiple parameters into a single object, streamlining method calls and improving code readability and maintainability.
|
||||
|
||||
In plain words
|
||||
@@ -32,7 +36,7 @@ Wikipedia says
|
||||
|
||||
> In the Collecting Parameter idiom a collection (list, map, etc.) is passed repeatedly as a parameter to a method which adds items to the collection.
|
||||
|
||||
**Programmatic Example**
|
||||
## Programmatic Example of Collecting Parameter Pattern in Java
|
||||
|
||||
Within a large corporate building, there exists a global printer queue that is a collection of all the printing jobs that are currently pending. Various floors contain different models of printers, each having a different printing policy. We must construct a program that can continually add appropriate printing jobs to a collection, which is called the collecting parameter.
|
||||
|
||||
@@ -106,24 +110,28 @@ This `App` class is the main entry point of the application. It uses the Collect
|
||||
|
||||
The `result` list, which is the collecting parameter, accumulates the valid print jobs as it is passed from method to method. This is the essence of the Collecting Parameter design pattern.
|
||||
|
||||
## Applicability
|
||||
Utilizing the Collecting Parameter pattern in Java design patterns leads to more efficient method calls and improved overall code structure.
|
||||
|
||||
## When to Use the Collecting Parameter Pattern in Java
|
||||
|
||||
This pattern is useful for managing parameters in Java coding practices, ensuring efficient code refactoring and enhanced readability.
|
||||
|
||||
* Use when a method needs to accept a large number of parameters, making the method signature unwieldy.
|
||||
* Use when the same group of parameters is passed to multiple methods, reducing redundancy and potential errors.
|
||||
* Use to improve the readability and maintainability of the code.
|
||||
|
||||
## Tutorials
|
||||
## Collecting Parameter Pattern Java Tutorials
|
||||
|
||||
* [Refactoring To Patterns (Joshua Kerivsky)](http://www.tarrani.net/RefactoringToPatterns.pdf)
|
||||
* [Smalltalk Best Practice Patterns (Kent Beck)](https://ptgmedia.pearsoncmg.com/images/9780134769042/samplepages/013476904X.pdf)
|
||||
|
||||
## Known uses
|
||||
## Real-World Applications of Collecting Parameter Pattern in Java
|
||||
|
||||
* Use when a method needs to accept a large number of parameters, making the method signature unwieldy.
|
||||
* Use when the same group of parameters is passed to multiple methods, reducing redundancy and potential errors.
|
||||
* Use to improve the readability and maintainability of the code.
|
||||
|
||||
## Consequences
|
||||
## Benefits and Trade-offs of Collecting Parameter Pattern
|
||||
|
||||
Benefits:
|
||||
|
||||
@@ -136,13 +144,13 @@ Trade-offs:
|
||||
* Introduces an additional class, which may increase complexity if not managed properly.
|
||||
* Can lead to over-generalization if the parameter object becomes too large or unwieldy.
|
||||
|
||||
## Related patterns
|
||||
## Related Java Design Patterns
|
||||
|
||||
* [Command](https://java-design-patterns.com/patterns/command/): Commands may utilize Collecting Parameter to aggregate results from multiple operations executed by the command objects.
|
||||
* [Composite](https://java-design-patterns.com/patterns/composite/): Can be used in tandem with Collecting Parameter when dealing with hierarchical structures, allowing results to be collected across a composite structure.
|
||||
* [Visitor](https://java-design-patterns.com/patterns/visitor/): Often used together, where Visitor handles traversal and operations on a structure, and Collecting Parameter accumulates the results.
|
||||
|
||||
## Credits
|
||||
## References and Credits
|
||||
|
||||
* [Clean Code: A Handbook of Agile Software Craftsmanship](https://amzn.to/4aApLP0)
|
||||
* [Refactoring: Improving the Design of Existing Code](https://amzn.to/3TVEgaB)
|
||||
|
||||
Reference in New Issue
Block a user