rspec/rules/S3442/csharp/rule.adoc

30 lines
608 B
Plaintext
Raw Normal View History

2021-04-28 16:49:39 +02:00
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++`` or ``++protected++``.
2021-04-28 16:49:39 +02:00
== Noncompliant Code Example
----
abstract class Base
{
public Base() // Noncompliant, should be private or protected
{
//...
}
}
----
2021-04-28 16:49:39 +02:00
== Compliant Solution
----
abstract class Base
{
protected Base()
{
//...
}
}
----