mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-10-13 18:15:41 +00:00
docs: collecting parameter docs + formatting
This commit is contained in:
1 parent
ea7bc2a4eb
commit
f80cc468b2
23 files changed
+1191
-794
No files matched your search
+26
-13
@@ -3,12 +3,14 @@ title: Business Delegate
|
||||
category: Structural
|
||||
language: en
|
||||
tag:
|
||||
- Decoupling
|
||||
- Decoupling
|
||||
---
|
||||
|
||||
## Intent
|
||||
|
||||
The Business Delegate pattern adds an abstraction layer between presentation and business tiers. By using the pattern we gain loose coupling between the tiers and encapsulate knowledge about how to locate, connect to, and interact with the business objects that make up the application.
|
||||
The Business Delegate pattern adds an abstraction layer between presentation and business tiers. By using the pattern we
|
||||
gain loose coupling between the tiers and encapsulate knowledge about how to locate, connect to, and interact with the
|
||||
business objects that make up the application.
|
||||
|
||||
## Also known as
|
||||
|
||||
@@ -18,7 +20,9 @@ Service Representative
|
||||
|
||||
Real world example
|
||||
|
||||
> A mobile phone application promises to stream any movie in existence to your device. It captures the user's search string and passes this on to the Business Delegate. The Business Delegate selects the most suitable video streaming service and plays the video from there.
|
||||
> A mobile phone application promises to stream any movie in existence to your device. It captures the user's search
|
||||
> string and passes this on to the Business Delegate. The Business Delegate selects the most suitable video streaming
|
||||
> service and plays the video from there.
|
||||
|
||||
In Plain Words
|
||||
|
||||
@@ -26,7 +30,10 @@ In Plain Words
|
||||
|
||||
Wikipedia says
|
||||
|
||||
> Business Delegate is a Java EE design pattern. This pattern is directing to reduce the coupling in between business services and the connected presentation tier, and to hide the implementation details of services (including lookup and accessibility of EJB architecture). Business Delegates acts as an adaptor to invoke business objects from the presentation tier.
|
||||
> Business Delegate is a Java EE design pattern. This pattern is directing to reduce the coupling in between business
|
||||
> services and the connected presentation tier, and to hide the implementation details of services (including lookup and
|
||||
> accessibility of EJB architecture). Business Delegates acts as an adaptor to invoke business objects from the
|
||||
> presentation tier.
|
||||
|
||||
**Programmatic Example**
|
||||
|
||||
@@ -57,6 +64,7 @@ public class YouTubeService implements VideoStreamingService {
|
||||
Then, we have a lookup service that decides which video streaming service to use.
|
||||
|
||||
```java
|
||||
|
||||
@Setter
|
||||
public class BusinessLookup {
|
||||
|
||||
@@ -77,6 +85,7 @@ The Business Delegate uses a business lookup to route movie playback requests to
|
||||
video streaming service.
|
||||
|
||||
```java
|
||||
|
||||
@Setter
|
||||
public class BusinessDelegate {
|
||||
|
||||
@@ -109,20 +118,20 @@ public class MobileClient {
|
||||
Finally, we can demonstrate the complete example in action.
|
||||
|
||||
```java
|
||||
public static void main(String[] args) {
|
||||
public static void main(String[]args){
|
||||
|
||||
// prepare the objects
|
||||
var businessDelegate = new BusinessDelegate();
|
||||
var businessLookup = new BusinessLookup();
|
||||
var businessDelegate=new BusinessDelegate();
|
||||
var businessLookup=new BusinessLookup();
|
||||
businessLookup.setNetflixService(new NetflixService());
|
||||
businessLookup.setYouTubeService(new YouTubeService());
|
||||
businessDelegate.setLookupService(businessLookup);
|
||||
|
||||
// create the client and use the Business Delegate
|
||||
var client = new MobileClient(businessDelegate);
|
||||
var client=new MobileClient(businessDelegate);
|
||||
client.playbackMovie("Die Hard 2");
|
||||
client.playbackMovie("Maradona: The Greatest Ever");
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Here is the console output.
|
||||
@@ -164,7 +173,8 @@ Benefits:
|
||||
|
||||
* Decoupling of Presentation and Business Tiers: Allows the client tier and business services to evolve independently.
|
||||
* Location Transparency: Clients remain unaffected by changes in the location or the instantiation of business services.
|
||||
* Reuse and Scalability: Business Delegate objects can be reused by multiple clients, and the pattern supports load balancing and scalability.
|
||||
* Reuse and Scalability: Business Delegate objects can be reused by multiple clients, and the pattern supports load
|
||||
balancing and scalability.
|
||||
|
||||
Trade-offs:
|
||||
|
||||
@@ -173,9 +183,12 @@ Trade-offs:
|
||||
|
||||
## Related patterns
|
||||
|
||||
* [Service Locator](https://java-design-patterns.com/patterns/service-locator/): Business Delegate uses Service Locator to locate business services.
|
||||
* [Session Facade](https://java-design-patterns.com/patterns/session-facade/): Business Delegate may use Session Facade to provide a unified interface to a set of business services.
|
||||
* [Composite Entity](https://java-design-patterns.com/patterns/composite-entity/): Business Delegate may use Composite Entity to manage the state of business services.
|
||||
* [Service Locator](https://java-design-patterns.com/patterns/service-locator/): Business Delegate uses Service Locator
|
||||
to locate business services.
|
||||
* [Session Facade](https://java-design-patterns.com/patterns/session-facade/): Business Delegate may use Session Facade
|
||||
to provide a unified interface to a set of business services.
|
||||
* [Composite Entity](https://java-design-patterns.com/patterns/composite-entity/): Business Delegate may use Composite
|
||||
Entity to manage the state of business services.
|
||||
|
||||
## Credits
|
||||
|
||||
|
||||
Reference in new issue
Block a user