Voici dans ce qui suit de ce que pourrait être une implémentation très minimaliste du pattern Service Gateway.
public class CustomerPortfolioManager
{
public CustomerPortfolioManager()
{
}
public PortfolioTO retievePortfolio(final String idGRC)
{
ICustomerPortfolioGateway gateway = null;
PortfolioTO portfolio = null;
// allocation de l'implementation
gateway = new CustomerPortfolioGateway();
// chargement du portefolio du client
portfolio = gateway.retievePortfolio(idGRC);
// execution de traitements complémentaires
return portfolio;
}
}
Interface ICustomerPortfolioGateway
{
public PortfolioTO retievePortfolio(final String idGRC);
}
public class CustomerPortfolioGatewayImp implements ICustomerPortfolioGateway
{
public CustomerPortfolioGateway()
{
}
public PortfolioTO retievePortfolio(final String idGRC)
{
PortfolioTO portfolio = null;
PortfolioMapper mapper = new PortfolioMapper();
MessageGateway msgGateway = new MessageGateway();
portfolio = msgGateway.send(idGRC);
return mapper.map(portfolio);
}
}
public class PortfolioMapper
{
public PortfolioMapper()
{
}
public PortfolioTO map(Portfolio remoteData)
{
}
}
public class MessageGateway
{
public MessageGateway()
{
}
public Portfolio send(final String idGRC)
{
Document request = null;
Document respDoc = null;
String Object[] args = {idGRC};
request = buildRequest(args);
respDoc = doSend(resquest);
return parseResponseDocument(respDoc);
}
// construction de la requete
private Document buildRequest(Object[] args)
{
Document request = null;
// construire le message à envoyer
return request;
}
// envoi du message
private Document doSend(Document msg)
{
MessageSender sender = new MessageSender();
return sender.send(msg);
}
// parsing/extraction des données
p
rivate Portfolio parseResponseDocument(Document respDoc)
{
Portfolio remoteData = null;
// parsing
return remoteData;
}
}