Ensuring only dependent products can be added to the cart

We have multiple products but need to make sure that only certain combinations are permitted.

For example:
product a; product b; product c; product d

Product a is only allowed to be added to the cart if the cart already has product b or product c in the cart.