Transcript poosd-A.ppt
Principles of Object-Oriented Software Development The language Smalltalk The language Smalltalk Introduction Terminology Expressions Control Objects Inheritance Techniques Summary Smalltalk -- a radical change in programming 1972 1976 1980 1990 Dynabook -- Alan Kay SmallTalk76 SmallTalk80 ObjectWorks/SmallTalk -- VisualWorks Design principles -- rapid prototyping uniform object model -- control dynamic typing -- flexible standard libraries -- functionality Terminology Smalltalk • • • • • literal -- constants object -- action by messages class -- collection of protocols protocol -- related methods category -- collection of classes Literal constants • • • • • • number -- 1, 34.6, 8r24 character -- $a, $b, ... string -- "this is a string" symbol -- #Float byte array -- # [0 255 2 7] array of literals -- # (12.1 # ($a $b)) Assignment aVar := 1. Variables temporary, instance, class, pool, global Block expressions [ :arg | expression ] Message expressions unary, binary, keyword Unary 1.0 sin , Random new Binary arithmetic -- ctr + 1 comparison -- aVar >= 200 combination -- 100 @ 200 association -- # Two -> 2 Keyword methods (i <= 7) ifTrue: [ m:= "oke" ] ifFalse: [ ... ] Control structures conditional -- ifTrue: ifFalse: iteration -- whileTrue: looping -- to: by: do: [ :i | ... ] Smalltalk -- control Object -- behavior instance variables, methods Class -- description class variables, class methods Self -- self reference super for ancestors Smalltalk -- objects (1) Example -- class Behavior subclass: #Ctr instanceVariableNames: 'value' Ctr methodsFor: 'initialization' initialize value := 0. Ctr methodsFor: 'modifications' add: aValue value := value + aValue. Ctr methodsFor: 'inspection' value ^value Smalltalk -- objects (2) Class description meta class Ctr class instanceVariableNames: ‘ ‘ Ctr class methodsFor: 'instance creation' new ^super new initialize Smalltalk -- objects (3) Inheritance Object Magnitude ArithmeticValue Number Integer Smalltalk -- inheritance Model subclass: #Ctr Model ... initialize value := 0. TV open: self. ... add: anInt value := value + anInt. self changed: #value. Smalltalk -- technology (1) View subclass: #TV View instanceVariableNames: '' TV methodsFor: 'updating' update: aValue Transcript show: 'ok'; cr . TV class instanceVariableNames: '' TV class methodsFor: 'instance creation' open: aCtr self new model: aCtr Smalltalk -- technology (2) The language Smalltalk • • • • • • design principles -- prototyping terminology -- object, class, protocols syntax -- method expressions objects -- self reference inheritance -- class hierarchy techniques -- MVC paradigm