Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8336167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:54:04+00:00 2026-06-09T03:54:04+00:00

The challenge is to come up with the best vb.net design pattern that will

  • 0

The challenge is to come up with the best vb.net design pattern that will allow a switch between 2 different mainframe accessing com objects. All this of course this without having to change the business logic.

What I’ve come up with so far is a factory type approach (see condensed pseudo code below). I have 2 classes that get instantiated based on an enum switch with the same methods and properties but with different underlying object specific methods.

Am I on the right track or should I take another approach? Thanks for any help.

Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Private MFA as MFSession = New MFSession(Enums.mfaccesstype.type1)
Private Sub Form1_Load()
    MFA.GotoScreen("XYZ")
End Sub
End Class

Public Class MFSession
Private SystemAccess As Object
End Property
Sub New(ByVal AccessType As Enums.mfaccesstype)
    Select Case AccessType
        Case Enums.mfaccesstype.type1
            SystemAccess = New AccessType1()
        Case Enums.mfaccesstype.type2
            SystemAccess = New AccessType2()
    End Select
End Sub

Public Sub GotoScreen(ByVal ScreenName As String, Optional ByVal Window As String = "")
    SystemAccess.GoToScreen(ScreenName)
End Sub
End Class

Public Class AccessType1
Private Type1Object As Object = CreateObject("comobj.Type1Object")

Sub New()
    'new session housekeeping
End Sub

Public Sub GotoScreen(ByVal ScreenName As String)
    'specialize Type1 method for going to 'ScreenName' here
End Sub

End Class


Public Class AccessType2
Private Type2Object As Object = CreateObject("comobj.Type2Object")

Sub New()
    'new session housekeeping
End Sub

Public Sub GotoScreen(ByVal ScreenName As String)
    'specialized Type2 method for going to 'ScreenName' here
End Sub
End Class
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T03:54:05+00:00Added an answer on June 9, 2026 at 3:54 am

    You are close.

    First define the common interface:

    Public Interface ISession 'could be abstract class instead if there is common code you'd like to share between the subclasses
    
       Sub GotoScreen(ByVal ScreenName As String) 
    
    End Interface
    

    Second, define the subclasses:

    Public Class Type1Session Implements ISession
    
       Private innerComObj As SomeComObject
    
       Public Sub GotoScreen(ByVal ScreenName As String)
          'type1-specific code using innerComObj
       End Sub 
    
    End Class
    
    Public Class Type2Session Implements ISession
    
       Private anotherComObj As SomeOtherComObject
    
       Public Sub GotoScreen(ByVal ScreenName As String)
          'type2-specific code using anotherComObj
       End Sub 
    
    End Class
    

    You could then create a factory that would take in an enum or other arg and return the concrete Type1Session or Type1Session.

    This can be done in a dedicated class:

    Public Class SessionFactory
    
       Public CreateSession(criteria) As ISession 
          'select case against your enum or whatever to create and return the specific type
       End Sub
    
    End Class
    

    There is also precident for putting the factory method in the superclass if you go for an abstract (MustOverride in VB) class instead of an interface.

    Finally, COM is all about interfaces so if you had control of the COM component source you could have them implement the common interface directly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The challenge The shortest code by character count, that will output musical notation based
The challenge The shortest code by character count that will generate a beehive from
The challenge The shortest code by character count that will output the numeric equivalent
I'm trying to write an Android app that will allow a user to search
I'm working on an Android application that will come with lots of data. I'd
I am doing a maths challenge for project euler and i have come across
Challenge: I have this code that fails to compile. Can you figure out what's
I'm looking for some input for a challenge that I'm currently facing. I have
Background: I will be working on tools that will be dependent on a rapidly
I'm trying to nail my understanding and best use of Lists, I have come

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.