/**
 * Copyright (C) 2022 by Martin Robillard. See https://codesample.info/about.html
 */
package e2.chapter9;

import java.util.function.Consumer;

/**
 * Sample observable object where the Observer design pattern is applied using
 * functional-style design.
 * 
 * See Section 9.5.
 */
public class ObservableDeck extends Deck {
	private Consumer<Card> aDrawHandler;

	public ObservableDeck(Consumer<Card> pDrawHandler) {
		aDrawHandler = pDrawHandler;
	}

	@Override
	public Card draw() {
		Card card = super.draw();
		aDrawHandler.accept(card);
		return card;
	}
}