N
Nick Stansbury
Hi,
Given a set of objects like the following I have two questions - firstly
is the technique used below for initialising what are effectively constants
in Sub New() correct? Is there a "better" way of doing this? Secondly, I
know that the code below for Validate() , requiredProperties etc. will never
work - you can't put a reference to nothing into a collection. How could I
effect this - or similar functionality? What I really want to be able to do
is to put a bunch of pointers into an array and check in Validate() whether
they point to an instantiated object...
(The idea here being that I can abstract the logic for validating common
objects like these into a base class.)
Thanks,
Nick
Class Animal
Public MaxAge as int
Public TypeDescription as string
Public RequiredProperties as Collection
Public Sub Validate()
for each Obj as Object in RequiredProperties
if Obj is nothing then : throw new exception("Required property
not set :" & obj.tostring()
next Obj
End Sub
End Class
Class Dog : inherits Animal
Public sub new()
TypeDescription = "Dog's are a man's best friend"
maxage = "14"
end sub
Public CollarSize as integer
End Class
Class Cat : inherits Animal
Public Sub New()
TypeDescription = "Nasty animals - not even good for eating"
MaxAge = "18"
RequiredProperties.add(HasStupidBellAroundNeck)
end sub
Public HasStupidBellAroundNeck as boolean
End Class
Given a set of objects like the following I have two questions - firstly
is the technique used below for initialising what are effectively constants
in Sub New() correct? Is there a "better" way of doing this? Secondly, I
know that the code below for Validate() , requiredProperties etc. will never
work - you can't put a reference to nothing into a collection. How could I
effect this - or similar functionality? What I really want to be able to do
is to put a bunch of pointers into an array and check in Validate() whether
they point to an instantiated object...
(The idea here being that I can abstract the logic for validating common
objects like these into a base class.)
Thanks,
Nick
Class Animal
Public MaxAge as int
Public TypeDescription as string
Public RequiredProperties as Collection
Public Sub Validate()
for each Obj as Object in RequiredProperties
if Obj is nothing then : throw new exception("Required property
not set :" & obj.tostring()
next Obj
End Sub
End Class
Class Dog : inherits Animal
Public sub new()
TypeDescription = "Dog's are a man's best friend"
maxage = "14"
end sub
Public CollarSize as integer
End Class
Class Cat : inherits Animal
Public Sub New()
TypeDescription = "Nasty animals - not even good for eating"
MaxAge = "18"
RequiredProperties.add(HasStupidBellAroundNeck)
end sub
Public HasStupidBellAroundNeck as boolean
End Class