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 7731467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:29:14+00:00 2026-06-01T06:29:14+00:00

I have written a base class from which I wish to derive several child

  • 0

I have written a base class from which I wish to derive several child classes (in this case Windows Form classes), and I’m using a Factory pattern in order to maintain a collection of the child instances, so that a form can only have one instance per primary key value (sort of a mash-up of Factory and Singleton patterns.)

I’m using the following code in the base form class:

Public Class PKSingletonForm
   Inherits Form

   Protected _PKValue As Int32 = 0
   Protected _strFormKey As String = ""
   Protected Shared _dictForms As New Dictionary(Of String, PKSingletonForm)

   Public Shared Function GetForm(Of T As {PKSingletonForm, New})(Optional ByVal PKValue As Int32 = 0) As T
      '** Create the key string based on form type and PK.
      Dim strFormKey As String = GetType(T).Name & "::" & PKValue.ToString

      '** If a valid instance of the form with that key doesn't exist in the collection, then create it.
      If (Not _dictForms.ContainsKey(strFormKey)) OrElse (_dictForms(strFormKey) Is Nothing) OrElse (_dictForms(strFormKey).IsDisposed) Then
         _dictForms(strFormKey) = New T()
         _dictForms(strFormKey)._PKValue = PKValue
         _dictForms(strFormKey)._strFormKey = strFormKey
      End If

      Return DirectCast(_dictForms(strFormKey), T)
   End Function
End Class

The idea is to create a child form (called UserInfoForm, for example) that inherits from the base form, and create an instance of it for user #42 as follows:

Dim formCurrentUser = PKSingletonForm.GetForm(of UserInfoForm)(42)

All this works as intended.

However, the UserInfoForm now has some properties I wish to set, and I would like to set them using Object Initializers, as opposed to after the form is created by the factory, like so:

Dim formCurrentUser As New UserInfoForm With { .ShowDeleteButton = False, .ShowRoleTabs = False }

Is there any way to combine these two methods, so I’ve got the factory as well as the initializer?

I’m not looking for:

Dim formCurrentUser = PKSingletonForm.GetForm(of UserInfoForm)(42)
formCurrentUser.ShowDeleteButton = False
formCurrentUser.ShowRoleTabs = False

…because the base class also has a ShowForm() method that takes additional base form parameters, wraps the GetForm() function, and shows the form.

  • 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-01T06:29:15+00:00Added an answer on June 1, 2026 at 6:29 am

    Our ShowForm() method was written as follows:

    Public Shared Sub ShowForm(Of T As {BaseForm, New})(Optional ByVal PKValue As Int32 = 0, <Several Parameters Here>)
    
       Dim formShown As BaseForm = GetForm(Of T)(PKValue, isRepeatable)
    
       <Do Stuff with Parameters Here>
    
       formShown.Show()
       formShown.BringToFront()
    End Sub
    

    Our solution was to take out the Shared (and the Generics), to simplify ShowForm() to:

    Public Sub ShowForm(<Several Parameters Here>)
    
       <Do Stuff with Parameters Here>
    
       Me.Show()
       Me.BringToFront()
    End Sub
    

    That way, we can write:

    Dim formCurrentUser = PKSingletonForm.GetForm(of UserInfoForm)(42)
    formCurrentUser.ShowDeleteButton = False
    formCurrentUser.ShowRoleTabs = False
    formCurrentUser.ShowForm(blah, blah)
    

    …as well as:

    Dim formCurrentUser = PKSingletonForm.GetForm(of UserInfoForm)(42).ShowForm()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a base class (written using C#.net) which uses datasets to pull data
i have written a generic repository for my base windows which have a problem
I have a bunch of classes extending an abstract Base class. Each subclass takes
I have trouble when designing classes like this class C1 { public: void foo();
I am new to STL. I have written a Template Base class as follows
I have a homework problem that asks: Desgin a derived class GraduateStudent from base
I have a custom UI control which has a JavaScript class written around the
I have a fairly complex set of C++ classes that are re-written from Java.
I have a .NET_4 Managed C++ ref class that I derive from a .NET_4
I have written some general functions to convert between decimal and any other base-n

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.