
Inline adoc files when they are included exactly once. Also fix language tags because this inlining gives us better information on what language the code is written in.
65 lines
1.6 KiB
Plaintext
65 lines
1.6 KiB
Plaintext
== Why is this an issue?
|
|
|
|
Since `abstract` classes can't be instantiated, there's no point in their having `public` or `internal` constructors. If there is basic initialization logic that should run when an extending class instance is created, you can by all means put it in a constructor, but make that constructor `private`, `private protected` or `protected`.
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,csharp]
|
|
----
|
|
abstract class Base
|
|
{
|
|
public Base() // Noncompliant, should be private, private protected or protected
|
|
{
|
|
//...
|
|
}
|
|
}
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,csharp]
|
|
----
|
|
abstract class Base
|
|
{
|
|
protected Base()
|
|
{
|
|
//...
|
|
}
|
|
}
|
|
----
|
|
|
|
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
Reduce the visibility of this constructor.
|
|
|
|
|
|
=== Highlighting
|
|
|
|
``++public++`` keyword
|
|
|
|
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
=== on 8 Dec 2015, 08:48:44 Tamas Vajk wrote:
|
|
\[~ann.campbell.2] LGTM, changed the label from api-design to clumsy. The constructor can't be called directly, because it's in an ``++abstract++`` class. So we can only call it from a deriving type's constructor, but this is also the case if the constructor is ``++protected++``, so we are not proposing any real change in api-design. WDYT?
|
|
|
|
=== on 12 Apr 2016, 17:56:27 Ann Campbell wrote:
|
|
Rule originally taken from R#, but also exists in MSFT Roslyn rule set & therefore doesn't need re-implementation.
|
|
|
|
=== on 26 Jan 2017, 16:49:21 Ann Campbell wrote:
|
|
https://msdn.microsoft.com/en-us/library/ms182126.aspx
|
|
|
|
endif::env-github,rspecator-view[]
|