質問

From MSDN: Abstract Class Design:

X DO NOT define public or protected internal constructors in abstract types.

√ DO define a protected or an internal constructor in abstract classes.

Is there contradiction here? Or does it mean that constructor should be or protected or internal but not protected and internal at the same time?

役に立ちましたか?

解決

Yes, it does mean that a constructor should not be protected and internal at the same time, but either protected or internal is ok. Protected (and) internal is as misleading as public because constructors of abstract classes can only be called from inheritors.
A single protected or internal make a difference as they allow a different range of inheritors (internal allows only inheritors from the current assembly, protected allows any inheritor). But public extends the accessibility over the range an abstract class can provide by its nature. Protected internal does nothing more than a single protected for an abstract class.
That's why they are misleading.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top