Search code examples
smalltalkpharo

How to implement getter in smalltalk pharo


I have class Person with my setters and getters like this:

Object subclass: #Person
instanceVariableName: 'name document'
classVariableName ' '
package: 'foo'

name
^name

name: anObject
name:= anObject

document
^document

document: anObject
document:= anObject

Then i instance my class in my TestPerson

setUp
p1:= Person name:'Alice' document:='12345'

So here i don't undestand how can i implement my getter to compare if my name is really Alice. For example in Java it Will be like this:

p1.getName().equals("Alice");

Solution

  • p1 name = 'Alice'
    

    You really need to read a book on Smalltalk, you are missing the basics and "learning by stack overflow" does not seems to be the best way.

    There is a MOOC: http://mooc.pharo.org/.
    There are a lot of free books here: http://books.pharo.org
    Here you have some free general books: http://stephane.ducasse.free.fr/FreeBooks.html
    And here you can find more general documentation: http://pharo.org/documentation (you can watch some introductory screencasts there).