2017-08-16 208 views
1

我开发一个VBScript VBSCRIPT多个语句如下喜欢单Return语句

Dim a 
Set a = New Class1 
a("text").doSomething 'Has to execute doSomething in Class1 
a("text").anotherSomething 'Has to execute doSoemthing in Class2 

class Class1 
    Dim b 
    Dim c 
    public default Function init(str) 
      Set b = New Class2 
      Set c = New Class3 
      'Some more operations to perform 
      If **What is the condition can be?** Then 
       Set init = c 
      Else 
       Set init = b 
      End If 
    End Function 
End class 

class Class2 
    public Function doSomething() 
     'Stuff to do something 
    End Function 
End class 
class Class3 
    public Function anotherSomething() 
     'Stuff to do something 
    End Function 
End class 

这里,对象“A”具有参数和这个参数可以是相同的。 所以,我不能保持是参数“=”或“<>”

而且,我不能将这些函数放在Class1中。

那么,什么是可以决定的条件。

+0

多态性是不是在VBScript本地执行,但也有可能是一些解决方法。 – omegastripes

回答

0

看起来你需要利用委托人。基本上你需要内部对象,它们是你想要访问OOP中父类的方法。

下面是一个例子:

Class ScreenPoint 
    '' Properties 

    'Ancestor Point2D 
    Private P2D 
    'Point color 
    Private Color 
    '---------------------- 

    '' Methods 
    'Constructor - called automatically 
    Private Sub Class_Initialize() 
    Set P2D = new Point2D 
    End Sub 
    '---------------------- 
    'Destructor - called automatically 
    Private Sub Class_Terminate() 
    Set P2D = Nothing 
    End Sub 
    '---------------------- 
    'A pair of methods to access private property X 
    Property Get X 
    X = P2D.X 
    End Property 

    Property Let X(ByVal in_X) 
    P2D.X = in_X 
    End Property 
    '---------------------- 
    'A pair of methods to access private property Y 
    Property Get Y 
    Y = P2D.Y 
    End Property 

    Property Let Y(ByVal in_Y) 
    P2D.Y = in_Y 
    End Property 
    '---------------------- 
End Class 

如果丢失,请尝试点击阅读文章出处:http://automation-beyond.com/2008/11/16/oop-vbscript-2/