July 2, 2022

Artwork instance methods


The instance methods of Artwork are as follows:

   "Answer the height of the receiver."

height: aNumber
   "Set the height of the receiver to aNumber (a number
   of cms). Answer the receiver."
   height := aNumber

   "Initialize the receiver with title set to the
   string 'untitled'. Answer the receiver."
   self title: 'untitled'

   "Answer the media of the receiver."

media: aString
   "Set the media of the receiver to aString (a
   string). Answer the receiver."
   media := aString

   "Answer the price of the receiver."

price: aFloat
   "Set the price of the receiver to aFloat (a float).
   Answer the receiver"
   price := aFloat

   "Answer with a string that indicates the height of
   the receiver multiplied by the width of the receiver
   in cms."
   ^self height printString,' cm ',' x ', self width
   printString ,' cm'

   "Answer the title of the receiver."

title: aString
   "Set the title of the receiver to aString ( a
   string). Answer the receiver"
   title := aString

   "Answer the width of the receiver."

width: aNumber
   "Set the width of the receiver to a Number ( a
   number of cms). Answer the receiver."
   width := aNumber

   "Answer the yearCreated of the receiver."

yearCreated: aString
   "Set the yearCreated of the receiver to aString (a
   String representing a year eg '1998'). Answer
   the receiver."
   yearCreated := aString

There is nothing too dramatic going on here. Each getter returns the value of the object referenced by the receiver's instance variable and the setters use assignment to set the instance variable to the object supplied as the argument. The initialize method sets the instance variable title of the receiver to a string object, in this case 'untitled'. The reasoning for this shouldn't concern you too much at this stage.

However both the initialize and size methods require us to consider the concept of self.

Next page » self

Previous page « Artwork protocol
































































Up to top of page