jeudi 2 septembre 2021

How to design an interface for searching clients with different data scenarios?

I need to be able to get clients from a bank system, but the types of clients that can be searched is actually unknown or could vary with time: active client, blocked client, random client.

I want to design an interface so I can later implement those search methods on an actual DB or on Java Enums, etc.

Should the interface have a method for each type of client? It doesn't sound right. Everytime a new type shows up, I'll have to change everything.

Should the interface have only one type of method?

Client getClient(ClientType type);
Client getOneClient(ClientType type);
List<Client> getManyClients(ClientType type);

If that's the case, how do you avoid an if / switch statement inside the method?

But also, a client can have another entities inside them: the card, the accounts, etc. And those sub entities could also have different states: active card, blocked card, account with money, account without money, etc, etc.

I've tried the Builder Pattern, I notice this is very similar to the way a QueryBuilder works, I've also investigated about the Decorator Pattern but I can't figure out the solution yet.

Why do I need this? Because I made a transaction message generator in Java, but the program needs client data for each message, and I need many types of data (clients, accounts, cards) to cover many test cases, and to avoid manually searching that data.

Aucun commentaire:

Enregistrer un commentaire