This post originated from an RSS feed registered with Agile Buzz
by Keith Ray.
Original Post: OO - the Solution to the Problem of Switch Statements
Feed Title: MemoRanda
Feed URL: http://homepage.mac.com/1/homepage404ErrorPage.html
Feed Description: Keith Ray's notes to be remembered on agile software development, project management, oo programming, and other topics.
Dan Ingalls, principle designer of Smalltalk, with Alan Kay at Xerox Parc. This video was sponsored by Apple, recorded in 1989. In introducing OO (and Smalltalk in particular), he describes the main failing of non-object oriented languages in writing complex software: the switch statement. The switch statement has all sorts of problems with cohesion and coupling. The irony today is that almost all OO languages today, other than Python and Smalltalk (in which it can easily be implemented), still have switch statements.
In most cases, switch statements can be eliminated by either using the Replace Conditional with Polymorphism refactoring, or by using a Map or Dictionary to hold keys and objects (the objects could be blocks of code, "pointers to methods", or regular objects).
On another subject: a recent (still in Beta) full-fledged Smalltalk implementation for MacOS X, which allows Cocoa programming: Ambrai Smalltalk. Screenshots. Cocoa Tutorial