Skip to content

Step 4: Classes

23 min · step 4 of 8

Introduction#

Turn the things on your term list into classes, and arrange them from general to specific.

A class is a kind of thing, like Drink or Ingredient. A class below another is its subclass: a Latte is a kind of MilkDrink. Everything you say about MilkDrink later also applies to every subclass. You can read the full guide to this step in Method.

What you’ll make#

31 classes in two trees: Drink at the top of one, Ingredient at the top of the other. Breve has two parents. You’ll also have three groups that can’t overlap and five design decisions.

Set the convention#

Pick how classes are named. The defaults are fine: PascalCase and singular. See the okb convention reference.

okb convention
Naming convention: classes PascalCase (singular) · slots camelCase · instances free text

Add the drinks#

Say each link out loud before you add it: “Every latte is a milk drink.” That’s an “is a” link. The top classes are abstract, because you never serve “a drink” without saying which. Then declare the three groups disjoint: a drink can’t be both pure espresso and a milk drink.

okb class add Drink --abstract --desc "Any coffee drink on the menu."
okb class add EspressoDrink --parent Drink --abstract --desc "A drink built on a shot of espresso."
okb class add PureEspresso --parent EspressoDrink --abstract --desc "An espresso drink with nothing but coffee and water."
okb class add MilkDrink --parent EspressoDrink --abstract --desc "An espresso drink with milk."
okb class add SweetenedDrink --parent EspressoDrink --abstract --desc "An espresso drink with chocolate, cream or gelato."
okb class disjoint PureEspresso MilkDrink SweetenedDrink
Added class Drink at the top level.

Added class EspressoDrink (a kind of Drink).

Added class PureEspresso (a kind of EspressoDrink).

Added class MilkDrink (a kind of EspressoDrink).
Can anything be both a MilkDrink and a PureEspresso? If not, say so: okb class disjoint "MilkDrink" "PureEspresso"

Added class SweetenedDrink (a kind of EspressoDrink).

Declared disjoint: PureEspresso, MilkDrink, SweetenedDrink. Nothing can be more than one of these now.

Now add the drinks themselves. Breve has two parents, because a breve is both a latte and a cappuccino made with half-and-half. That’s multiple inheritance. Read what okb says about it.

okb class add Espresso --parent PureEspresso --desc "A short, strong shot pulled through finely ground coffee."
okb class add Ristretto --parent PureEspresso --desc "A shorter, sweeter shot pulled with less water."
okb class add Lungo --parent PureEspresso --desc "A longer shot pulled with more water."
okb class add Americano --parent PureEspresso --desc "Espresso topped up with hot water."
okb class add LongBlack --parent PureEspresso --desc "Hot water with espresso poured on top."
okb class add Macchiato --parent MilkDrink --desc "Espresso marked with a spoonful of milk foam."
okb class add Cortado --parent MilkDrink --desc "Espresso cut with an equal amount of warm milk."
okb class add FlatWhite --parent MilkDrink --desc "Espresso with a thin layer of velvety milk."
okb class add Cappuccino --parent MilkDrink --desc "Espresso with steamed milk and a thick cap of foam."
okb class add Latte --parent MilkDrink --desc "Espresso with a lot of steamed milk and a little foam."
okb class add Breve --parent Latte --parent Cappuccino --desc "A latte or cappuccino made with half-and-half instead of milk."
okb class add Mocha --parent SweetenedDrink --desc "Espresso with chocolate and steamed milk."
okb class add ConPanna --parent SweetenedDrink --desc "Espresso topped with whipped cream."
okb class add Affogato --parent SweetenedDrink --desc "A scoop of gelato drowned in a shot of espresso."
okb class add CafeBombon --parent SweetenedDrink --desc "Espresso layered with condensed milk."
Added class Espresso (a kind of PureEspresso).

Added class Ristretto (a kind of PureEspresso).
Can anything be both a Ristretto and an Espresso? If not, say so: okb class disjoint "Ristretto" "Espresso"

Added class Lungo (a kind of PureEspresso).

Added class Americano (a kind of PureEspresso).

Added class LongBlack (a kind of PureEspresso).

Added class Macchiato (a kind of MilkDrink).

Added class Cortado (a kind of MilkDrink).
Can anything be both a Cortado and a Macchiato? If not, say so: okb class disjoint "Cortado" "Macchiato"

Added class FlatWhite (a kind of MilkDrink).

Added class Cappuccino (a kind of MilkDrink).

Added class Latte (a kind of MilkDrink).

Added class Breve (a kind of Latte and Cappuccino).
Multiple parents are fine when it's truly a kind of each. Consider recording why with `okb decision add`.

Added class Mocha (a kind of SweetenedDrink).

Added class ConPanna (a kind of SweetenedDrink).
Can anything be both a ConPanna and a Mocha? If not, say so: okb class disjoint "ConPanna" "Mocha"

Added class Affogato (a kind of SweetenedDrink).

Added class CafeBombon (a kind of SweetenedDrink).

Add ingredients#

Ingredients get their own tree. Milk is abstract: a café pours a kind of milk, never just “milk”.

okb class add Ingredient --abstract --desc "Something that goes into a drink."
okb class add Coffee --parent Ingredient --desc "Ground coffee, pulled as espresso."
okb class add Water --parent Ingredient --desc "Hot water."
okb class add Milk --parent Ingredient --abstract --desc "Any milk or cream added to a drink."
okb class add WholeMilk --parent Milk --desc "Whole cow's milk."
okb class add HalfAndHalf --parent Milk --desc "Equal parts milk and cream."
okb class add CondensedMilk --parent Milk --desc "Sweetened, thickened milk."
okb class add Foam --parent Ingredient --desc "Milk aerated with steam."
okb class add Chocolate --parent Ingredient --desc "Chocolate syrup or powder."
okb class add WhippedCream --parent Ingredient --desc "Cream whipped until light."
okb class add Gelato --parent Ingredient --desc "Italian ice cream."
okb class disjoint Coffee Water Milk Foam Chocolate WhippedCream Gelato
okb tree
Added class Ingredient at the top level.

Added class Coffee (a kind of Ingredient).

Added class Water (a kind of Ingredient).
Can anything be both a Water and a Coffee? If not, say so: okb class disjoint "Water" "Coffee"

Added class Milk (a kind of Ingredient).

Added class WholeMilk (a kind of Milk).

Added class HalfAndHalf (a kind of Milk).
Can anything be both a HalfAndHalf and a WholeMilk? If not, say so: okb class disjoint "HalfAndHalf" "WholeMilk"

Added class CondensedMilk (a kind of Milk).

Added class Foam (a kind of Ingredient).

Added class Chocolate (a kind of Ingredient).

Added class WhippedCream (a kind of Ingredient).

Added class Gelato (a kind of Ingredient).

Declared disjoint: Coffee, Water, Milk, Foam, Chocolate, WhippedCream, Gelato. Nothing can be more than one of these now.

Drink (abstract)
  └ EspressoDrink (abstract)
    └ MilkDrink (abstract)
      └ Cappuccino
        └ Breve (also under Latte)
      └ Cortado
      └ FlatWhite
      └ Latte
        └ Breve (see above)
      └ Macchiato
    └ PureEspresso (abstract)
      └ Americano
      └ Espresso
      └ LongBlack
      └ Lungo
      └ Ristretto
    └ SweetenedDrink (abstract)
      └ Affogato
      └ CafeBombon
      └ ConPanna
      └ Mocha
Ingredient (abstract)
  └ Chocolate
  └ Coffee
  └ Foam
  └ Gelato
  └ Milk (abstract)
    └ CondensedMilk
    └ HalfAndHalf
    └ WholeMilk
  └ Water
  └ WhippedCream

Settle the names#

okb warns when sibling names don’t follow a pattern: MilkDrink and SweetenedDrink end in “Drink”, but PureEspresso doesn’t. Here the menu names win. Record that as a decision, so the warning is explained instead of ignored:

okb decision add --title "Drinks keep their own names" --decision "Espresso, Ristretto, Lungo and the other drinks keep the names a menu uses." --why "Baristas say Lungo, not LungoEspresso. The parent names group them, so the children don't repeat a word." --about EspressoDrink --waives naming-subclass-names-consistent
okb decision add --title "Menu names for pure espressos" --decision "The pure espresso drinks keep their menu names." --why "Nobody orders a LongBlackEspresso." --about PureEspresso --waives naming-subclass-names-consistent
okb decision add --title "Milk names stay natural" --decision "HalfAndHalf keeps its everyday name." --why "That's what the carton says." --about Milk --waives naming-subclass-names-consistent
Recorded design decision d.2: Drinks keep their own names.
It explains 2 current finding(s) from naming-subclass-names-consistent (they'll show as 'explained' in okb validate).

Recorded design decision d.3: Menu names for pure espressos.
Note: it doesn't match any current finding from naming-subclass-names-consistent. Check the --about target (a decision about a class also covers its subclasses).

Recorded design decision d.4: Milk names stay natural.
It explains 1 current finding(s) from naming-subclass-names-consistent (they'll show as 'explained' in okb validate).

Class or instance#

Is a cortado a class or an instance? (Classes and instances explains the difference.) It depends on your questions. Run okb explain decision.instance-or-class and answer each of its questions. Here, the questions compare kinds of drinks, and each kind has its own facts. Every drink type is a class, and one cortado on today’s menu is an instance. A café that only listed menu items could choose differently. Record your choice:

okb decision add --title "Cortado is a class" --decision "Every drink type, Cortado included, is a class. Items on the menu are instances." --why "The questions compare kinds of drinks, and each kind has its own facts. A café that only listed menu items would model them as instances." --about Cortado
Recorded design decision d.5: Cortado is a class.

Check your work#

Run okb status. Step 4 should have a tick. Then move on:

okb status
Espresso drinks  · 31 classes · 0 slots · 0 instances · 6 questions

✓ 1. Determine the domain and scope
✓ 2. Consider reusing existing ontologies
✓ 3. Enumerate important terms
✓ 4. Define the classes and the class hierarchy ◀ you are here
     ✓ A naming convention is set
     ✓ At least two classes, organized with at least one is-a link
     ✓ The class hierarchy has no known mistakes
     ? You've stood back and looked at the whole tree, checking each is-a link against the "Is this really a subclass?" guide
○ 5. Define the properties of classes (slots)
○ 6. Define the facets of the slots
○ 7. Create instances
○ 8. Review against your questions, and iterate

Validator (steps 1–4): ✗ 0  ! 0  i 7   okb validate for details

Step 4 looks done. When you're happy with it: okb step next
okb step next
Now on step 5. (To read a step's guide without moving: okb explain 5)

Step 5 of 8: Define the properties of classes (slots)

  Goal: Turn the remaining terms into slots and attach each one to the most general class whose
  members all have it.
  Why it matters: Classes alone can't answer your questions. Slots hold the facts and
  relationships the answers are made of.

Questions to answer
  • Which remaining terms describe a class rather than being one?
  • For each: is it intrinsic (flavor), extrinsic (name, region), a part, or a relationship to
  another thing (maker)?
  • What is the most general class whose members all have this property?
  • Which competency question needs this slot?

You're done when
  ○ At least one slot
  ○ Every slot is attached to at least one class

Tips
  • Two kinds of slot: properties hold a value (name, year, one of a list); relationships point
  at another thing (maker → Winery).
  • Name relationships as verbs or roles read from the domain class: a Wine has a maker; a
  Winery produces wines.
  • If you're attaching the same slot to every child, attach it to the parent instead.

In Ontology 101's wine example
  • Wine gets: color, body, flavor, sugar, name, maker, grape
  • Winery gets: location, produces
  • Red Wine gets: tanninLevel, because white wines aren't described by tannin

Decision guides for this step  (okb explain <id>)
  decision.slot-placement      Which class does this slot go on?
  decision.class-or-value      New class, or just a slot value?

Commands
  okb property add   okb relationship add   okb show   okb term set

Common mistakes

  • Making a drink an instance too early. “Vertex cortado” is one cup. “Cortado” is a kind, and you can have two of them.
  • Forgetting the second parent. Without it, okb can’t tell that a breve is also a cappuccino.
  • No disjoint groups. Without them, okb can’t catch a drink filed as both pure espresso and milk drink.

Next step#

You built 31 classes in two trees and recorded how you chose them. Next, you’ll say which facts you can state about each class.

View page source