BaseClass-DerivedClass Instance-Issue

G

Guest

Hi,

I have a BaseClass-DerivedClass Instance-Issue.

Classes: (Framework)

Stegosoft.Settings.SerializationClass
Stegosoft.Stegosuite.Common.UIStrings (Inherits
Stegosoft.Settings.SerializationClass)
Stegosoft.Windows.Forms.UIForm
Stegosoft.Windows.Forms.UIFormWithCommandManager (Inherits
Stegosoft.Windows.Forms.UIForm)
And many more Derived forms

Application:

References all assemblies
Has forms derived from UIForm, UIFormWithCommandManager, UIF.....

At start-up the Application creates a new Instance of UIStrings. (Friend
scope mUIStrings)
The properties are serialized and remain unchanged for the rest of the
Apps-Life.

UIForm and UIFormWithCommandManager use Properties of UIString (the
Application itself too).

Now the Issue:

SerializationClass has some Shared Methods
Every time a form gets instanciated, it creates an instance of UIStrings
Since SerializationClass has some Shared Methods, the class doesn't get
disposed at the end of the Form's lifecycle.
Besides that, all properties of every instance are the same, so I don't need
new instances.

So basically: my BaseForm needs to use the Instance of a Class which is
instanciated in a derived class or a containg application.
I could pass the Instance through the BaseForms' constructor or a property,
but I don't want to do that.

Isn't there another way to acchieve this?

TIA,


Michael
 
L

Larry Lard

If I'm reading this right, it sounds like you want there to only ever
exist ONE UIStrings object? In which case you should look up the
Singleton pattern. If not, ignore me :)
 
G

Guest

Hi Larry,

Thanks for your reply.
Yes and no (I guess)...
You are correct that I need only ONE instance.
But... this is at assembly-level (Library - Framework) and has nothing to do
with Server-Side Activation.
Methods in the BaseForm have to use the Instance of the UIStrings-Class
which is accessed by the BaseForms' Child (grandchild, grand-grandchild, ...)
at Runtime.

I can't figure out how Singleton can help me out here (as far as my
knowledge in this subject goes - which isn't far)

Maybe you can elaborate your idea a bit more (would appreciate this very
much).

Kind regards,

Michael
 
G

Guest

Hi Larry,

I've got it now (started off the wrong route :-( )

\\\
Namespace Common

<Serializable()> _
Public Class UIStrings
Inherits Stegosoft.Settings.SerializationClass
Private Shared mInstance As New UIStrings

Public Shared ReadOnly Property Instance() As UIStrings
Get
Return mInstance
End Get
End Property

Private Sub New()
Debug.WriteLine("New UIStrings created")
End Sub

#Region " Load "

Public Shadows Function Load(ByVal path As String, Optional ByVal
user As String = Nothing) As UIStrings
Return DirectCast(MyBase.Load(Me,
Me.GetType.Assembly.GetCallingAssembly, path, user), UIStrings)
End Function
.....
///

And instead of creating a new instance like:

\\\
Friend mUIstrings As New Stegosoft.Common.UIStrings
///

I get the original instance like:


\\\
Friend mUIstrings As Stegosoft.Common.UIStrings =
Stegosoft.Common.UIStrings.Instance
///

Thanks for your help!

Regards,

Michael
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top