Tuesday, December 28, 2010

Combining Abstract Classes and Interfaces

I've been continuing to work with my GUI classes in XNA. I'm in the process of remodeling the base class to make things more extensible and customizable. I use an abstract base class Control that all controls inherit from so they can be iterated over easily. I also have a class that can manage all of the controls that are present on the screen. I started experimenting with combining the base class with interfaces. I'm pleased with the results. I created a number of interfaces for different types of controls that can be used to extend the abstract base class providing a well defined public interface for accessing the controls. So now the base class Control has just two fields exposed by properties.

public abstract class Control
{
   #region Field Region
   string name;
   object tag;