Relative Content

Tag Archive for polymorphism

How do I cleanly keep track of the type of various objects implementing a common interface without reflection?

In my multiplayer game I have an inventory package that acts as a facade over a lower-level package. To abide by the Open-Closed Principle, I have a class for each inventory action, like PlaceAirplaneCommand and TurboTerminalCommand that extends the abstract InventoryItem with abstract classes in between that group these commands together. I then polymorphically call use() or lose() on the InventoryItem abstract class in my Inventory class which is the public API for the higher-level packages.

How do I identify the type of object without reflection in a game inventory system?

In my multiplayer game I have an inventory package that acts as a facade over a lower-level package. To abide by the Open-Closed Principle, I have a class for each inventory action, like PlaceRouteCommand and TurboTerminalCommand that extends the abstract InventoryItem with abstract classes in between that group these commands together. I then polymorphically call use() or lose() on the InventoryItem abstract class in my Inventory class which is the public API for the higher-level packages.

Does C++ support subtyping?

I know it might be a silly question to ask, but I didn’t quite get an a absolute clear answer on this matter, so I thought I’d put it here.

How would I handle a set of differing event classes with differing handler interfaces in a single event processor?

I’m working on an event processor framework for a simple game I’m writing, in which multiple types of events are handled in a loop. Since these events carry distinct pieces of data (i.e. one carries a player and position, another carries a message and timestamp), I ended up creating different classes for them (though they still all implement a common interface, which is currently a marker interface).

How would I handle a set of differing event classes with differing handler interfaces in a single event processor?

I’m working on an event processor framework for a simple game I’m writing, in which multiple types of events are handled in a loop. Since these events carry distinct pieces of data (i.e. one carries a player and position, another carries a message and timestamp), I ended up creating different classes for them (though they still all implement a common interface, which is currently a marker interface).