views:

87

answers:

3
A: 

I am not sure if this is a solution to your problem, but what if you had an abstract class do the basic work of looping through the entities, and then have classes extend the abstract class, and these child class would then do the more specific things. Then, runtime, you could supply to the variable of the abstract class type actual classes, based on the (user's?) specific needs.

A: 

You may first want to sperate you game entities into different classes so that each class/entity contains its own code and knows how to process it self. See http://en.wikipedia.org/wiki/Factory_method_pattern

Instead of using if/switch statements to determine what entitiy it is you could look at using Reflection. Or take it a step further and using some IoC container such as http://www.springframework.net/ this will be a step learning curve and probably overkill for now. but definatlly worth reading and learning more about.

Daveo
+3  A: 

Declare an interface with methods that the looping code calls, then supply the looping code with different implementations of the interface depending on what you need it do to.

This is commonly referred to as the Template Method Pattern

ChrisH