Will the functions you add change the definition of what the class is, or will you simply be creating functions to manipulate data that is already a part of the class?
If you need to redefine aspects of the base class of these two classes then yes, you will need to change your inheritance structure. But if the functions will simply manipulate data that is already part of the class now then I would suggest you use the interface and create utility functions.
Here is a clumsy example of what I mean:
using System;
abstract class Pet { }
class Dog : Pet, IPet
{
public String Name { get; set; }
public Int32 Age { get; set; }
}
class Cat : Pet, IPet
{
public String Name { get; set; }
public Int32 Age { get; set; }
}
interface IPet
{
String Name { get; set; }
Int32 Age { get; set; }
}
static class PetUtils
{
public static void Print(this IPet pet)
{
Console.WriteLine(pet.Name + " is " + pet.Age);
}
}
Your two UI classes are perhaps related in this way. I would imagine that what you need to do in a cross-cutting fashion would be solved by a utility method like the one I have created. I did create the PetUtils.Print
method as an extension method as this will create the expressive illusion of an instance method. If you are not using C# 3 just remove "this
" from public static void Print(this IPet pet)
.