Rubberduck: Wrap fields in private type

Created on 17 Dec 2015  路  4Comments  路  Source: rubberduck-vba/Rubberduck

A module usually has its fields this way:

Private mFoo As Integer
Private mBar As Integer

Public Property Get Foo() As Integer
    Foo = mFoo
End Property

Public Property Get Bar() As Integer
    Bar = mBar
End Property

That works, but I prefer this:

Private Type TClassName
    Foo As Integer
    Bar As Integer
End Type

Private this As TClassName

Public Property Get Foo() As Integer
    Foo = this.Foo
End Property

Public Property Get Bar() As Integer
    Bar = this.Bar
End Property

Wrapping the private fields in a private type like this, eliminates the need for prefixes and makes the code cleaner, leaving only a single field in the class, which I like to name this.

Could be just me though. Thoughts?

difficulty-03-duck enhancement feature-refactorings up-for-grabs

Most helpful comment

I have a rewrite of the EncapsulateFieldRefactoring which will support encapsulation of 1 to n Fields using individual backing fields or wrapped in a Private Type. So, the PR addresses this issue, #2582, and would be considered partial progress regarding the discussion threads of #4805, #4985, #2232.

I know right now the focus is on v2.5 (and I would not expect this PR to make 'the cut' for v2.5). So, the question is: does it makes sense to create this PR as WIP or would it be best to wait until v2.5 is released? (not sure what the migration to VS2019 entails) I was thinking some degree of comment and review would be helpful to me at this point - but did not want to move forward if it would just be 'in the way' or a distraction. I would say I'm at about 90% ready to generate the PR.

All 4 comments

Do it!!!

I have a rewrite of the EncapsulateFieldRefactoring which will support encapsulation of 1 to n Fields using individual backing fields or wrapped in a Private Type. So, the PR addresses this issue, #2582, and would be considered partial progress regarding the discussion threads of #4805, #4985, #2232.

I know right now the focus is on v2.5 (and I would not expect this PR to make 'the cut' for v2.5). So, the question is: does it makes sense to create this PR as WIP or would it be best to wait until v2.5 is released? (not sure what the migration to VS2019 entails) I was thinking some degree of comment and review would be helpful to me at this point - but did not want to move forward if it would just be 'in the way' or a distraction. I would say I'm at about 90% ready to generate the PR.

WIP is fine, I like how it gives others visibility on who's doing what!

Knowing, even at a guestimate, gives me goosebumps that this is coming to a rubber ducky we all know, use, and love.

Was this page helpful?
0 / 5 - 0 ratings