Enum work like a class

Here is a code snippet from "Growing Object-Oriented Software Guided by Test", which really impressed me by the way enum is used. Very cool.

public enum SniperState {
    JOINING {
        @Override
        public SniperState whenAuctionClosed() {
            return LOST;
        }
    },
    BIDDING {
        @Override
        public SniperState whenAuctionClosed() {
            return LOST;
        }
    },
    WINNING {
        @Override
        public SniperState whenAuctionClosed() {
            return WON;
        }
    },
    LOST, WON;
    public SniperState whenAuctionClosed() {
        throw new RuntimeException("Oops");
    }
}

By the way, if you know where I can buy the paper book of "Growing Object-Oriented Software Guided by Test", please let me know:)

Advertisements