Let's assume I have the following Abstract Class Student:
public abstract class Student
{
public string studentID {get; private set;}
public string FirstName {get; private set;}
public string lastname {get; private set;}
public int age {get; private set;}
public Student(string id,string firstname, string lastname, int age)
{
this.FirstName = firstname;
this.lastname = lastname;
this.age = age;
}
public abstract void calculatePayment();
}
and the following sub-class:
public class InternationalStudent:Student
{
public bool inviteOrientation {get; private set;}
public InternationalStudent(string interID,string first, string last, int age, bool inviteOrientation)
:base(interID,first,last,age)
{
this.inviteOrientation = inviteOrientation;
}
public override void calculatePayment()
{
//implementation left out
}
}
Main
InternationalStudent svetlana = new InternationalStudent("Inter-100""Svetlana","Rosemond",22,true);
InternationalStudent checkEq = new InternationalStudent("Inter-101","Trisha","Rosemond",22,true);
Question:
How would I properly implement my equalsTo method inside my subclass? I've been reading here but I'm confused because some answers indicate that a subclass shouldn't know the members of the parent class.
If I wanted to implement IEquality in a subclass, so that svetlana.Equals(checkEq);
returns false, how would I go it?
As per the comments what makes the object equals is if the ID, First name, and Last name are the same.