Hare Krishna, Hi,
I wanted to know if C# has a facility whereby i can define one single implementation for a method that is used by two different classes in two different class heirarchies? Now let me illustrate the problem with an example.
I have got a 'cat' class and a 'dog' class:
The implementation for the 'eat' method is exactly the same for both classes. Hence, I would like to define the 'eat' method at any one place so that maintenance of the code will be easy. But the 'eat' method must be usable by both classes. How can i accomplish this feat in C#?
I wanted to know if C# has a facility whereby i can define one single implementation for a method that is used by two different classes in two different class heirarchies? Now let me illustrate the problem with an example.
I have got a 'cat' class and a 'dog' class:
Code:
public class Cat : Feline { void eat(food f) { //procedure for eating food } } public class Dog : Canine { void eat(food f) { //procedure for eating food } }
Comment