Special

Introducing the “Welcome to Xojo” Bundle!

New to Xojo and looking for guidance? We've put together a terrific bundle to welcome you! Xojo Bundle

This bundle includes six back issues of the magazine -- all of year 21 in printed book and digital formats -- plus a one-year subscription (beginning with 22.1) so you'll be learning all about Xojo for the next year. It's the perfect way to get started programming with Xojo. And you save as much as $35 over the non-bundle price!

This offer is only available for a limited time as supplies are limited, so hurry today and order this special bundle before the offer goes away!

Article Preview


Buy Now

Issue 1.6

COLUMN

Double Dispatch

Better Design Through Indirection

Issue: 1.6 (June/July 2003)
Author: Charles Yeomans
Author Bio: Charles Yeomans is a software developer in Lexington, Kentucky.
Article Description: No description available.
Article Length (in bytes): 5,479
Starting Page Number: 36
Article Number: 1618
Resource File(s):

Download Icon 1618.zip Updated: 2013-03-11 19:07:56

Related Link(s): None

Excerpt of article text...

You're writing a spaceship game in which ships of various types collide. Let's suppose that the game currently has three types of ships: ShipA, ShipB, and ShipC, all of which inherit from a common abstract class SpaceShip. SpaceShip has an abstract function CollideWith(ship as SpaceShip) as CollisionOutcome. How do you implement ShipA, ShipB, and ShipC?

It's immediately clear that there are six possible collisions, and it's certainly possible that the code in each situation will be quite different. Our first step will be to move collision resolution into its own class, SpaceshipCollisionResolver, and give it a single method, Resolve, that we'll overload to handle all possible cases.

...End of Excerpt. Please purchase the magazine to read the full article.