Objects, Abstract Class or Interface?
-
I'm trying to get my head around objects and am asking for thoughts on this idea. If for example I were to implement a Person Object, there may be differnt Person objects representing people of different cultures. All Person objects have similar characteristics, ie Height, Weight, Age ect but I imagine that there could be a method ie SayHello which Person objects of different cultures would implement differently. Now what i'm trying to figure out is whether the Person Class should be abstract to cope with different cultures or whether I should create an interface or both. Thoughts and comments appreciated. Regards Wayne Phipps ____________ Time is the greatest teacher... unfortunately, it kills all of its students LearnVisualStudio.Net
-
I'm trying to get my head around objects and am asking for thoughts on this idea. If for example I were to implement a Person Object, there may be differnt Person objects representing people of different cultures. All Person objects have similar characteristics, ie Height, Weight, Age ect but I imagine that there could be a method ie SayHello which Person objects of different cultures would implement differently. Now what i'm trying to figure out is whether the Person Class should be abstract to cope with different cultures or whether I should create an interface or both. Thoughts and comments appreciated. Regards Wayne Phipps ____________ Time is the greatest teacher... unfortunately, it kills all of its students LearnVisualStudio.Net
Although you could implement it with interfaces, a simple virtual method for SayHello, or other methods, would be simplier.
-
I'm trying to get my head around objects and am asking for thoughts on this idea. If for example I were to implement a Person Object, there may be differnt Person objects representing people of different cultures. All Person objects have similar characteristics, ie Height, Weight, Age ect but I imagine that there could be a method ie SayHello which Person objects of different cultures would implement differently. Now what i'm trying to figure out is whether the Person Class should be abstract to cope with different cultures or whether I should create an interface or both. Thoughts and comments appreciated. Regards Wayne Phipps ____________ Time is the greatest teacher... unfortunately, it kills all of its students LearnVisualStudio.Net
Hello I don't think there are any requirements for using interface in your case. You can create your base
Person
class, with a virtualSayHello
method. You can provide it with default realization (may the person can greet you on some kind of default language of human being saying "Mmmm" :-D or with some other action). Then, any other class, which will inherit your base class, can override the method. Or you can make the method abstract to make it obligate to provide realization of the method. With best regards, Andrew -
I'm trying to get my head around objects and am asking for thoughts on this idea. If for example I were to implement a Person Object, there may be differnt Person objects representing people of different cultures. All Person objects have similar characteristics, ie Height, Weight, Age ect but I imagine that there could be a method ie SayHello which Person objects of different cultures would implement differently. Now what i'm trying to figure out is whether the Person Class should be abstract to cope with different cultures or whether I should create an interface or both. Thoughts and comments appreciated. Regards Wayne Phipps ____________ Time is the greatest teacher... unfortunately, it kills all of its students LearnVisualStudio.Net
-
Hello I don't think there are any requirements for using interface in your case. You can create your base
Person
class, with a virtualSayHello
method. You can provide it with default realization (may the person can greet you on some kind of default language of human being saying "Mmmm" :-D or with some other action). Then, any other class, which will inherit your base class, can override the method. Or you can make the method abstract to make it obligate to provide realization of the method. With best regards, AndrewWhy make the
SayHello
method virtual? Could you noy just Override the method in the derrived class? I understand that making it abstract forces the derrived class to implement the method in its own way but again, could this not also be achieved by Overriding the inherited method? Is there a benefit or forefeit to either approach? Regards Wayne Phipps ____________ Time is the greatest teacher... unfortunately, it kills all of its students LearnVisualStudio.Net -
Why make the
SayHello
method virtual? Could you noy just Override the method in the derrived class? I understand that making it abstract forces the derrived class to implement the method in its own way but again, could this not also be achieved by Overriding the inherited method? Is there a benefit or forefeit to either approach? Regards Wayne Phipps ____________ Time is the greatest teacher... unfortunately, it kills all of its students LearnVisualStudio.Net -
Hello I don't think there are any requirements for using interface in your case. You can create your base
Person
class, with a virtualSayHello
method. You can provide it with default realization (may the person can greet you on some kind of default language of human being saying "Mmmm" :-D or with some other action). Then, any other class, which will inherit your base class, can override the method. Or you can make the method abstract to make it obligate to provide realization of the method. With best regards, AndrewI agree with Andrew, I think that would be the best way to solve this requirement. You can override the method of sayhello of base class and implement it in the child class Regards, Jaiprakash M Bankolli