SlideShare uma empresa Scribd logo
1 de 25
Stéphane Ducasse 1
Stéphane Ducasse
stephane.ducasse@inria.fr
http://stephane.ducasse.free.fr/
Some Points on Classes
S.Ducasse 2
Outline
Class definition
Method definition
Basic class instantiation
S.Ducasse 3
A template is proposed by the browser:
Smalltalk defineClass: #NameOfClass
superclass: #{NameOfSuperclass}
indexedType: #none
private: false
instanceVariableNames: 'instVarName1
instVarName2'
classInstanceVariableNames: ''
imports: ''
category: ''
Class Definition (VW)
S.Ducasse 4
Fill the Template (VW)
Smalltalk defineClass: #Packet
superclass: #{Object}
indexedType: #none
private: false
instanceVariableNames: 'contents
addressee originator'
classInstanceVariableNames: ''
imports: ''
category: 'LAN'
Automatically a class named “Packet class” is created.
Packet is the unique instance of “Packet class”.To see it,
click on the class button in the browser
S.Ducasse 5
Class Definition: (Sq)
A template is proposed by the browser:
NameOfSuperclass subclass: #NameOfClass
instanceVariableNames: 'instVarName1
instVarName2'
classVariableNames: 'ClassVarName1
ClassVarName2'
poolDictionaries: ''
category: 'CategoryName’
S.Ducasse 6
Filling the Template (Sq)
Just fill this Template in:
Object subclass: #Packet
instanceVariableNames: 'contents addressee
originator '
classVariableNames: ''
poolDictionaries: ''
category: 'LAN-Simulation’
Automatically a class named “Packet class” is
created. Packet is the unique instance of Packet
class.To see it, click on the class button in the
browser
S.Ducasse 7
Named InstanceVariables
instanceVariableNames: 'instVarName1 instVarName2'
...
instanceVariableNames: 'contents addressee originator '
...
•Begins with a lowercase letter
•Explicitly declared: a list of instance variables
•Name should be unique in the inheritance chain
•Default value of instance variable is nil
•Private to the instance: instance based (vs. C++ class-
based)
•Can be accessed by all the methods of the class and its
subclasses
•Instance variables cannot be accessed by class methods.
•A client cannot directly access instance variables.
•The clients must use accessors to access an instance
variable.
S.Ducasse 8
Roadmap
Class definition
Method definition
Basic class instantiation
S.Ducasse 9
Method Definition
• Fill in the template. For example:
Packet>>defaultContents
“returns the default contents of a Packet”
^ ‘contents no specified’
Workstation>>originate: aPacket
aPacket originator: self.
self send: aPacket
• How to invoke a method on the same object? Send the
message to self
Packet>>isAddressedTo: aNode
“returns true if I’m addressed to the node aNode”
^ self addressee = aNode name
S.Ducasse 10
Accessing InstanceVariables
Using direct access for the methods of the class
Packet>>isSentBy: aNode
^ originator = aNode
is equivalent to use accessors
Packet>>originator
^ originator
Packet>>isSentBy: aNode
^ self originator = aNode
Design Hint: Do not directly access instance
variables of a superclass from subclass methods.
This way classes are not strongly linked.
S.Ducasse 11
Methods always return aValue
• Message = effect + return value
• By default, a method returns self
• In a method body, the ^ expression returns the value of
the expression as the result of the method execution.
Node>>accept: thePacket
self send: thePacket
This is equivalent to:
Node>>accept: thePacket
self send: thePacket.
^self
11
S.Ducasse 12
Methods always return a value
• If we want to return the value returned by #send:
Node>>accept: thePacket
^self send: thePacket.
• Use ^ self to notify the reader that something abnormal
is arriving
MyClass>>foo
…
^ self
S.Ducasse 13
Some Naming Conventions
• Shared variables begin with an upper case letter
• Private variables begin with a lower case letter
• For accessors, use the same name as the instance
variable accessed:
Packet>>addressee
^ addressee
Packet>>addressee: aSymbol
addressee := aSymbol
S.Ducasse 14
Some Naming Conventions
• Use imperative verbs for methods performing an
action like #openOn:, #close, #sleep
• For predicate methods (returning a boolean)
prefix the method with is or has
• Ex: isNil, isAddressedTo:, isSentBy:
• For converting methods prefix the method with
as
• Ex: asString
S.Ducasse 15
Roadmap
Class definition
Method definition
Basic class instantiation
S.Ducasse 16
Object Instantiation
Objects can be created by:
- Direct Instance creation: new/new:
- Messages to instances that create other objects
- Class specific instantiation messages
S.Ducasse 17
Object Creation
- When a class creates an object =
allocating memory + marking it to
be instance of that class
S.Ducasse 18
Instance Creation with new
aClass new
returns a newly and UNINITIALIZED instance
OrderedCollection new -> anOrderedCollection ()
Packet new -> aPacket
Default instance variable values are nil
nil is an instance of UndefinedObject and only
understands a limited set of messages
S.Ducasse 19
Messages to Instances
Messages to Instances that create Objects
1 to: 6 (an
interval)
1@2 (a point)
(0@0) extent: (100@100) (a rectangle)
#lulu asString (a string)
1 printString
(a string)
3 asFloat (a float)
#(23 2 3 4) asSortedCollection
(a
S.Ducasse 20
Opening the Box
1 to: 6
creates an interval
Number>>to: stop
"Answer an Interval from the receiver up to the
argument,
stop, with each next element computed by incrementing
the
previous one by 1."
^Interval from: self to: stop by: 1
S.Ducasse 21
Strings...
1 printString
Object>>printString
"Answer a String whose characters are a description
of the receiver."
| aStream |
aStream := WriteStream on: (String new: 16).
self printOn: aStream.
^ aStream contents
S.Ducasse 22
Instance Creation
1@2
creates a point
Number>>@ y
"Answer a new Point whose x value is the receiver and
whose y value is the argument."
<primitive: 18>
^ Point x: self y: y
S.Ducasse 23
Class-specific Messages
Array with: 1 with: 'lulu'
OrderedCollection with: 1 with: 2 with: 3
Rectangle fromUser -> 179@95 corner:
409@219
Browser browseAllImplementorsOf: #at:put:
Packet send:‘Hello mac’ to: #mac
Workstation withName: #mac
S.Ducasse 24
new and new:
• new:/basicNew: is used to specify the size of the
created instance
Array new: 4 -> #(nil nil nil nil)
• new/new: can be specialized to define
customized creation
• basicNew/basicNew: should never be overridden
• #new/basicNew and new:/basicNew: are class
methods
S.Ducasse 25
Summary
How to define a class?
What are instance variables?
How to define a method?
Instances creation methods

Mais conteúdo relacionado

Mais procurados (9)

Stoop 423-smalltalk idioms
Stoop 423-smalltalk idiomsStoop 423-smalltalk idioms
Stoop 423-smalltalk idioms
 
Stoop ed-some principles
Stoop ed-some principlesStoop ed-some principles
Stoop ed-some principles
 
Chapter ii(oop)
Chapter ii(oop)Chapter ii(oop)
Chapter ii(oop)
 
Scaling modern JVM applications with Akka toolkit
Scaling modern JVM applications with Akka toolkitScaling modern JVM applications with Akka toolkit
Scaling modern JVM applications with Akka toolkit
 
Stoop 416-lsp
Stoop 416-lspStoop 416-lsp
Stoop 416-lsp
 
Ete programs
Ete programsEte programs
Ete programs
 
Ensayo Convergencia Informatica
Ensayo Convergencia InformaticaEnsayo Convergencia Informatica
Ensayo Convergencia Informatica
 
Image Recognition with Neural Network
Image Recognition with Neural NetworkImage Recognition with Neural Network
Image Recognition with Neural Network
 
Using Combine, SwiftUI and callAsFunction to build an experimental localizati...
Using Combine, SwiftUI and callAsFunction to build an experimental localizati...Using Combine, SwiftUI and callAsFunction to build an experimental localizati...
Using Combine, SwiftUI and callAsFunction to build an experimental localizati...
 

Destaque (7)

12 virtualmachine
12 virtualmachine12 virtualmachine
12 virtualmachine
 
13 traits
13 traits13 traits
13 traits
 
09 metaclasses
09 metaclasses09 metaclasses
09 metaclasses
 
11 bytecode
11 bytecode11 bytecode
11 bytecode
 
10 reflection
10 reflection10 reflection
10 reflection
 
99 questions
99 questions99 questions
99 questions
 
05 seaside canvas
05 seaside canvas05 seaside canvas
05 seaside canvas
 

Semelhante a 9 - OOP - Smalltalk Classes (c)

4 - OOP - Taste of Smalltalk (VisualWorks)
4 - OOP - Taste of Smalltalk (VisualWorks)4 - OOP - Taste of Smalltalk (VisualWorks)
4 - OOP - Taste of Smalltalk (VisualWorks)
The World of Smalltalk
 
Pharo, an innovative and open-source Smalltalk
Pharo, an innovative and open-source SmalltalkPharo, an innovative and open-source Smalltalk
Pharo, an innovative and open-source Smalltalk
Serge Stinckwich
 

Semelhante a 9 - OOP - Smalltalk Classes (c) (20)

Stoop 304-metaclasses
Stoop 304-metaclassesStoop 304-metaclasses
Stoop 304-metaclasses
 
Stoop 432-singleton
Stoop 432-singletonStoop 432-singleton
Stoop 432-singleton
 
5 - OOP - Smalltalk in a Nutshell (c)
5 - OOP - Smalltalk in a Nutshell (c)5 - OOP - Smalltalk in a Nutshell (c)
5 - OOP - Smalltalk in a Nutshell (c)
 
8 - OOP - Syntax & Messages
8 - OOP - Syntax & Messages8 - OOP - Syntax & Messages
8 - OOP - Syntax & Messages
 
4 - OOP - Taste of Smalltalk (VisualWorks)
4 - OOP - Taste of Smalltalk (VisualWorks)4 - OOP - Taste of Smalltalk (VisualWorks)
4 - OOP - Taste of Smalltalk (VisualWorks)
 
5 - OOP - Smalltalk in a Nutshell (a)
5 - OOP - Smalltalk in a Nutshell (a)5 - OOP - Smalltalk in a Nutshell (a)
5 - OOP - Smalltalk in a Nutshell (a)
 
Pharo, an innovative and open-source Smalltalk
Pharo, an innovative and open-source SmalltalkPharo, an innovative and open-source Smalltalk
Pharo, an innovative and open-source Smalltalk
 
Stoop ed-unit ofreuse
Stoop ed-unit ofreuseStoop ed-unit ofreuse
Stoop ed-unit ofreuse
 
Java-Module 3-PPT-TPS.pdf.Java-Module 3-PPT-TPS.pdf
Java-Module 3-PPT-TPS.pdf.Java-Module 3-PPT-TPS.pdfJava-Module 3-PPT-TPS.pdf.Java-Module 3-PPT-TPS.pdf
Java-Module 3-PPT-TPS.pdf.Java-Module 3-PPT-TPS.pdf
 
Test beautycleanness
Test beautycleannessTest beautycleanness
Test beautycleanness
 
5 - OOP - Smalltalk in a Nutshell (b)
5 - OOP - Smalltalk in a Nutshell (b)5 - OOP - Smalltalk in a Nutshell (b)
5 - OOP - Smalltalk in a Nutshell (b)
 
Class object method constructors in java
Class object method constructors in javaClass object method constructors in java
Class object method constructors in java
 
java classes
java classesjava classes
java classes
 
Class notes(week 6) on inheritance and multiple inheritance
Class notes(week 6) on inheritance and multiple inheritanceClass notes(week 6) on inheritance and multiple inheritance
Class notes(week 6) on inheritance and multiple inheritance
 
Stoop 300-block optimizationinvw
Stoop 300-block optimizationinvwStoop 300-block optimizationinvw
Stoop 300-block optimizationinvw
 
Stoop ed-lod
Stoop ed-lodStoop ed-lod
Stoop ed-lod
 
06 inheritance
06 inheritance06 inheritance
06 inheritance
 
The Ring programming language version 1.3 book - Part 5 of 88
The Ring programming language version 1.3 book - Part 5 of 88The Ring programming language version 1.3 book - Part 5 of 88
The Ring programming language version 1.3 book - Part 5 of 88
 
Ruby and Rails by example
Ruby and Rails by exampleRuby and Rails by example
Ruby and Rails by example
 
Introduction to Ruby Programming Language
Introduction to Ruby Programming LanguageIntroduction to Ruby Programming Language
Introduction to Ruby Programming Language
 

Mais de The World of Smalltalk (18)

08 refactoring
08 refactoring08 refactoring
08 refactoring
 
07 bestpractice
07 bestpractice07 bestpractice
07 bestpractice
 
06 debugging
06 debugging06 debugging
06 debugging
 
05 seaside
05 seaside05 seaside
05 seaside
 
04 idioms
04 idioms04 idioms
04 idioms
 
03 standardclasses
03 standardclasses03 standardclasses
03 standardclasses
 
02 basics
02 basics02 basics
02 basics
 
01 intro
01 intro01 intro
01 intro
 
Stoop sed-smells
Stoop sed-smellsStoop sed-smells
Stoop sed-smells
 
Stoop sed-class initialization
Stoop sed-class initializationStoop sed-class initialization
Stoop sed-class initialization
 
Stoop sed-class initialization
Stoop sed-class initializationStoop sed-class initialization
Stoop sed-class initialization
 
Stoop metaclasses
Stoop metaclassesStoop metaclasses
Stoop metaclasses
 
Stoop ed-subtyping subclassing
Stoop ed-subtyping subclassingStoop ed-subtyping subclassing
Stoop ed-subtyping subclassing
 
Stoop ed-inheritance composition
Stoop ed-inheritance compositionStoop ed-inheritance composition
Stoop ed-inheritance composition
 
Stoop ed-frameworks
Stoop ed-frameworksStoop ed-frameworks
Stoop ed-frameworks
 
Stoop ed-dual interface
Stoop ed-dual interfaceStoop ed-dual interface
Stoop ed-dual interface
 
Stoop 450-s unit
Stoop 450-s unitStoop 450-s unit
Stoop 450-s unit
 
Stoop 440-adaptor
Stoop 440-adaptorStoop 440-adaptor
Stoop 440-adaptor
 

Último

Último (20)

Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 

9 - OOP - Smalltalk Classes (c)

  • 1. Stéphane Ducasse 1 Stéphane Ducasse stephane.ducasse@inria.fr http://stephane.ducasse.free.fr/ Some Points on Classes
  • 2. S.Ducasse 2 Outline Class definition Method definition Basic class instantiation
  • 3. S.Ducasse 3 A template is proposed by the browser: Smalltalk defineClass: #NameOfClass superclass: #{NameOfSuperclass} indexedType: #none private: false instanceVariableNames: 'instVarName1 instVarName2' classInstanceVariableNames: '' imports: '' category: '' Class Definition (VW)
  • 4. S.Ducasse 4 Fill the Template (VW) Smalltalk defineClass: #Packet superclass: #{Object} indexedType: #none private: false instanceVariableNames: 'contents addressee originator' classInstanceVariableNames: '' imports: '' category: 'LAN' Automatically a class named “Packet class” is created. Packet is the unique instance of “Packet class”.To see it, click on the class button in the browser
  • 5. S.Ducasse 5 Class Definition: (Sq) A template is proposed by the browser: NameOfSuperclass subclass: #NameOfClass instanceVariableNames: 'instVarName1 instVarName2' classVariableNames: 'ClassVarName1 ClassVarName2' poolDictionaries: '' category: 'CategoryName’
  • 6. S.Ducasse 6 Filling the Template (Sq) Just fill this Template in: Object subclass: #Packet instanceVariableNames: 'contents addressee originator ' classVariableNames: '' poolDictionaries: '' category: 'LAN-Simulation’ Automatically a class named “Packet class” is created. Packet is the unique instance of Packet class.To see it, click on the class button in the browser
  • 7. S.Ducasse 7 Named InstanceVariables instanceVariableNames: 'instVarName1 instVarName2' ... instanceVariableNames: 'contents addressee originator ' ... •Begins with a lowercase letter •Explicitly declared: a list of instance variables •Name should be unique in the inheritance chain •Default value of instance variable is nil •Private to the instance: instance based (vs. C++ class- based) •Can be accessed by all the methods of the class and its subclasses •Instance variables cannot be accessed by class methods. •A client cannot directly access instance variables. •The clients must use accessors to access an instance variable.
  • 8. S.Ducasse 8 Roadmap Class definition Method definition Basic class instantiation
  • 9. S.Ducasse 9 Method Definition • Fill in the template. For example: Packet>>defaultContents “returns the default contents of a Packet” ^ ‘contents no specified’ Workstation>>originate: aPacket aPacket originator: self. self send: aPacket • How to invoke a method on the same object? Send the message to self Packet>>isAddressedTo: aNode “returns true if I’m addressed to the node aNode” ^ self addressee = aNode name
  • 10. S.Ducasse 10 Accessing InstanceVariables Using direct access for the methods of the class Packet>>isSentBy: aNode ^ originator = aNode is equivalent to use accessors Packet>>originator ^ originator Packet>>isSentBy: aNode ^ self originator = aNode Design Hint: Do not directly access instance variables of a superclass from subclass methods. This way classes are not strongly linked.
  • 11. S.Ducasse 11 Methods always return aValue • Message = effect + return value • By default, a method returns self • In a method body, the ^ expression returns the value of the expression as the result of the method execution. Node>>accept: thePacket self send: thePacket This is equivalent to: Node>>accept: thePacket self send: thePacket. ^self 11
  • 12. S.Ducasse 12 Methods always return a value • If we want to return the value returned by #send: Node>>accept: thePacket ^self send: thePacket. • Use ^ self to notify the reader that something abnormal is arriving MyClass>>foo … ^ self
  • 13. S.Ducasse 13 Some Naming Conventions • Shared variables begin with an upper case letter • Private variables begin with a lower case letter • For accessors, use the same name as the instance variable accessed: Packet>>addressee ^ addressee Packet>>addressee: aSymbol addressee := aSymbol
  • 14. S.Ducasse 14 Some Naming Conventions • Use imperative verbs for methods performing an action like #openOn:, #close, #sleep • For predicate methods (returning a boolean) prefix the method with is or has • Ex: isNil, isAddressedTo:, isSentBy: • For converting methods prefix the method with as • Ex: asString
  • 15. S.Ducasse 15 Roadmap Class definition Method definition Basic class instantiation
  • 16. S.Ducasse 16 Object Instantiation Objects can be created by: - Direct Instance creation: new/new: - Messages to instances that create other objects - Class specific instantiation messages
  • 17. S.Ducasse 17 Object Creation - When a class creates an object = allocating memory + marking it to be instance of that class
  • 18. S.Ducasse 18 Instance Creation with new aClass new returns a newly and UNINITIALIZED instance OrderedCollection new -> anOrderedCollection () Packet new -> aPacket Default instance variable values are nil nil is an instance of UndefinedObject and only understands a limited set of messages
  • 19. S.Ducasse 19 Messages to Instances Messages to Instances that create Objects 1 to: 6 (an interval) 1@2 (a point) (0@0) extent: (100@100) (a rectangle) #lulu asString (a string) 1 printString (a string) 3 asFloat (a float) #(23 2 3 4) asSortedCollection (a
  • 20. S.Ducasse 20 Opening the Box 1 to: 6 creates an interval Number>>to: stop "Answer an Interval from the receiver up to the argument, stop, with each next element computed by incrementing the previous one by 1." ^Interval from: self to: stop by: 1
  • 21. S.Ducasse 21 Strings... 1 printString Object>>printString "Answer a String whose characters are a description of the receiver." | aStream | aStream := WriteStream on: (String new: 16). self printOn: aStream. ^ aStream contents
  • 22. S.Ducasse 22 Instance Creation 1@2 creates a point Number>>@ y "Answer a new Point whose x value is the receiver and whose y value is the argument." <primitive: 18> ^ Point x: self y: y
  • 23. S.Ducasse 23 Class-specific Messages Array with: 1 with: 'lulu' OrderedCollection with: 1 with: 2 with: 3 Rectangle fromUser -> 179@95 corner: 409@219 Browser browseAllImplementorsOf: #at:put: Packet send:‘Hello mac’ to: #mac Workstation withName: #mac
  • 24. S.Ducasse 24 new and new: • new:/basicNew: is used to specify the size of the created instance Array new: 4 -> #(nil nil nil nil) • new/new: can be specialized to define customized creation • basicNew/basicNew: should never be overridden • #new/basicNew and new:/basicNew: are class methods
  • 25. S.Ducasse 25 Summary How to define a class? What are instance variables? How to define a method? Instances creation methods