mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-10-13 16:14:58 +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 parent
cb946c0cdc
commit
6cd2d0353a
219 files changed
+3308
-2819
No files matched your search
+22
-20
@@ -1,28 +1,30 @@
|
||||
---
|
||||
title: Abstract Factory
|
||||
title: "Abstract Factory Pattern in Java: Mastering Object Creation Elegantly"
|
||||
shortTitle: Abstract Factory
|
||||
description: "Learn the Abstract Factory pattern in Java with real-world examples, class diagrams, and tutorials. Understand its intent, applicability, benefits, and known uses to enhance your design pattern knowledge."
|
||||
category: Creational
|
||||
language: en
|
||||
tag:
|
||||
- Abstraction
|
||||
- Decoupling
|
||||
- Gang of Four
|
||||
- Instantiation
|
||||
- Polymorphism
|
||||
- Abstraction
|
||||
- Decoupling
|
||||
- Gang of Four
|
||||
- Instantiation
|
||||
- Polymorphism
|
||||
---
|
||||
|
||||
## Also known as
|
||||
|
||||
* Kit
|
||||
|
||||
## Intent
|
||||
## Intent of Abstract Factory Design Pattern
|
||||
|
||||
Provide an interface for creating families of related or dependent objects without specifying their concrete classes.
|
||||
The Abstract Factory pattern in Java provides an interface for creating families of related or dependent objects without specifying their concrete classes, enhancing modularity and flexibility in software design.
|
||||
|
||||
## Explanation
|
||||
## Detailed Explanation of Abstract Factory Pattern with Real-World Examples
|
||||
|
||||
Real-world example
|
||||
|
||||
> Imagine a furniture company that produces various styles of furniture: modern, Victorian, and rustic. Each style includes products like chairs, tables, and sofas. To ensure consistency within each style, the company uses an Abstract Factory pattern.
|
||||
> Imagine a furniture company that uses the Abstract Factory pattern in Java to produce various styles of furniture: modern, Victorian, and rustic. Each style includes products like chairs, tables, and sofas. To ensure consistency within each style, the company uses an Abstract Factory pattern.
|
||||
>
|
||||
> In this scenario, the Abstract Factory is an interface for creating families of related furniture objects (chairs, tables, sofas). Each concrete factory (ModernFurnitureFactory, VictorianFurnitureFactory, RusticFurnitureFactory) implements the Abstract Factory interface and creates a set of products that match the specific style. This way, clients can create a whole set of modern or Victorian furniture without worrying about the details of their instantiation. This maintains a consistent style and allows easy swapping of one style of furniture for another.
|
||||
|
||||
@@ -34,9 +36,9 @@ Wikipedia says
|
||||
|
||||
> The abstract factory pattern provides a way to encapsulate a group of individual factories that have a common theme without specifying their concrete classes
|
||||
|
||||
**Programmatic Example**
|
||||
## Programmatic Example of Abstract Factory in Java
|
||||
|
||||
To create a kingdom we need objects with a common theme. The elven kingdom needs an elven king, elven castle, and elven army whereas the orcish kingdom needs an orcish king, orcish castle, and orcish army. There is a dependency between the objects in the kingdom.
|
||||
To create a kingdom using the Abstract Factory pattern in Java, we need objects with a common theme. The elven kingdom needs an elven king, elven castle, and elven army whereas the orcish kingdom needs an orcish king, orcish castle, and orcish army. There is a dependency between the objects in the kingdom.
|
||||
|
||||
Translating the kingdom example above. First of all, we have some interfaces and implementation for the objects in the kingdom.
|
||||
|
||||
@@ -163,13 +165,13 @@ The program output:
|
||||
07:35:46.343 [main] INFO com.iluwatar.abstractfactory.App -- This is the orc king!
|
||||
```
|
||||
|
||||
## Class diagram
|
||||
## Abstract Factory Pattern Class Diagram
|
||||
|
||||

|
||||
|
||||
## Applicability
|
||||
## When to Use the Abstract Factory Pattern in Java
|
||||
|
||||
Use the Abstract Factory pattern when:
|
||||
Use the Abstract Factory pattern in Java when:
|
||||
|
||||
* The system should be independent of how its products are created, composed, and represented.
|
||||
* You need to configure the system with one of multiple families of products.
|
||||
@@ -180,12 +182,12 @@ Use the Abstract Factory pattern when:
|
||||
* You need to choose which product to use from a family at runtime.
|
||||
* Adding new products or families should not require changes to existing code.
|
||||
|
||||
## Tutorials
|
||||
## Abstract Factory Pattern Java Tutorials
|
||||
|
||||
* [Abstract Factory Design Pattern in Java (DigitalOcean)](https://www.digitalocean.com/community/tutorials/abstract-factory-design-pattern-in-java)
|
||||
* [Abstract Factory(Refactoring Guru)](https://refactoring.guru/design-patterns/abstract-factory)
|
||||
|
||||
## Consequences
|
||||
## Benefits and Trade-offs of Abstract Factory Pattern
|
||||
|
||||
Benefits:
|
||||
|
||||
@@ -203,7 +205,7 @@ Trade-offs:
|
||||
|
||||
* Indirectness: Client code interacts with products indirectly through factories, potentially reducing transparency.
|
||||
|
||||
## Known uses
|
||||
## Real-World Applications of Abstract Factory Pattern in Java
|
||||
|
||||
* Java Swing's `LookAndFeel` classes for providing different look-and-feel options.
|
||||
* Various implementations in the Java Abstract Window Toolkit (AWT) for creating different GUI components.
|
||||
@@ -211,13 +213,13 @@ Trade-offs:
|
||||
* [javax.xml.transform.TransformerFactory](http://docs.oracle.com/javase/8/docs/api/javax/xml/transform/TransformerFactory.html#newInstance--)
|
||||
* [javax.xml.xpath.XPathFactory](http://docs.oracle.com/javase/8/docs/api/javax/xml/xpath/XPathFactory.html#newInstance--)
|
||||
|
||||
## Related patterns
|
||||
## Related Java Design Patterns
|
||||
|
||||
* [Factory Method](https://java-design-patterns.com/patterns/factory-method/): Abstract Factory uses Factory Methods to create products.
|
||||
* [Singleton](https://java-design-patterns.com/patterns/singleton/): Abstract Factory classes are often implemented as Singletons.
|
||||
* [Factory Kit](https://java-design-patterns.com/patterns/factory-kit/): Similar to Abstract Factory but focuses on configuring and managing a set of related objects in a flexible way.
|
||||
|
||||
## Credits
|
||||
## References and Credits
|
||||
|
||||
* [Design Patterns: Elements of Reusable Object-Oriented Software](https://amzn.to/3w0pvKI)
|
||||
* [Design Patterns in Java](https://amzn.to/3Syw0vC)
|
||||
|
||||
Reference in new issue
Block a user