我正在阅读这里创建类工厂:https : //rubberduckvba.wordpress.com/2018/04/24/factories-parameterized-object-initialization/我很困惑为什么他们将实现的函数设为私有,不会我们希望它们是公开的,以便我们可以访问它们?
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "Something"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Type TSomething
Bar As Long
Ducky As String
End Type
Private this As TSomething
Implements ISomething
Public Function Create(ByVal initialBar As Long, ByVal initialDucky As String) As ISomething
With New Something
.Bar = initialBar
.Ducky = initialDucky
Set Create = .Self
End With …Run Code Online (Sandbox Code Playgroud)