Avoid using a public contructor for an abstract class

이 페이지는 아직 한국어로 제공되지 않으며 번역 작업 중입니다. 번역에 관한 질문이나 의견이 있으시면 언제든지 저희에게 연락해 주십시오.

Metadata

ID: csharp-best-practices/public-abstract-constructors

Language: C#

Severity: Notice

Category: Best Practices

Description

Using an abstract modifier in a class declaration indicates that a class is intended only to be a base class of other classes and not instantiated by itself. Due to this, there is no need for public or internal constructors within. Any initialization logic should be added in a private,private protected, or protected constructor.

Non-Compliant Code Examples

abstract class Foo
{
    internal Foo()
    {
      //...
    }
}
abstract class Foo
{
    public Foo()
    {
      //...
    }
}

Compliant Code Examples

abstract class Foo
{
    private protected Foo()
    {
      //...
    }
}
abstract class Foo
{
    private Foo()
    {
      //...
    }
}
abstract class Foo
{
    protected Foo()
    {
      //...
    }
}
https://static.datadoghq.com/static/images/logos/github_avatar.svg https://static.datadoghq.com/static/images/logos/vscode_avatar.svg jetbrains

Seamless integrations. Try Datadog Code Analysis

PREVIEWING: esther/docs-9518-update-example-control-sensitive-log-data