S
sloan
Here is one I've been tinkering around with for a few days.
Given the bottom 2 classes and one interface. (at the very bottom)
Is there a way to represent
EmployeeCollection : List<IEmployee>
as an interface?
as in, I'd like to have:
public class EmployeeCollection : IEmployeeCollection
{}
but is still just a
List<IEmployee>
Does that make sense?
I tried this:
public interface IEmployeeCollection :
System.Collections.Generic.IEnumerable<IEmployee>
{}
but that really didn't do it.
To say it another way, I'd like to be able to use an IEmployeeCollection, in
place of the concrete EmployeeCollection.
as in:
IEmployeeCollection icoll = new EmployeeCollection();
and have methods like
icoll.Add ( new Employee ) ;
or
IEmployee ie = new Employee( //constructor params here //);
icoll.Add ( ie ) ;
......................
Here's my code samples:
....................
[Serializable]
public class EmployeeCollection : List<IEmployee>
{
public EmployeeCollection()
{
System.Console.WriteLine("New EmployeeCollection has been created.");
}
}
public interface IEmployee
{
Guid EmployeeUUID { get; }
string LastName { get; }
string FirstName { get; }
DateTime HireDate { get; }
}
[Serializable]
public class Employee : IEmployee
{
private Guid _employeeUUID ;
private string _lastName = string.Empty;
private string _firstName = string.Empty;
private DateTime _hireDate = DateTime.MinValue; //yes a nullable would be
better here, just demo code
private Employee() {} //unnecessary, but a placeholder
public Employee(System.Guid empUUID , string firstName, string lastName,
DateTime hireDate)
{
this._employeeUUID = empUUID;
this.FirstName = firstName;
this.LastName = lastName;
this.HireDate = hireDate;
}
#region IEmployee Members
public Guid EmployeeUUID
{
get { return _employeeUUID; }
set { this._employeeUUID = value; }
}
public string LastName
{
get { return _lastName; }
set { this._lastName = value; }
}
public string FirstName
{
get { return _firstName; }
set { this._firstName = value; }
}
public DateTime HireDate
{
get { return _hireDate; }
set { this._hireDate = value; }
}
#endregion
}
Given the bottom 2 classes and one interface. (at the very bottom)
Is there a way to represent
EmployeeCollection : List<IEmployee>
as an interface?
as in, I'd like to have:
public class EmployeeCollection : IEmployeeCollection
{}
but is still just a
List<IEmployee>
Does that make sense?
I tried this:
public interface IEmployeeCollection :
System.Collections.Generic.IEnumerable<IEmployee>
{}
but that really didn't do it.
To say it another way, I'd like to be able to use an IEmployeeCollection, in
place of the concrete EmployeeCollection.
as in:
IEmployeeCollection icoll = new EmployeeCollection();
and have methods like
icoll.Add ( new Employee ) ;
or
IEmployee ie = new Employee( //constructor params here //);
icoll.Add ( ie ) ;
......................
Here's my code samples:
....................
[Serializable]
public class EmployeeCollection : List<IEmployee>
{
public EmployeeCollection()
{
System.Console.WriteLine("New EmployeeCollection has been created.");
}
}
public interface IEmployee
{
Guid EmployeeUUID { get; }
string LastName { get; }
string FirstName { get; }
DateTime HireDate { get; }
}
[Serializable]
public class Employee : IEmployee
{
private Guid _employeeUUID ;
private string _lastName = string.Empty;
private string _firstName = string.Empty;
private DateTime _hireDate = DateTime.MinValue; //yes a nullable would be
better here, just demo code
private Employee() {} //unnecessary, but a placeholder
public Employee(System.Guid empUUID , string firstName, string lastName,
DateTime hireDate)
{
this._employeeUUID = empUUID;
this.FirstName = firstName;
this.LastName = lastName;
this.HireDate = hireDate;
}
#region IEmployee Members
public Guid EmployeeUUID
{
get { return _employeeUUID; }
set { this._employeeUUID = value; }
}
public string LastName
{
get { return _lastName; }
set { this._lastName = value; }
}
public string FirstName
{
get { return _firstName; }
set { this._firstName = value; }
}
public DateTime HireDate
{
get { return _hireDate; }
set { this._hireDate = value; }
}
#endregion
}