Make Closed

Change Modifier > Make Closed removes 'as open' from a class, record, component or function, returning it to EK9's closed-by-default. Here Shape says 'as open' but nothing extends it - an openness nobody uses. To play it in the IDE: Help > Lessons > Refactoring…, or ek9 -ide -lesson make-closed.

The EK9 IDE as the lesson opens

Start from

The code the lesson starts from: copy it into a file of your own and follow the steps.

#!ek9
defines module lesson.makeclosed

  defines class

    Shape as open

      describe() as pure
        <- rtn as String: "a shape, not extended by anything"

  defines program

    Shapes()
      stdout <- Stdout()
      shape <- Shape()
      stdout.println(shape.describe())

//EOF

Step 1: Where it is

Put the caret on Shape, on line 6.

The EK9 IDE once this is done: Put the caret on Shape, on line 6

Step 2: Make Closed

Right-click it - or choose Refactor > Refactor This… - and choose Change Modifier > Make Closed.

The EK9 IDE once this is done: Right-click it - or choose Refactor > Refactor This… - and choose Change Modifier > Make Closed

Step 3: Preview and apply

The preview shows every change the refactoring makes; then the IDE formats each file it changed. Choose Apply.

The result

That is Make Closed: Shape no longer says 'as open', so it is closed again - exactly where every EK9 type starts. Had anything already extended it, the preview would have listed each subtype instead of offering Apply. Make Open reverses it; Make Abstract and Make Concrete sit beside it in the same submenu. AI assistants use the ek9_make_closed tool.

The EK9 IDE when the lesson has finished

Where this lesson comes from