Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1e0fdc9

Browse files
authored
Add files via upload
1 parent efbe88f commit 1e0fdc9

File tree

4 files changed

+300
-0
lines changed

4 files changed

+300
-0
lines changed

BuilderPattern/IUser.cls

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
VERSION 1.0 CLASS
2+
BEGIN
3+
MultiUse = -1 'True
4+
END
5+
Attribute VB_Name = "IUser"
6+
Attribute VB_GlobalNameSpace = False
7+
Attribute VB_Creatable = False
8+
Attribute VB_PredeclaredId = False
9+
Attribute VB_Exposed = False
10+
Option Explicit
11+
12+
'@Folder("VBAProject")
13+
'@Interface
14+
15+
Public Property Get Id() As String
16+
End Property
17+
18+
Public Property Get UserName() As String
19+
End Property
20+
21+
Public Property Get FirstName() As String
22+
End Property
23+
24+
Public Property Get LastName() As String
25+
End Property
26+
27+
Public Property Get Email() As String
28+
End Property
29+
30+
Public Property Get EmailVerified() As Boolean
31+
End Property
32+
33+
Public Property Get TwoFactorEnabled() As Boolean
34+
End Property
35+
36+
Public Property Get PhoneNumber() As String
37+
End Property
38+
39+
Public Property Get PhoneNumberVerified() As Boolean
40+
End Property
41+
42+
Public Property Get AvatarUrl() As String
43+
End Property
44+

BuilderPattern/IUserBuilder.cls

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
VERSION 1.0 CLASS
2+
BEGIN
3+
MultiUse = -1 'True
4+
END
5+
Attribute VB_Name = "IUserBuilder"
6+
Attribute VB_GlobalNameSpace = False
7+
Attribute VB_Creatable = False
8+
Attribute VB_PredeclaredId = False
9+
Attribute VB_Exposed = False
10+
Attribute VB_Description = "Incrementally builds a User instance."
11+
'@Interface
12+
'@ModuleDescription("Incrementally builds a User instance.")
13+
Option Explicit
14+
15+
'@Description("Returns the current object.")
16+
Public Function Build() As IUser
17+
Attribute Build.VB_Description = "Returns the current object."
18+
End Function
19+
20+
'@Description("Builds a user with a first and last name.")
21+
Public Function WithName(ByVal FirstName As String, ByVal LastName As String) As IUserBuilder
22+
Attribute WithName.VB_Description = "Builds a user with a first and last name."
23+
End Function
24+
25+
'@Description("Builds a user with an email address.")
26+
Public Function WithEmail(ByVal Email As String, Optional ByVal Verified As Boolean = False) As IUserBuilder
27+
Attribute WithEmail.VB_Description = "Builds a user with an email address."
28+
End Function
29+
30+
'@Description("Builds a user with SMS-based 2FA enabled.")
31+
Public Function WithTwoFactorAuthentication(ByVal PhoneNumber As String, Optional ByVal Verified As Boolean = False) As IUserBuilder
32+
Attribute WithTwoFactorAuthentication.VB_Description = "Builds a user with SMS-based 2FA enabled."
33+
End Function
34+
35+
'@Description("Builds a user with an avatar at the specified URL.")
36+
Public Function WithAvatar(ByVal Url As String) As IUserBuilder
37+
Attribute WithAvatar.VB_Description = "Builds a user with an avatar at the specified URL."
38+
End Function

BuilderPattern/User.cls

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
VERSION 1.0 CLASS
2+
BEGIN
3+
MultiUse = -1 'True
4+
END
5+
Attribute VB_Name = "User"
6+
Attribute VB_GlobalNameSpace = False
7+
Attribute VB_Creatable = False
8+
Attribute VB_PredeclaredId = False
9+
Attribute VB_Exposed = False
10+
'@Folder("VBAProject")
11+
12+
Option Explicit
13+
Implements IUser
14+
15+
Private Type TUser
16+
Id As String
17+
UserName As String
18+
FirstName As String
19+
LastName As String
20+
Email As String
21+
EmailVerified As Boolean
22+
TwoFactorEnabled As Boolean
23+
PhoneNumber As String
24+
PhoneNumberVerified As Boolean
25+
AvatarUrl As String
26+
End Type
27+
28+
Private this As TUser
29+
30+
Public Property Get Id() As String
31+
Id = this.Id
32+
End Property
33+
34+
Public Property Let Id(ByVal value As String)
35+
this.Id = value
36+
End Property
37+
38+
Public Property Get UserName() As String
39+
UserName = this.UserName
40+
End Property
41+
42+
Public Property Let UserName(ByVal value As String)
43+
this.UserName = value
44+
End Property
45+
46+
Public Property Get FirstName() As String
47+
FirstName = this.FirstName
48+
End Property
49+
50+
Public Property Let FirstName(ByVal value As String)
51+
this.FirstName = value
52+
End Property
53+
54+
Public Property Get LastName() As String
55+
LastName = this.LastName
56+
End Property
57+
58+
Public Property Let LastName(ByVal value As String)
59+
this.LastName = value
60+
End Property
61+
62+
Public Property Get Email() As String
63+
Email = this.Email
64+
End Property
65+
66+
Public Property Let Email(ByVal value As String)
67+
this.Email = value
68+
End Property
69+
70+
Public Property Get EmailVerified() As Boolean
71+
EmailVerified = this.EmailVerified
72+
End Property
73+
74+
Public Property Let EmailVerified(ByVal value As Boolean)
75+
this.EmailVerified = value
76+
End Property
77+
78+
Public Property Get TwoFactorEnabled() As Boolean
79+
TwoFactorEnabled = this.TwoFactorEnabled
80+
End Property
81+
82+
Public Property Let TwoFactorEnabled(ByVal value As Boolean)
83+
this.TwoFactorEnabled = value
84+
End Property
85+
86+
Public Property Get PhoneNumber() As String
87+
PhoneNumber = this.PhoneNumber
88+
End Property
89+
90+
Public Property Let PhoneNumber(ByVal value As String)
91+
this.PhoneNumber = value
92+
End Property
93+
94+
Public Property Get PhoneNumberVerified() As Boolean
95+
PhoneNumberVerified = this.PhoneNumberVerified
96+
End Property
97+
98+
Public Property Let PhoneNumberVerified(ByVal value As Boolean)
99+
this.PhoneNumberVerified = value
100+
End Property
101+
102+
Public Property Get AvatarUrl() As String
103+
AvatarUrl = this.AvatarUrl
104+
End Property
105+
106+
Public Property Let AvatarUrl(ByVal value As String)
107+
this.AvatarUrl = value
108+
End Property
109+
110+
Private Property Get IUser_Id() As String
111+
IUser_Id = this.Id
112+
End Property
113+
114+
Private Property Get IUser_UserName() As String
115+
IUser_UserName = this.UserName
116+
End Property
117+
118+
Private Property Get IUser_FirstName() As String
119+
IUser_FirstName = this.FirstName
120+
End Property
121+
122+
Private Property Get IUser_LastName() As String
123+
IUser_LastName = this.LastName
124+
End Property
125+
126+
Private Property Get IUser_Email() As String
127+
IUser_Email = this.Email
128+
End Property
129+
130+
Private Property Get IUser_EmailVerified() As Boolean
131+
IUser_EmailVerified = this.EmailVerified
132+
End Property
133+
134+
Private Property Get IUser_TwoFactorEnabled() As Boolean
135+
IUser_TwoFactorEnabled = this.TwoFactorEnabled
136+
End Property
137+
138+
Private Property Get IUser_PhoneNumber() As String
139+
IUser_PhoneNumber = this.PhoneNumber
140+
End Property
141+
142+
Private Property Get IUser_PhoneNumberVerified() As Boolean
143+
IUser_PhoneNumberVerified = this.PhoneNumberVerified
144+
End Property
145+
146+
Private Property Get IUser_AvatarUrl() As String
147+
IUser_AvatarUrl = this.AvatarUrl
148+
End Property
149+

BuilderPattern/UserBuilder.cls

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
VERSION 1.0 CLASS
2+
BEGIN
3+
MultiUse = -1 'True
4+
END
5+
Attribute VB_Name = "UserBuilder"
6+
Attribute VB_GlobalNameSpace = False
7+
Attribute VB_Creatable = False
8+
Attribute VB_PredeclaredId = True
9+
Attribute VB_Exposed = False
10+
Attribute VB_Description = "Builds a User object."
11+
'@PredeclaredId
12+
'@ModuleDescription("Builds a User object.")
13+
Option Explicit
14+
Implements IUserBuilder
15+
Private internal As User
16+
17+
'@Description("Creates a new UserBuilder instance.")
18+
Public Function Create(ByVal Id As String, ByVal UserName As String) As IUserBuilder
19+
Attribute Create.VB_Description = "Creates a new UserBuilder instance."
20+
Dim result As UserBuilder
21+
Set result = New UserBuilder
22+
23+
'@Ignore UserMeaningfulName FIXME
24+
Dim obj As User
25+
Set obj = New User
26+
obj.Id = Id
27+
obj.UserName = UserName
28+
29+
Set result.User = internal
30+
Set Create = result
31+
End Function
32+
33+
'@Ignore WriteOnlyProperty
34+
'@Description("For property injection of the internal IUser object; only the Create method should be invoking this member.")
35+
Friend Property Set User(ByVal value As IUser)
36+
Attribute User.VB_Description = "For property injection of the internal IUser object; only the Create method should be invoking this member."
37+
If Me Is UserBuilder Then Err.Raise 5, TypeName(Me), "Member call is illegal from default instance."
38+
If value Is Nothing Then Err.Raise 5, TypeName(Me), "'value' argument cannot be a null reference."
39+
Set internal = value
40+
End Property
41+
42+
Private Function IUserBuilder_Build() As IUser
43+
If internal Is Nothing Then Err.Raise 91, TypeName(Me), "Builder initialization error: use UserBuilder.Create to create a UserBuilder."
44+
Set IUserBuilder_Build = internal
45+
End Function
46+
47+
Private Function IUserBuilder_WithName(ByVal FirstName As String, ByVal LastName As String) As IUserBuilder
48+
internal.FirstName = FirstName
49+
internal.LastName = LastName
50+
Set IUserBuilder_WithName = Me
51+
End Function
52+
53+
Private Function IUserBuilder_WithEmail(ByVal Email As String, Optional ByVal Verified As Boolean = False) As IUserBuilder
54+
internal.Email = Email
55+
internal.EmailVerified = Verified
56+
Set IUserBuilder_WithEmail = Me
57+
End Function
58+
59+
Private Function IUserBuilder_WithTwoFactorAuthentication(ByVal PhoneNumber As String, Optional ByVal Verified As Boolean = False) As IUserBuilder
60+
internal.TwoFactorEnabled = True
61+
internal.PhoneNumber = PhoneNumber
62+
internal.PhoneNumberVerified = Verified
63+
Set IUserBuilder_WithTwoFactorAuthentication = Me
64+
End Function
65+
66+
Private Function IUserBuilder_WithAvatar(ByVal Url As String) As IUserBuilder
67+
internal.AvatarUrl = Url
68+
Set IUserBuilder_WithAvatar = Me
69+
End Function

0 commit comments

Comments
 (0)