I am studing VBA object module and trying to use it as an easy way of retriave objects properties.
I write the code below and would really appreciate if you could tell me if there is a better way of doing it, or if I am in the right path for write some good code.
Consider that I intend to use this on a bigger project, so I need to know if it is well written.
Class Module Animals
Option Explicit
Private pCat As New Animal
Private pDog As New Animal
Private pFish As New Animal
Private Sub Class_Initialize()
pCat.Mammal = True
pCat.NumberOfPaws = 4
pDog.Mammal = True
pDog.NumberOfPaws = 4
pFish.Mammal = False
pFish.NumberOfPaws = 0
End Sub
Property Get Cat() As Animal
Set Cat = pCat
End Property
Property Get Dog() As Animal
Set Dog = pDog
End Property
Property Get Fish() As Animal
Set Fish = pFish
End Property
Class Module Animal
Option Explicit
Private nPaws As Integer
Private pMammal As String
Property Get NumberOfPaws() As Integer
NumberOfPaws = nPaws
End Property
Property Let NumberOfPaws(numPaws As Integer)
nPaws = numPaws
End Property
Property Get Mammal() As Boolean
Mammal = pMammal
End Property
Property Let Mammal(IsMammal As Boolean)
pMammal = IsMammal
End Property
Subroutine for testing the object modeules above
Option Explicit
Sub Test()
Dim objAnimal As New Animals
Debug.Print objAnimal.Cat.Mammal
Debug.Print objAnimal.Cat.NumberOfPaws
Debug.Print objAnimal.Dog.Mammal
Debug.Print objAnimal.Dog.NumberOfPaws
Debug.Print objAnimal.Fish.Mammal
Debug.Print objAnimal.Fish.NumberOfPaws
End Sub