| ||
Student Originated Software 1997-1998
| ||
A Software Engineering Course at The Evergreen State College | ||
|
Student Originated Software 1997-8Object-Oriented Programming (Smalltalk)Lecture 2alast time:
objects
what's a class? defining objects - classes and instances inheritance, overriding, polymorphism (next week) using oo models for software development - modeling the real world! the language.... naming conventions - height, myHeight; Book, aBook; Employee, anEmployee literals (constants) 8r377, 16rFF,1.586e5,$a,#(1,2,3),#[1,2,3] variables sending messages every message expression has a value. unary, binary, keyword; left to right. list addFirst: newComponent list removeLast ages at: 'Brett' put:3 address at: 'Peggy' HouseholdFinances spend:32.50 on: 'utilities' 1+2*3 2*theta sin (2*theta) sin frame scale: factor max:5 frame scale: (factor max:5) bigFrame width:smallFrame width*2 p.22 combining messages (chaining, cascading) (book openAtPage: 1+2*3) print most methods return self, usually by default, but not always! block - a deferred sequence of messages - evaluated when the block receives the message aBlock := [a:=0]. aBlock value MyBlock := [:anObject | anObject print]. anotherBlock := [:parm1 :parm2| |tmp| tmp := parm1 incorporate:parm2. tmp := rehash. ] executing blocks MyBlock value: 'This is a string sent to print'. value, value:, value:value:, value:value:value: valueWithArguments:argArray (> 3 arguments. classes attributes (class and instance variables) methods (class and instance methods) Object subclass #SpendingHistory instanceVariableNames: 'cashOnHand expenditures' classVariableNames: ' ' poolDictionaries: ' ' category: 'Spending' that's all there is to the language! ---------------- the smalltalk virtual machine
advice:
---------------- about visual works (minimal subset)
launcher, main window (aka transcript) workspace select function (editing), operate function (undo, do it, inspect SAVING YOUR IMAGE....file-out-as #(1 2 'three') "inspect it" | array1 array3 array2 | array1 := #(1 2 'three'). array3 := array2 := array1. array1:= #[6 7 8]. array2:= #[3 4 5]. array1 inspect. array2 inspect. array3 inspect. ---------- Application Development The system browser! its panes: class categories, classes, protocols, methods, in Lab - Today, we will do Chapter 6 & 7. add a new method to an existing class (Number) diff:aNumber "return the absolute difference between me and aNumber" | temp | temp := self - aNumber. temp < 0 ifTrue:[^temp negated] ifFalse:[^temp] diff:aNumber "return the absolute difference between me and aNumber" ^(self - aNumber) abs some useful browsers and menu operations..... system browser class browser hierarchy implementors of --------- A small application (Spending) new category, with classes & methods). self new initialize self new setInitialBalace:anAmount ^self new setInitialBalace:anAmount setInitialBalance: anAmount cashOnHand := anAmount. expenditures := Dictionary new. totalSpentOn: reason (expenditures includesKey: reason) ifTrue:[^expenditures at:reason] ifFalse:[0] spend:anAmount on:reason expenditures at: reason put: (self totalSpentOn: reason) + anAmount. cashOnHand := cashOnHand - anAmount. printOn:aStream super printOn:aStream. aStream space. aStream nextPutAll: 'balance:' cashOnHand printOn: aStream. expenditures keysAndValuesDo: [:reason :amount | aStream cr. reason printOn: aStream. aStream tab. amount printOn: aStream] invoking the app: mySpendingHistory initialBalance:600 mySpendingHistory spend:1000 on: 'rent'. Saving your source code file out as ... Spending.st using the file browser, 'spawning' a new (file) broswer
|