mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-08-11 16:25:36 +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,25 +1,27 @@
|
||||
---
|
||||
title: Model-View-Presenter
|
||||
title: "Model-View-Presenter Pattern in Java: Enhancing UI Logic Separation for Cleaner Code"
|
||||
shortTitle: Model-View-Presenter (MVP)
|
||||
description: "Discover the Model-View-Presenter (MVP) pattern in Java. Learn how it separates user interface, business logic, and data interaction to enhance testability and maintainability."
|
||||
category: Architectural
|
||||
language: en
|
||||
tag:
|
||||
- Architecture
|
||||
- Client-server
|
||||
- Decoupling
|
||||
- Enterprise patterns
|
||||
- Interface
|
||||
- Presentation
|
||||
- Architecture
|
||||
- Client-server
|
||||
- Decoupling
|
||||
- Enterprise patterns
|
||||
- Interface
|
||||
- Presentation
|
||||
---
|
||||
|
||||
## Also known as
|
||||
|
||||
* MVP
|
||||
|
||||
## Intent
|
||||
## Intent of Model-View-Presenter Design Pattern
|
||||
|
||||
MVP aims to separate the user interface (UI) logic from the business logic and model in a software application, enabling easier testing and maintenance.
|
||||
|
||||
## Explanation
|
||||
## Detailed Explanation of Model-View-Presenter Pattern with Real-World Examples
|
||||
|
||||
Real-world example
|
||||
|
||||
@@ -35,13 +37,13 @@ Real-world example
|
||||
|
||||
In plain words
|
||||
|
||||
> The Model-View-Presenter (MVP) pattern separates the user interface, business logic, and data interaction in an application, with the presenter mediating between the view and the model to facilitate clear communication and updates.
|
||||
> The Model-View-Presenter (MVP) pattern separates the user interface, business logic, and data interaction in an application, with the presenter mediating between the view and the model to facilitate clear communication and updates. Java developers use MVP to improve application structure.
|
||||
|
||||
Wikipedia says
|
||||
|
||||
> Model–view–presenter (MVP) is a derivation of the model–view–controller (MVC) architectural pattern, and is used mostly for building user interfaces. In MVP, the presenter assumes the functionality of the "middle-man". In MVP, all presentation logic is pushed to the presenter.
|
||||
|
||||
**Programmatic example**
|
||||
## Programmatic Example of Model-View-Presenter Pattern in Java
|
||||
|
||||
The Model-View-Presenter (MVP) design pattern is a derivative of the well-known Model-View-Controller (MVC) pattern. It aims to separate the application's logic (Model), GUIs (View), and the way that the user's actions update the application's logic (Presenter). This separation of concerns makes the application easier to manage, extend, and test.
|
||||
|
||||
@@ -133,16 +135,16 @@ public class App {
|
||||
|
||||
In this setup, the `App` class creates instances of the Model, View, and Presenter. It then connects these instances, forming the MVP triad. The Presenter is given a reference to the View, and the Model is set on the Presenter. Finally, the Presenter is started, which in turn opens the View.
|
||||
|
||||
## Applicability
|
||||
## When to Use the Model-View-Presenter Pattern in Java
|
||||
|
||||
Use MVP in applications where a clear [separation of concerns](https://java-design-patterns.com/principles/#separation-of-concerns) is needed between the presentation layer and the underlying business logic. It's particularly useful in client-server applications and enterprise-level applications.
|
||||
|
||||
## Known Uses
|
||||
## Real-World Applications of Model-View-Presenter Pattern in Java
|
||||
|
||||
* Desktop applications like those built using Java Swing or JavaFX.
|
||||
* Web applications with complex user interfaces and business logic.
|
||||
|
||||
## Consequences
|
||||
## Benefits and Trade-offs of Model-View-Presenter Pattern
|
||||
|
||||
Benefits:
|
||||
|
||||
@@ -155,12 +157,12 @@ Trade-offs:
|
||||
* Increases complexity with more classes and interfaces.
|
||||
* Requires careful design to avoid over-coupling between the presenter and the view.
|
||||
|
||||
## Related Patterns
|
||||
## Related Java Design Patterns
|
||||
|
||||
* [Model-View-Controller (MVC)](https://java-design-patterns.com/patterns/model-view-controller/): MVP is often considered a variant of MVC where the presenter takes over the controller's role in managing user input and updating the model.
|
||||
* [Model-View-ViewModel (MVVM)](https://java-design-patterns.com/patterns/model-view-viewmodel/): Similar to MVP but adapted for frameworks like WPF or frameworks that support data binding, making the view update automatically when the model changes.
|
||||
|
||||
## Credits
|
||||
## References and Credits
|
||||
|
||||
* [Patterns of Enterprise Application Architecture](https://amzn.to/3WfKBPR)
|
||||
* [Pro JavaFX 8: A Definitive Guide to Building Desktop, Mobile, and Embedded Java Clients](https://amzn.to/4a8qcQ1)
|
||||
|
||||
Reference in New Issue
Block a user