Initialize a Rectangle inside a class

138 Views Asked by At

I have a class named Map. I want to initialize a rectangle from the Rectangle class origin: 0 @ 0 corners: 50 @ 40 inside the Map. So, when I try in workspace as

myMap := Map new. 

it should return me (0 @ 0) corner: (50 @ 40).

I have tried:

initialize Rectangle origin: 0@0 corner: 100@100.

but it didn't work? any ideas?

1

There are 1 best solutions below

0
On BEST ANSWER

Look, if you want to initialise the instance variable, then you have to define it first:

Object subclass: #Map
  instanceVariableNames: 'rectangle'
  ...

and then you initialise it:

initialize
  rectangle := Rectangle origin: 0@0  corner: 100@100.

Now if you want to subclass Rectangle, and want to initialise your map with 0@0 corner: 100@100 by default you do:

initialize
  self setOrigin: 0@0 corner: 100@100