Here is the basics of what I'm doing for those of you that don't want to open the project from the file:
I basically have a set calendar items. Meals, workouts and measurements. They all have a date and a name and can print details. but other than that they have a few items they each need differently.
public enum AppointmentType
{
Workout,
Meal,
Measurement
}
public abstract class Appointment
{
public string Name { get; set; }
public DateTime DateStarted { get; set; }
public virtual string PrintDetails()
{
return string.Format("Type: {0}\nName: {1}\nDate: {2}",this.GetType().ToString(), Name, DateStarted.ToShortDateString());
}
}
public class Workout : Appointment
{
public List<string> Exercises { get; set; }
public Workout()
{
Exercises = new List<string>();
}
public override string PrintDetails()
{
string startInfo = base.PrintDetails();
string addedInfo = "\nToday I will be doing the following:\n";
foreach (string exercise in Exercises)
{
addedInfo += string.Format("{0}\n", exercise);
}
return startInfo + addedInfo;
}
}
public class Meal : Appointment
{
public List<string> FoodItems { get; set; }
public Meal()
{
FoodItems = new List<string>();
}
public override string PrintDetails()
{
string startInfo = base.PrintDetails();
string addedInfo = "\nToday I will be eating the following:\n";
foreach (string foodItem in FoodItems)
{
addedInfo += string.Format("{0}\n", foodItem);
}
return startInfo + addedInfo;
}
}
public class Measurement : Appointment
{
public string Height { get; set; }
public string Weight { get; set; }
public override string PrintDetails()
{
string startInfo = base.PrintDetails();
string addedInfo = string.Format("\nI am {0} feet tall and I weight {1} pounds!\n", Height, Weight);
return startInfo + addedInfo;
}
}
public interface IAppointmentFactory
{
Appointment CreateAppointment(AppointmentType appointmentType);
}
public class AppointmentFactory : IAppointmentFactory
{
public Appointment CreateAppointment(AppointmentType appointmentType)
{
switch (appointmentType)
{
case AppointmentType.Workout:
return new Workout();
case AppointmentType.Meal:
return new Meal();
case AppointmentType.Measurement:
return new Measurement();
default:
return new Workout();
}
}
}