More Smalltalk - PowerPoint PPT Presentation

1 / 10
About This Presentation
Title:

More Smalltalk

Description:

More Smalltalk – PowerPoint PPT presentation

Number of Views:62
Avg rating:3.0/5.0
Slides: 11
Provided by: chrisb2
Learn more at: https://www.cs.usfca.edu
Category:

less

Transcript and Presenter's Notes

Title: More Smalltalk


1
More Smalltalk
  • August 30, 2002
  • CS 345

2
Objects and Messages
  • Everything in Smalltalk is an object.
  • You communicate with objects via messages.
  • The receiver of a message responds via the
    execution of a method.
  • ltobjectgt ltselector1gt arg1 ltselector2gt arg2
  • myList at 1 put someObject

3
Numbers
  • Numbers are instances of class Number
  • Respond to messages about arithmetic.
  • , -, , /, work as expected.
  • Left-to-right evaluation.
  • // quotient (integer division)
  • \\ remainder (modular division)
  • Numbers understand a rich set of methods
  • sin, abs, asRandom, asCharacter, bit
    manipulation, looping

4
Iteration
  • To do a for loop, send a message to a number.
  • 1 to 10 do
  • index anArray at index put (aValue
    index).
  • 10 timesRepeat
  • anArray addLast elt.
  • code represents a block.
  • Treats a chunk of statements as a single object.

5
Strings
  • Delimited by single quotes.
  • s lt- hello there!
  • s lt- String new.
  • Strings have a rich set of methods
  • Byte and character manipulation
  • Comparison, matching, search
  • Conversion
  • Formatting

6
Conditionals
  • True and False are objects.
  • Comparison methods return true or false.
  • This can be used to do if and while.
  • (a gt 12) ifTrue Transcript show True.
  • ifFalse Transcript show False.
  • index lt- 1.
  • index lt anArray size whileTrue
  • anArray at index put (index index).
  • (this uses a Block to test the condition)

7
Program design
  • Program design consists of constructing a set of
    objects and determining how they relate to each
    other.
  • is-A relationship
  • has-A relationship
  • Typically, youll have an object or set of
    objects (e.g., a GUI) that implement a start or
    run method, triggering other objects.

8
OO design
  • Objects have attributes and services.
  • Attributes instance variables
  • Services methods.
  • Design For each object, write out its
    responsibilities and its collaborators.
  • Think about use cases how will other objects
    want to use this object?

9
OO design tools
  • Brainstorming
  • CRC cards
  • UML Unified Modeling Language
  • Rational Rose www.rational.com
  • Object Management Group www.omg.org/uml
  • UML provides a powerful set of tools for
    designing classes and the relationships between
    them.

10
OO design example
  • Design a calculator
  • User interface
  • Engine
Write a Comment
User Comments (0)
About PowerShow.com