Skip to content

Commit

Permalink
Rephrased based on feedback (dennisdoomen#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
bkoelman authored and mapfel committed Mar 22, 2021
1 parent 055c029 commit 2482470
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Src/Cheatsheet/Cheatsheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ NOTE: Requires Markdown Extra. See http://michelf.ca/projects/php-markdown/extra
* A class or interface should have a single purpose (AV1000)
* An interface should be small and focused (AV1003)
* Use an interface to decouple classes from each other (AV1005)
* Don’t hide inherited members with the `new` keyword (AV1010)
* Don't suppress compiler warnings using the new keyword (AV1010)
* It should be possible to treat a derived object as if it were a base class object (AV1011)
* Don’t refer to derived classes from the base class (AV1013)
* Avoid exposing the objects an object depends on (AV1014)
Expand Down
5 changes: 3 additions & 2 deletions Src/Guidelines/1000_ClassDesignGuidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ With the exception of extension method containers, static classes very often lea

**Note:** If you really need that static class, mark it as static so that the compiler can prevent instance members and instantiating your class. This relieves you of creating an explicit private constructor.

### <a name="av1010"></a> Don't hide inherited members with the new keyword (AV1010) ![](images/1.png)
### <a name="av1010"></a> Don't suppress compiler warnings using the new keyword (AV1010) ![](images/1.png)

Not only does the new keyword break [Polymorphism](http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming), one of the most essential object-orientation principles, it also makes sub-classes more difficult to understand. Consider the following two classes:
Compiler warning [CS0114](https://docs.microsoft.com/en-us/dotnet/csharp/misc/cs0114) is issued when breaking [Polymorphism](http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming), one of the most essential object-orientation principles.
The warning goes away when you add the `new` keyword, but it keeps sub-classes difficult to understand. Consider the following two classes:

public class Book
{
Expand Down

0 comments on commit 2482470

Please sign in to comment.