Community in read only mode June 18 & 19
This community will be set in READ ONLY mode for a while on Tuesday June 18 into Wednesday June 19 while we import content and users from our Micro Focus Forums community site. MORE INFORMATION
rpry Absent Member.
Absent Member.
2303 views

Multiple inheritance in SilkTest

Jump to solution

As I know, there are no multiple inheritance in SilkTest. But I need my winclass W inherit controls and methods of winclasses W1 and W2 (which aren't connected by inheritance). How can I  implement it?

0 Likes
1 Solution

Accepted Solutions
cwBrendan Absent Member.
Absent Member.

RE: Multiple inheritance in SilkTest

Jump to solution

I'm not eggbox but here you go. winclass W inherits everything from W1. Since you can't also inherit from W2 you create an instance of W2 (W2stub) and then create wrapper methods to pass method calls through to W2. The result looks like multiple inheritance but it requires a bit more work since you have to write all the wrapper methods yourself.

[+] winclass W1
    [ ]
    [-] void DoSomething()
        [ ] print("I did something!")
    [ ]
[ ]
[+] winclass W2
    [ ]
    [-] void DoSomethingElse()
        [ ] print("I did something else!")
    [ ]
[ ]
[+] winclass W : W1
    [ ]
    [ ] W2 W2stub
    [ ]
    [+] void DoSomethingElse()
        [ ] W2stub.DoSomethingElse()
    [ ]
    [ ]
[ ]
[+] window W testWin
    [ ] tag "something or other"
    [ ]
    [ ] // etc
    [ ]
[ ]
[+] testcase aaa() appstate none
    [ ]
    [ ] testWin.DoSomething()
    [ ]
    [ ] testWin.DoSomethingElse()
    [ ]

Is there any way to format the code to look nicer? I'm new to this forum. Hope this helps.

0 Likes
3 Replies
Micro Focus Contributor
Micro Focus Contributor

RE: Multiple inheritance in SilkTest

Jump to solution

One way would be to create an instance of one of the classes in your new class, e.g. W inherits from W1 but contains an instance of W2.  Then all you need to do us to provide wrapper methods with the same names as the methods in W2 that execute the methods of W2.

//*eggbox
0 Likes
Abhinandan Singh Absent Member.
Absent Member.

RE: Multiple inheritance in SilkTest

Jump to solution

@eggbox Could you provide a code snippet?

0 Likes
cwBrendan Absent Member.
Absent Member.

RE: Multiple inheritance in SilkTest

Jump to solution

I'm not eggbox but here you go. winclass W inherits everything from W1. Since you can't also inherit from W2 you create an instance of W2 (W2stub) and then create wrapper methods to pass method calls through to W2. The result looks like multiple inheritance but it requires a bit more work since you have to write all the wrapper methods yourself.

[+] winclass W1
    [ ]
    [-] void DoSomething()
        [ ] print("I did something!")
    [ ]
[ ]
[+] winclass W2
    [ ]
    [-] void DoSomethingElse()
        [ ] print("I did something else!")
    [ ]
[ ]
[+] winclass W : W1
    [ ]
    [ ] W2 W2stub
    [ ]
    [+] void DoSomethingElse()
        [ ] W2stub.DoSomethingElse()
    [ ]
    [ ]
[ ]
[+] window W testWin
    [ ] tag "something or other"
    [ ]
    [ ] // etc
    [ ]
[ ]
[+] testcase aaa() appstate none
    [ ]
    [ ] testWin.DoSomething()
    [ ]
    [ ] testWin.DoSomethingElse()
    [ ]

Is there any way to format the code to look nicer? I'm new to this forum. Hope this helps.

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.