cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

CAP Factory/Facade Pattern with Remote and Local Entities

DavidBrodmann
Explorer
0 Likes
593

Dear all

I was wondering if there is a good/certain way to implement some kind of factory or facade pattern with CDS to combine two entities from different remote services, into the current application.

Here is a brief example that I was thinking of. The goal would be to use as many tools from the CAP framework itself so I have to implement as few things as possible.

 ┌──────────────┐                                             
 │FactoryOrders ┼──────────────┐                              
 └──────────────┘          ┌───▼───┐                          
                           │Orders ├─────►use entity <Orders> 
 ┌──────────────┐          └───▲───┘      in OrdersService    
 │LogisticOrders┼──────────────┘                              
 └──────────────┘                                             
                                                              

Of Course FactoryOrders and LogisticOrders have the same keywords with the same types etc. But FactoryOrders is from one remote service and LogisticOrders are from another remote service.

At the moment, what I am doing is I have an entity Order, that is getting the keywords and types from one of the remote entities:

entity Orders {
orderNumber : FactoryOrders:orderNumber;
orderType : FactoryOrders:orderType;
orderData: FactoryOrders:orderDate;
}

Then in the on.READ event handler of entitity <Orders> I read the orders from both remote services and return the combined orders.

This solution does not feel completely right though and I am curious if there are better/different solutions.

I hope I explained the problem in an understandable manner, have a blast.

cheers

David

Accepted Solutions (0)

Answers (1)

Answers (1)

martinstenzig
Contributor

I would say model the two pieces as aspects. https://cap.cloud.sap/docs/cds/aspects#separate-reuse-aspects

 

DavidBrodmann
Explorer

Dear Martin, thank you very much for the reply and indeed this sounds like a smart solution. I will definitely try this out and update the solution.

It really feels like a very obvious solution, but somehow I did not think about using aspects like this 😄