I have searched through the numerous S/O postings and have not found an answer that helps me.
I would like to get a mental vision of what is an abstract class and what is an interface. I have read through this post Real world abstract class usage simple samples, but I am still not clear about the concepts.
I am hoping someone can describe a real world in the form of an “Person” object.
So inheritance would be “Person” –> “Employee” –> “Manager”
And Overriding would be “Employee’s Salary” would become “Sales employee commission”
How can I describe an abstract class and an interface within a Person object concept?
There are different views on the subject of using an interface versus abstract class. An interface, though, should express the behavior of an object (what it can do) and the abstract class should define what it is. Basically “I can” versus “I am” from the object’s persepective.
So, if we have a Person, that is a noun and so we’ll use an abstract class to define it. Any thing that “is a” Person will inherit from that class. If we want to define some behaviour that describes some behavior that the Person is capable of that doesn’t extend to all Persons, we should put that into an interface.
Using the relationship that you defined (Person -> Employee -> Manager), we can say that the Employee implements IFirable and the Manager implements IFirer. The employee can be fired, and the manager can fire an employee.