Coming soon - Get a detailed view of why an account is flagged as spam!
view details

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.

8
My common-language rough-shamble understanding of when to hide methods and when to use "new" and when to use "virtual" and "override," and their differences
Post Body

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.

Author
Account Strength
100%
Account Age
15 years
Verified Email
Yes
Verified Flair
No
Total Karma
639,966
Link Karma
107,616
Comment Karma
529,103
Profile updated: 3 days ago
Posts updated: 3 months ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
2 years ago