Dismissal of an unjust enrichment claim by the Superior Court is reversed. A cause of action for quantum meruit, also known as unjust enrichment, will ordinarily lie where the defendant receives something of value to which he is not entitled and which he should restore to the plaintiff. It is an equitable quasi-contract cause of action, imposing liability where there is no enforceable contract between the parties but fairness dictates that the plaintiff receive compensation for services provided. Because this is an equitable remedy, like all equitable remedies it is inappropriate where a legal remedy is available. Thus the general rule is that no equitable quasi-contractual claim can arise when a contract exists between the parties concerning the same subject matter, since legal remedies are available to a plaintiff in a breach of contract action. In this case, there is a contract covering the same subject matter, but not between the parties to the suit. Applying the barred by contract doctrine would not serve the objective of holding the parties to the terms of their contractual agreements, and would make little sense given the rule's purpose and the function of an equitable claim for unjust enrichment to imply a contract in order to prevent injustice when one party inequitably receives and retains a benefit from another. Therefore, the Superior Court erred in holding that the unjust enrichment claim was barred by the plaintiff's contract with another entity to which the defendants were not parties, because the barred by contract rule does not apply when the opposing parties have not entered an express contract. The doctrine of res judicata, addressed on this appeal in this appeal in the interests of judicial economy since this issue will likely recur on remand, is also no bar to the plaintiff's suit. While it is true that involuntary dismissal generally acts as a judgment on the merits, res judicata requires that (1) the prior judgment was valid, final, and on the merits; (2) the parties in the subsequent action are identical to or in privity with the parties in the prior action; and (3) the claims in the subsequent action arise out of the same transaction or occurrence as the prior claims. Here the defendants are not identical to the entity that was the defendant in the previous suit, nor have has it been asserted that the present defendants are in privity with that other party. Thus dismissal of plaintiff's prior suit against the other entity does not preclude its unjust enrichment claim against the present defendants. Therefore, the Superior Court erred in dismissing this complaint. The July 17, 2013 order is reversed, and the case is remanded for further proceedings.