1. Home
  2. /
  3. Smalltalk
  4. /
  5. Counter and Theme Toggle

Counter and Theme Toggle - Smalltalk Typing CST Test

Loading…

Counter and Theme Toggle — Smalltalk Code

Demonstrates a simple counter with theme toggling using Smalltalk objects and messages.

Object subclass: Counter [
	| count isDark |

	Counter class >> new [ ^ super new initialize ]

	initialize [
		count := 0.
		isDark := false.
		self updateUI.
	]

	updateUI [
		Transcript show: 'Counter: ', count printString; cr.
		Transcript show: 'Theme: ', (isDark ifTrue: ['Dark'] ifFalse: ['Light']); cr.
	]

	increment [ count := count + 1. self updateUI ]
	decrement [ count := count - 1. self updateUI ]
	reset [ count := 0. self updateUI ]
	toggleTheme [ isDark := isDark not. self updateUI ]
]

| counter |
counter := Counter new.
counter increment.
counter increment.
counter toggleTheme.
counter decrement.
counter reset.

Smalltalk Language Guide

Smalltalk is a dynamically typed, object-oriented programming language known for its pure object model, live environment, and influential role in the development of modern OOP concepts. Everything in Smalltalk is an object, including numbers, classes, and code blocks.

Primary Use Cases

  • ▸Educational programming for OOP concepts
  • ▸Rapid prototyping of applications
  • ▸GUI-based application development
  • ▸Dynamic systems with runtime object inspection
  • ▸Research in programming languages and software design
  • ▸Domain-specific languages and frameworks

Notable Features

  • ▸Pure object-oriented system
  • ▸Everything is an object
  • ▸Dynamic typing and reflection
  • ▸Live programming environment (image-based)
  • ▸Message passing paradigm

Origin & Creator

Smalltalk was created in the 1970s at Xerox PARC by Alan Kay, Dan Ingalls, Adele Goldberg, and others as part of the development of object-oriented programming and graphical user interfaces.

Industrial Note

Smalltalk has been widely used in educational environments, early GUI-based applications, research prototypes, and some enterprise applications requiring highly dynamic and reflective systems.

More Smalltalk Typing Exercises

Smalltalk Simple AdditionSmalltalk FactorialSmalltalk Fibonacci SequenceSmalltalk Max of Two NumbersSmalltalk Array SumSmalltalk Even Numbers FilterSmalltalk Conditional Counter IncrementSmalltalk Resettable CounterSmalltalk Theme Toggle Only

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher