December 21, 2024

Artwork instance methods

 

The instance methods of Artwork are as follows:

height
   "Answer the height of the receiver."
   ^height

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

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

media
   "Answer the media of the receiver."
   ^media

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

price
   "Answer the price of the receiver."
   ^price

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

size
   "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'

title
   "Answer the title of the receiver."
   ^title

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

width
   "Answer the width of the receiver."
   ^width

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

yearCreated
   "Answer the yearCreated of the receiver."
   ^yearCreated

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