It's maybe an old horse to beat (not dead yet?), but I'm wondering if OCL allows modeling the problem of the business rules for building houses and hotels in the game of Monopoly within a domain model (conceptual class diagram, separate from an implementation).
I've supplied the rules after my naive attempt, but I'm not sure how to go about capturing the ordering aspects in OCL. That is, one must own all properties of a colour-group, then build the houses on those properties "evenly" (see below), then replace the 4 houses on a property with a hotel, etc. There is also the case of a "housing shortage" because there are only a total of 32 houses and 8 hotels in the game. I realize this question is ambitious, but I'm trying to see if it's possible in OCL and to have some pointers of where to go.
So far, I've managed to specify the fact that a property can't have houses and hotels at the same time with the {xor}
option between two associations.
Model done with PlantUML/PlantText.
Here are the rules concerning Houses and Hotels, cited from a fan site.
HOUSES
When a player owns all the properties in a colour-group they may buy houses from the Bank and erect them on those properties.
If you buy one house, you may put it on any one of those properties. The next house you buy must be erected on one of the unimproved properties of this or any other complete colour-group you may own.
The price you must pay the Bank for each house is shown on your Title Deed card for the property on which you erect the house. The owner still collects double rent from an opponent who lands on the unimproved properties of there complete colour-group.
Following the above rules, you may buy and erect at any time as many houses as your judgement and financial standing will allow. But you must build evenly, i.e., you cannot erect more than one house on any one property of any colour-group until you have built one house on every property of that group. You may then begin on the second row of houses, and so on, up to a limit of four houses to a property. For example, you cannot build three Houses on one property if you have only one house on another property of that group.
As you build evenly, you must also break down evenly if you sell houses back to the Bank (see SELLING PROPERTY).
HOTELS
When a player has four houses on each property of a complete colour-group, they may buy a hotel from the Bank and erect it on any property of the colour-group. They return the four houses from that property to the Bank and pay the price for the hotel as shown on the Title Deed card. Only one hotel may be erected on any one property.
N.B. This is not a homework, although it would make a great one maybe for a graduate class?