This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
I was having a hard time grasping the different behavior.
edit: I still didn't understand and the below is incorrect. See comments.
If you make a new method and hide the parent method, when you directly call it, it will work as you expect.
However, it will not be called by other methods which are inside the parent class.
Here's an example of a mistake:
Cow : Animal
Cows have a lot of stomachs and have to chew cud. Say you set a special digestion method for your cow. But it’s hidden. You tell your animal (which is a cow) to eat. Eat() is a method of the base class, which involves biting, swallowing, digesting and queuing poop. But because the method for digestion is hidden, it’ll use the base animal class for digestion. Therefore you should have overridden digest() in that case.
There may be a case where you want to use the standard behavior for most things, but the special behavior for others. AI thought of an example: People have a standard greeting “Hello!” that they use with each other. Your person has a catch-phrase “HOWDY-DOO!” that he uses as a greeting. But when he meets someone for the first time, he should say “Hello, nice to meet you.” So his greeting is new, hiding the standard greeting, but he uses the standard greeting in any other method.
However I think a lot of people would prefer that you create a new field for "catch-phrase" and different methods for greeting and still avoid using hiding.
Subreddit
Post Details
- Posted
- 2 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/learncsharp...