The Count Slides
P | N
- The Count
- Pieces:
- Introducing the Problem
- OOA: Object-Oriented Analysis
- OOD: Object-Oriented Design
- OOP: Object-Oriented Programming
- Why we did it so flexibly: ASCII and Date Counts
- Why we aimed for reuse: A Profit Calculator
- Introducing the Problem
- I love to count. Build me a system to help with that counting.
- I want to know how much I have counted. And I want to increment and decrement the counter.
- I had a bright red plastic counter.

- OOA: Object-Oriented Analysis
- What classes?
- What are the relationships between classes?
- What are the services and attributes of each?
- Goals:
- Aim for flexibility
- Aim for reusability
- OOA: What do we need?
- Nouns: Count(er)
- Services: incrementing, decrementing, reseting
- Attributes: value, resetValue

- OOA: Flexibility
- What if we want to count Integers in other bases?

- OOA: Flexibility and Reusability
- What if we want to count dates? sequences? letters?

- Note:
- Abstract Classes: Never create instances. Shared functionality only.
- Concrete Classes: Create instances
- OOD: Object-Oriented Design
- What do the services->methods do?
- Increment, Decrement, Reset
- Fill in the details
- Accessing instance variables
- Initializations
- OOP: Object-Oriented Programming
- Create the Count Class Definition
- Model subclass: #Count
- instanceVariableNames: 'value resetValue '
- classVariableNames: ''
- poolDictionaries: ''
- category: 'Counts'
- OOP: Accessing
- Count methodsFor: 'accessing'
- value
- value: aValue
- resetValue
- resetValue: aValue
- OOP: Counting Methods
- Count methodsFor: 'counting'
- decrement
- "Subclasses must implement"
- self subclassResponsibility
- increment
- "Subclasses must implement"
- self subclassResponsibility
- reset
- OOP: Initialization
- Count methodsFor: 'initialization'
- initialize
- Count class methodsFor: 'initialization'
- new
- | aCount |
- aCount := super new.
- aCount initialize.
- ^aCount
- Now, Creating the IntegerCount
- Count subclass: #IntegerCount
- instanceVariableNames: ''
- classVariableNames: ''
- poolDictionaries: ''
- category: 'Counts'
- IntegerCount methodsFor: 'counting'
- increment
- decrement
- asBase: radix
- ^value printStringBase: radix "printStringRadix: in VisualWorks"
- Finishing up IntegerCount
- IntegerCount methodsFor: 'initialization'
- initialize
- resetValue := 0.
- super initialize.
- Testing
- | aCount |
- aCount := IntegerCount new.
- aCount value: 10.
- Transcript cr; show: 'Current Value; ', aCount value printString.
- aCount increment. aCount increment.
- Transcript cr; show: 'Current Value: ', aCount value printString.
- aCount decrement.
- Transcript cr; show: 'Current Value: ', aCount value printString.
- aCount reset.
- Transcript cr; show: 'Current Value: ', aCount value printString.
- Testing Flexibility: Creating a DateCount

- Count subclass: #DateCount
- instanceVariableNames: ''
- classVariableNames: ''
- poolDictionaries: ''
- category: 'Counts'
- DateCount methodsFor: 'counting'
- decrement
- value := value subtractDays: 1.
- increment
- value := value addDays: 1.
- initialize
- resetValue := Date today.
- super initialize.
- Testing Reuse: Profit Calculation
- Imagine a counter at a gate (Airport, Six Flags)
- Profit is some percentage of the gate

- Question: Just talks-to or has-a?
- OOP: Profit
- Object subclass: #Profit
- instanceVariableNames: 'gateCount margin ' "Fixed it from the picture"
- classVariableNames: ''
- poolDictionaries: ''
- category: 'Counts' "Probably shouldn't be this"
- Profit methodsFor: 'calculate'
- initialize: aCount
- gateCount := aCount.
- margin := 0.25.
- total
- ^ margin * (gateCount value).
- Profit testing
- | profit aCount |
- profit := Profit new.
- aCount := IntegerCount new.
- profit initialize: aCount.
- 10 timesRepeat: [aCount increment].
- Transcript cr; show: 'Profit so-far: ', profit total printString.
Previous | Next
Last modified at 7/17/97; 2:59:55 PM
Other Links of Interest
College of Computing | EduTech Institute | GVU Center
Mark Guzdial | Papers | CS 2390 Spring '97 Home Page | STABLE | MMC-CaMILE
Slide Master