Excuse the poor title, couldn't quite explain my issue in as few words. I'm trying to make a simple calendar app within some rough guidelines I've been given which have led me this far.
I have a class called Apts, inheriting from an interface IApts, which itself inherits from another interface IApt. My code is as follows:
IApt
public interface IApt
{
DateTime Start { get; }
int Length { get; }
string Description{ get; }
bool Occurs(DateTime date);
}
IApts
public interface IApts : IList<IApt>
{
bool Load();
bool Save();
IEnumerable<IApt> GetAptsOnDate(DateTime date);
}
Apts (Cut down to the minimum of course)
class Apts: IApts
{
public List<IApt> myAppointments = new List<IApt>();
public Apts()
{
// Constructor must be empty - guideliness
}
public bool Load()
{
//Code to load appointment data from file to variables below
string startTime = x;
string lengthTime = y;
string description = z;
IApt loadedAppointment = new IApt(aptStartDate, aptLength, aptDescription);
myAppointments.Add(loadedAppointment);
}
#IList Methods
#IEnumerable Methods
}
Hopefully my code snippets give you the idea of what I'm trying to achieve here. I will create an instance of the Apts class from my mainForm in order to hold all of my appointments as follows:
IApts _Appointments = new Apts();
I want to do 2 things now. I want to add items from my mainForm of type IApt (Is this even possible? :S). I also want my Load() method to be able to be called from my mainForm once I've created the instance in order to populate the list myAppointments with appointments whose contents will come from a simple text file storage.
Could someone advise me if what I'm trying to do is even possible? Everything else is in place, I just need to be able to access thelist which is created when I create the instance of Apts and to add objects to it of type IApt.
OR would it make sense to create another class, perhaps named Apt because creating a new object of type Apts would be creating another list..? I'm hoping someone is following me heh.. My head is spinning!
public interface IApt
{
DateTime Start { set;get; }
int Length { set;get; }
string Description{ set;get; }
bool Occurs(DateTime date);
}
Add this property to the interface IApts
List<IApt> myAppointments {set;get;}
Implement this interface eg:
public class Apt : IApt
{
public DateTime Start { set;get; }
public int Length { set;get; }
public string Description{ set;get; }
public bool Occurs(DateTime date){
}
}
Then
IApts _Appointments = new Apts();
IApt apt = new Apt();
apt.Start=...
apt.Length=...
_Appointments.myAppointments.Add(apt);
_Appointments.Load();
Don't want to pass judgement on your naming conventions as long as they stay the same through out the code but public members are normally UpperCamelCase and private are either prefixed with _lowerCamelCase or lowerCamelCase.