Post by thraka on Aug 8, 2006 11:54:55 GMT -5
I've created an IOperator interface which will contain the methods:
Add(Value As Variant) As Object
Subtract(Value As Variant) As Object
Well this is as far as I got. Why is this good? Well it gives you a standard interface for using an equal way to the +, - and other operators on class objects themselves.
Since this cannot be done:
Point1 = Point2 + Point3
You would now be able to
Set Point1 = Point2.Add(Point3)
You can also check for different object types. In the example of Point which contains X and Y properties, you could pass in a Point object or an actual number:
Set Point1 = Point2.Add(20)
This would be coded to detect different object types and apply differently. This example would add 20 to X and Y.
IOperator.cls
Sample Class
Add(Value As Variant) As Object
Subtract(Value As Variant) As Object
Well this is as far as I got. Why is this good? Well it gives you a standard interface for using an equal way to the +, - and other operators on class objects themselves.
Since this cannot be done:
Point1 = Point2 + Point3
You would now be able to
Set Point1 = Point2.Add(Point3)
You can also check for different object types. In the example of Point which contains X and Y properties, you could pass in a Point object or an actual number:
Set Point1 = Point2.Add(20)
This would be coded to detect different object types and apply differently. This example would add 20 to X and Y.
IOperator.cls
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "IOperator"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Option Explicit
Public Function Add(Value As Variant) As Object: End Function
Public Function Subtract(Value As Variant) As Object: End Function
Sample Class
Public Function Add(Value As Variant) As Object
Set Add = Nothing
End Function
Public Function Subtract(Value As Variant) As Object
Set Subtract = Nothing
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' IOperator Interface
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Function IOperator_Add(Value As Variant) As Object
Set IOperator_Add = Add(Value)
End Function
Private Function IOperator_Subtract(Value As Variant) As Object
Set IOperator_Subtract = Subtract(Value)
End Function