rspec/rules/S3442/csharp/rule.adoc
2022-02-04 16:28:24 +00:00

49 lines
932 B
Plaintext

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)
include::message.adoc[]
include::highlighting.adoc[]
'''
== Comments And Links
(visible only on this page)
include::comments-and-links.adoc[]
endif::env-github,rspecator-view[]