Copyright © 1994 Vikas Malik
All Rights Reserved
This FAQ may be posted to any USENET newsgroup, on-line service, or BBS as long as it is posted in its entirety and includes this copyright statement.
This FAQ may not be distributed for financial gain.
This FAQ may not be included in commercial collections or compilations without express permission from the author.
________________________________________________________________________________________________
From: vmalik@ipass.net (Vikas Malik) Newsgroups: comp.lang.smalltalk,comp.answers,news.answers Subject: Smalltalk FAQ (v.1.0) Followup-To: poster Approved: news-answers-request@MIT.EDU Archive-name: smalltalk-faq Posting-Frequency: monthly Last-modified: May 14,1996 Version: 1.0 URL: http://www.ipass.net/~vmalik________________________________________________________________________________________________
________________________________________________________________________________________________
Q2. What is super?
Ans. super refers to the superclass of the class that
defines the message sent to the receiver. Super is mechanism by
which a sender can overide its own defined method hierarchy.
Q3. What are three different message
types in Smalltalk?
Ans. 1. Unary messages
2. Binary Messages
3. Keyword Messages
Q4. What is shallow copy?
Ans. shallowCopy returns a copy of receiver which shares
the receiver's instance variables.
Q5. What is deep copy?
Ans. deepCopy returns a copy of the receiver with shallow
copies of each instance variable.
Q6. What are class instance
variables?
Ans. Class instance variables are similar to class
variables, except that they are created for eachsubclass of the
defining class. When a class declares a class instance variable,
a new variable is created for each subclass of that class. Each
subclass then has its own instance of the variable and retains
its own value for the variable, but each subclass has a variable
with the same name. Only class methods of a class and its
subclasses can refer to class instance variables; instance
methods cannot.
Q7. What do you get when you inspect
Smalltalk?
Ans. An instance of SystemDictionary. SystemDictionary
maintains all the names of classes, global variables and pool
dictionaries in the system. Smalltalk is the sole instance of the
class SystemDictionary.
Q8. How can I implement stack and
queue operations in Smalltalk?
Ans. An OrderedCollection can be used to implement stack
and queue operations. A stack is implemented by using
addLast: anObject and removeLast methods for
pushing and poping respectively. A Queue is implemented by
using addLast: anObject and removeFirst
methods.
Q9. What is the difference between
an array and a set?
Ans. An array is a fixed size collection whereas a set can grow
in size. An array has integer keys and a set is not keyed. A set
enforces uniqueness upon its members.
Q10. What is the difference
between protocol and category?
Ans. The methods of a class are organised in logical groups
called protocols. Classes are grouped together into groups
called categories.
Q11. What do I get from
1+2*3?
Ans. 9
Q12. How do I stop the execution
of a program?
Ans. By sending message halt.
Q13. What is the difference
between = and == ?
Ans. = is a test for equality. == is a test for
identity (same object). Except for some special classes
like Symbol, Character & SmallInteger, two cases of a value
(eg. 1.54) will not be the identical object, just one with equal
value. The special cases are "special" and any variables that
points to such an object will be by definition "Identical".
Q14. How do I iterate a
collection?
Ans. By using the following enumeration messages.
1. do: aBlock
2. select: aBlock
3. reject: aBlock
4. detect: aBlock
5. collect: aBlock
6. inject: aValue into: aBlock
Q15. How do I use message perform:
?
Ans. perform: method is used to tell an object to execute
a method whose name, rather than being hardcoded, is sent as a
parameter. This means that the name of the message need not be
know until runtime.
anObject perform: #methodNameQ16. What is the difference between detect: and select: methods for collections?
Q17. What is the result of sending
collect: [ :each | each > 5 ] to aCollection?
Ans. A collection whose elements are true and false.
collect:aBlock returns a collection which contains the
results of performing the same operation on each element in the
receiver collection.
Q18. What do I use to concatenate
strings efficiently?
Ans. Streams.
Q19. What is superclass of
Object?
Ans. nil.
Q20. What is subclassResposiblity
method used for?
Ans. subclassResponsibility method is used to defer the
actual implementation of a method.
Q21. What is shouldNotImplement
method used for?
Ans. shouldNotImplement method is used to indicate that a
subclass wants to undefine a method defined in a superclass.
Q22. What methods do I need to
implement if I implement = method for an object?
Ans. hash:
Q23. What method do I need to
implement for proxy objects?
Ans. doesNotUnderstand: aMessage
Q24. What are three pseudo
variables used by VisualWorks?
Ans. self, super and thisContext.
Q25. What is the difference
between SmallInteger and LargeInteger?
Ans. A SmallInteger has fixed number of bytes and a LargeInteger
has variable number of bytes.
Q26. What is the difference
between Symbol and String?
Ans. Symbols are similar to strings except that they are unique.
This means that whilst one can create several string objects
containing the same sequence of characters, there will only be
exactly one instance of a symbol with a given sequence of
characters.
Q27. What is the difference
between Bag and Set?
Ans. A bag can have duplicates whereas a Set contains no
duplicate objects.
Q28. What is the difference
between chaining and cascading?
Ans. In Chaining, one message can follow on after another.
In this case the second message is sent to the object which is
the result of the first message.
anObject msg1 msg2 msg3
In Cascading, each message is followed by a
semicolon (;) and another message. In Cascading, subsequent
messages are sent to the first receiver.
anObject msg1; msg2; msg3
Q29. What is yourself method
used for?
| aCollection |
aCollection := OrderedCollection new add: 1;
add: 2;
yourself.
In the above example add: returns its argument, not the
receiver. Therefore, yourself message is sent to do the proper
assignment of an OrderedCollection to aCollection variable.
Q30. What is the difference
between isMemberOf: and isKindOf: methods?
Ans. isMemberOf: aClass returns true if receiver is an
instance of aClass.
isKindOf: aClass returns true if receiver is an instance
of aClass or one of its subclasses.
Q31. Where is the method new
defined?
Ans. Method new is defined on instance side of class
Behavior.
Q32. Why is an IdentitySet faster
than a Set?
Ans. An IdentitySet is faster that a Set because == is a faster
test than = .
Q33. What happens when I modify a
collection while iterating over it?
Ans. Modifying a collection while iterating over it will give
unpredictable results.
Employees do: [:anEmployee | anEmployee isProgrammer ifTrue: [
Employees remove: anEmployee]]
Above example will not work as expected since we are changing the
size of Employees collection while iterating over it. Making a
copy of the collection will avoid the above problem.
Employees copy do: [:anEmployee | anEmployee isProgrammer ifTrue:
[ Employees remove: anEmployee]]
Q34. What is nil?
Ans. nil is the only instance of the class UndefinedObject
and it is the default value for any new variable until a specific
value is assigned to it.
Q35. What are pool
dictionaries?
Ans. Pool dictionaries are created for providing access to
pool variables to several classes that are not related by
inheritance.
Q35+. What is a literal?
Ans. A literal is a piece of Smalltalk code that the
compiler converts immediately to an object. Literals can be
freely included in the programs just by typing them.
Literal type Example
Character $s
Symbol #name
String 'David Letterman'
Number 12
Boolean false
UndefinedObject nil
Array of literals #('apple' 12.9 name)
Q36. What is MVC?
Q37. What is an aspect?
Ans. An aspect is a piece or subset of model's domain
information.
Q38. What is a dependent?
Ans. A dependent is an object that is dependent on the
information residing in a model. A dependent object is usually a
view, a window, or another model and is contained in dependents
collection of a model.
Q39. How do I add a dependent to a
model? Ans. aModel addDependent: aDependent.
This method adds aDependent to aModel's dependents
collection.
Q40. How do I release dependents
from a model?
Ans. aModel release replaces aModel's dependents
collection with nil.
Q41. What is the changed/update
mechanism?
Ans. The changed/update mechanism is used by a model to
broadcast a notification of change to all its dependents.
Q42. What happens when I send
changed or changed: message to a Model?
Ans. A changed/changed: message sends an update message to all of
receiver's(model) dependents.
Q43. How do I implement an update
method for a view?
Ans. The prototype for an update method for a view is
update: anAspect
anAspect = anAspectOfInterest
ifTrue: [ self invalidate]
Q44. What does
invalidateRectangle: method do?
Ans. Invalidate messages initiate a view's redrawing process.
invalidateRectangle: aRectangle invalidates only that area
of the view defined by aRectangle.
Q45. How does a controller
accesses keyboard events and mouse state?
Ans. By using its instance variable sensor, which references a
TranslatingSensor.
Q46. What is a ValueHolder in
VisualWorks?
Ans. A ValueHolder is a value model. It holds simple model
objects like numbers, strings, etc. A ValueHolder is created by
sending asValue message to any object or sending with:
anObject to ValueHolder class
anObject asValue.
ValueHolder with: anObject
A ValueHolder understands value/value: protocol. value
message is used to access its value. value: anObject message
is used to set its value to anObject.
Q47. What is a channel?
Ans. A channel is a value model that is used as a common
access point for a changing value.
Q48. How do an object register
interest in a ValueModel?
Ans. By sending onChangeSend: aChangeMessage to:
anInterestedObject to a ValueModel. The advantages of this
approach are:
(i) The interested object does not need to be a dependent of the
value model.
(ii) The interested object does not need to implement an update
method.
Q49. What is a dependency
transformer?
A DependencyTransformer implements the behavior needed by
an object to register interest in a value model. A
dependencyTransformer is defined as a dependent of a value model
and converts an update message sent to itself into a specific
change message and sends this change message to the interested
object.
Q50. How do I change the value of
a ValueModel without triggering any updates?
Ans. 1. By using setValue: newValue method instead of
value: newValue method. setValue: method replaces the
value instance variable without sending update messages to
dependents.
2. Remove the DependencyTransformer from the ValueModel's
dependents. Send retractInterestsFor: anObject message to
the ValueModel. This is done just prior to sending value:
newValue message.
Using setValue: disallows all updates. retractInterestsFor: only
disallows a specific update, allowing all others to proceed.
Q51. What is an
AspectAdaptor?
Ans. An AspectAdaptor is a ValueModel whose value actually
belongs to another object called the subject. The task of
AspectAdaptor is to interface the general-purpose view object to
just one aspect of the model(subject). An AspectAdaptor is
created as follows:
| aa |
aa := AspectAdaptor subject: Employee new.
aa forAspect: #ssn.
One can change the ssn of this employee by using aa value:
aNumber. An AspectAdaptor needs to know which messages to send to
the model to access and assign value to one of its aspect. In the
above example value/value: messages sent to aa are converted into
ssn/ssn: and sent to subject. forAspect: #ssn message sets the
getSelector to #ssn and sets the putSelector to #ssn: The value
method of AspectAdaptor is implemented as
value
^subject perform: self getSelector
Q52. What is the subject channel
of an AspectAdaptor?
Q53. What is a
PluggableAdaptor?
Ans. A PluggableAdaptor uses blocks to adapt a model to a
view instead of using just selectors like AspectAdaptor. The
blocks are called the getBlock, the putBlock and
the updateBlock. These blocks get executed when a
PluggableAdaptor receives value/value: and update messages. A
PluggableAdaptor can be created as follows:
| pa |
pa := PluggableAdaptor on: Employee new.
pa getBlock: [ :m | m salary * 30 ]
putBlock: [ :m :v | m salary: (v/30)]
updateBlock: [ :m :a :p | .... ].
On sending value message to pa, getBlock gets executed. It
send salary message to employee(model), multiplies the result by 30
and returns it. In this way, one can perform more complex
operations on model as a result of just sending the value message
to pluggableAdapator.
Q54. What is an
IndexedAdaptor?
Ans. An IndexedAdaptor is similar to AspectAdaptor except
that its subject is a sequenceable collection and value/value:
messages are dispatched to the subject as at:/at: put: .
Q55. What is a SelectionInList?
Ans. A SelectionIinList is a selection model. It has two
instance variables.
(i) listHolder instance variable is a ValueModel
containing a sequenceable collection. listHolder acts as a model
for SequenceView.
(ii) selectionIndexHolder instance variable is a
ValueHolder with the index of the current selection as its
value.
SelectionInList does not have any dependents. Both of its
instance variables have two dependents : the SequenceView and the
SelectionInList object itself.
Q56. What is a
BufferedValueHolder?
Ans. A BufferedValueHolder is a ValueModel that references
two other value models called its subject and trigger
channel. When a BufferedValueHolder receives a value:
message, it holds onto the new value and does not update the
subject until trigger channel becomes true.
Q57. What is the difference
between an IndexedAdaptor and an AspectAdaptor?
Ans. An IndexedAdaptor operates on a numbered instance variable
in the subject, whereas an AspectAdaptor operates on a named
instance variable.
Q58. What is a BlockClosure in
VisualWorks?
Ans. Class BlockClosure implements the block notation in
VisualWorks Smalltalk. In VisualWorks, blocks are close to being
closures. One can declare variables local to the block, and the
names of block parameters are local to the block.
Q59. What is the launcher in
VisualWorks?
Ans. The launcher is the root of the VisualWorks
development environment. Various development tools can be
launched (or opened) from its menu.The launcher is implemented by
VisualLauncher which is a subclass of
ApplicationModel.
Q60. What is a SpecWrapper?
Ans. A VisualWorks component is a SpecWrapper. A SpecWrapper is
wrapper that contains a widget, decoration for the widget, a copy
of WidgetState object and ComponentSpec.
Q61. What is the difference
between an active component and a passive component?
Ans. An active component is a VisualWorks component whose
widget is a View and has a Model and a Controller. A passive
component is a VisualWorks component whose widget is not a
View and it does not depend on a model and a controller.
Q62. What is a widget?
Ans. A widget is a visual part responsible for the visual
representation of a VisualWorks component.
Q63. What is difference between
application model and aspect model?
Ans. An ApplicationModel is responsible for creating and
managing a runtime user interface. An aspect model
contains a single aspect of info and provides the model behavior
for a single VisualWorks component. The relationship between an
application model and an aspect model is that an application
model contains one or more aspect models.
Q64. What is a keyboard
hook?
Ans. A keyboard hook is a used for intercepting all the
keyboard activity going to a VisualWorks component. It is a block
which is evaluated just prior to the widget controller handling a
keyboard event. Keyboard hook can be set as follows:
| comp |
comp := anApplicationModel builder componentAt: #myComponent.
comp widget controller keyboardHook: aBlock.
Q65. What is the
Transcript?
Q66. What is a dispatcher?
Ans. A dispatcher is used by a widget controller to
dispatch notification and validation messages to the
ApplicationModel. A dispatcher is an instance of class
UIDispatcher.
Q67. What is a
ComponentSpec?
Ans. A ComponentSpec describes properties and features of
a VisualWorks component. ComponentSpec provides behavior for
interface persistence in form of source code or text file.
Q68. What is a builder in
ApplicationModel architecture?
Ans. A builder is an instance of class UIBuilder. It is
used to construct a user interface according to the
specifications. It also provides access to the runtime interface.
Builder provides access to named components, the keyboard
processor, the window and aspect models of a running
application.
Q69. What is a FullSpec?
Ans. A FullSpec is a combination of a window spec and a
spec collection. A window spec describes a window and a spec
collection is a collection of component specs for all components
of a window.
Q70. What is a builder's
resource?
Ans. A resource is an object used by the builder to
construct the interface according to the specs. Examples of
resources are aspect models, menus, images, and labels. There are
two types of resources:
1. Static resources - do not change during runtime.
2. Dynamic resources - change during runtime.
Q71. What is the builder's
source?
Ans. The builder's source is an ApplicationModel that
provides the necessary resources to a builder for building an
interface according to the specs. It is kept in source instance
variable of UIBuilder.
Q72. How does a builder caches
resources?
Ans. A builder uses the following variables to cache
resources.
1. bindings to cache aspect models reqired by active
components.
2. labels to cache text labels.
3. visuals to cache visual components.
Q73. What is a lookPolicy
object?
Ans. A lookPolicy object is an instance of one of the
subclasses of the UILookPolicy abstract class. A lookPolicy
object is used to create a VisualWorks component based on the
componentSpec and the specific window environment's look and
feel.
Q74. How can I change a builder's
look policy?
Ans. By sending policy: aLookPolicy message to a
builder.
aBuilder policy: MotifLookPolicy new.
Q75. How is a VisualWorks
component built?
Q76. What methods are used to
access window, keyboardProcessor, named components and aspect
models from a builder?
Ans.
aBuilder window.
aBuilder keyboardProcessor.
aBuilder componentAt: #componentID.
aBuilder aspectAt: #aspect.
Q77. What is a keyboard
processor?
Q78. What is the difference
between preBuildWith: and postBuildWith: methods of
ApplicationModel?
Ans. preBuildWith: aBuilder method allows
anApplicationModel to make any changes to its builder prior to
handling its full spec. postBuildWith: aBuilder method
allows any final changes to the interface prior to opening.
Q79. What is the difference
between postBuildWith: and postOpenWith: methods of
ApplicationModel?
Ans. In the postBuildWith: method, the interface is
completely built but it exists in memory only and window is not
open. Whereas postOpenWith: method allows the application
model to make any changes to the interface with the window
open.
Q80. How do I close a window
programmatically?
Ans. By sending the closeRequest message to anApplicationModel.
closeRequest method sends an update: #closeRequest to
anApplication Model dependents (window is one of the
dependents).
Q81. Which message is sent to
anApplicationModel for notification of a window close?
Ans. noticeOfWindowClose: aWindow.
Q82. Which message is sent to
anApplicationModel for validation of a window close?
Ans. requestForWindowClose.
Q83. What do I mean by Parent
application and subapplication?
Ans. The subapplication is the application model that
manages the subcanvas. The parent application is the
application model that provides the subapplication as an aspect
model.
Q84. What is the SubCanvasSpec's
clientKey?
Ans. clientKey is the message name which is sent to parent
application to acquire the subapplication that manages the
subcanvas.
Q85. What is the SubCanvasSpec's
majorKey?
Ans. majorKey is the name of ApplicationModel subclass
that builds and runs the subcanvas component.
Q86. What is the SubCanvasSpec's
minorKey?
Ans. minorKey is name of the class method that returns a
full spec describing the subcanvas interface.
Q87. How do I rebuild a
subcanvas?
Ans. By sending one of the following messages to aSubCanvas.
client: appModel
client: appModel spec: aSpec
client: appModel spec: aSpec builder: aBuilder
appModel is subapplication, aSpec is full spec of subcanvas,
and aBuilder is an instance of UIBuilder.
Q88. What is
ScheduledControllers?
Ans. ScheduledControllers is a global variable that refers
to the only instance of ControlManager. It is responsible for
managing all current window controllers.
Q89. How do I access active
window?
Ans. ScheduledControllers currentController view
Q90. How do I access widget of a
named component?
Ans. (anApplicationModel builder componentAt: #compID)
widget
Q91. How do I give keyboard focus
to a widget?
Ans. By sending takeKeyboardFocus to a VisualWorks
component.
Q92. How do I change a component's
label?
Ans. comp labelString: aString
Q93. How do I make a widget
invisible/visible?
Ans.
comp beInvisible.
comp beVisible.
Q94. How do I enable/disable a
component?
comp enable.
comp disable.
Q95. Which method is used by
aSequenceView to display its contents?
Q96. How do I use an arbitrary
method to display contents in aSequenceView?
Ans. By sending displayStringSelector: aSymbol message to
aSequenceView. aSymbol is the name of method used to display
strings.
Q97. How do I change grid spacing
of aSequenceView?
Ans. aSequenceView lineGrid: aNumber