Encapsulate Public Field

Flags publicly exposed instance fields.

Reasoning

Instance fields are the implementation details of a object's internal state; exposing them directly breaks encapsulation. Often, an object only needs to expose a 'Get' procedure to expose an internal instance field.

Default severity

Suggestion

Inspection type

NamingAndConventionsIssues

Examples

This example should trigger a result

MyModule (StandardModule)
Public Foo As Long

This example should NOT trigger a result

MyModule (StandardModule)
Private internalFoo As Long Public Property Get Foo() As Long Foo = internalFoo End Property

Rubberduck.CodeAnalysis.Inspections.Concrete.EncapsulatePublicFieldInspection.cs (Prerelease-v2.5.9.6289)