all groups > dotnet distributed apps > november 2006 >
You're in the

dotnet distributed apps

group:

Class Library Design Problem


Class Library Design Problem JerryWEC
11/22/2006 3:55:25 PM
dotnet distributed apps:
This is a basic question regarding the design of a class library...

Main parts of the .dll class library (3 .vb files):
1] Logging Class (Singleton Pattern) - Main Interface to calling
application
2] Common Class (Singleton Pattern) - General methods for logging
3] LoggingForm (VB.net WinForm) - Display of last 100 errors.

I designed this thinking I could use my Logging class as my main class which
contains the LoggingForm as private and calls teh Common instance for common
methods.

I have two methods in my Logging class that show and close my LoggingForm.
I have three events defined in my Logging Class and one of them is to raise
back to the calling application the LoggingForm is closing.

However, the LoggingForm can only see the Shared properties and methods. It
can see any of the public properties that are not shared nor the non-shared
methods.

I have tried to pass in a reference to the Logging class into the
LoggingForm's constructor. This does work but it can't raise my event back
to the calling application.

The Logging class holds my public properties to allow my calling application
to interact with my .dll.

How would you design this class library to be able to interact the the form
and logging class objects???

Any help is greatly appreciated!!

JerryM

Re: Class Library Design Problem JerryWEC
11/22/2006 4:05:48 PM
Repost: Typos:

Happy Thanksgiving Everyone!

* This is a basic question regarding the design of a class library...

Main parts of the .dll class library (3 .vb files):
1] Logging Class (Singleton Pattern) - Main Interface to calling
application
2] Common Class (Singleton Pattern) - General methods for logging
3] LoggingForm (VB.net WinForm) - Display of last 100 errors.

I designed this thinking I could use my Logging class as my main class which
contains the LoggingForm as a private variable and calls the Common instance
for common
logging methods.

I have two methods in my Logging class, one that show() and close() my
LoggingForm.
I have three public events defined in my Logging Class and one of them is to
raise
event back to the calling application that LoggingForm is closing.

However, the LoggingForm can only see the Shared properties and methods. It
can't see any of the public properties that are not shared and can't see the
non-shared
methods either.

I have tried to pass in a reference to the Logging class into the
LoggingForm's constructor. This does work, but it can't raise my event back
to the calling application every time (If I open the form 3 times only one
of the forms invokes the event handler-???).

The Logging class holds my public properties to allow my calling application
to interact with my .dll.

How would you design this class library to be able to interact with the
logging form
and with logging class objects??? Both classes need to be able to interact
nicely with each other. I did try playing with Protect Friend. I could
make it all one class using parial keyword but I did not want to make a fat
client application out of my .dll. Design help is needed.

Any help is greatly appreciated!!

JerryM


Re: Class Library Design Problem lukezhan NO[at]SPAM online.microsoft.com
11/23/2006 12:00:00 AM
Hi Jerry,

I am not very clear about:

However, the LoggingForm can only see the Shared properties and methods. It
can't see any of the public properties that are not shared and can't see
the non-shared methods either.

Are the "Shared properties and methods" form Logging Class? or your outer
application calling Logging Class? Do you need to call the event from
Logging form, or Logging class?

Sincerely,

Luke Zhang

Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.


Re: Class Library Design Problem JerryWEC
11/27/2006 9:32:40 AM
The Logging Class is the main class in my class library (.dll).

The Logging Class holds a private variable of type LoggingForm which is a
form to show my last 50 error messages.

I'd like to keep my Logging Class as the main class with my public
properties.

My other applications say app1 annd app2 will use this Logging Class (.dll)
to log messages to a file and to this LoggingForm (frm).

I need to allow my LoggingForm to see some properties and methods in my
Logging Class as well as my Logging class see some properties and methods in
my LoggingForm (frm).

I guess I could use my Logging Class to contain an instance of my Logging
From and another class that holds my private data. I'm just trying to do
this right and not make everything public.

I'm also trying to not pass events from one class to another and then to my
parent app1 and app2.

Hope this makes since.

JerryM

Re: Class Library Design Problem lukezhan NO[at]SPAM online.microsoft.com
11/28/2006 12:00:00 AM
Hello Jerry,

As I understand, you want to share some data in Logging class with logging
form, but you don't want to make them public, is my understanding correct?

As a private variable of Logging class, logging form's properties can be
accessed directly in logging class's method, like:

this.LoggingForm.someProperties

To pass data from logging class to logging form, you may add a constructor
method in it:

private string data;

public LoggingForm2(string s)
{
InitializeComponent();
data = s;
}

in logging class:

LoggingForm f = new LoggingForm("hello");

f.Show();

Could this help on the issue?

Sincerely,

Luke Zhang

Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.


Re: Class Library Design Problem JerryWEC
11/28/2006 11:43:33 AM
Luke, your comments were very helpful!! I appreciate them!

I understand and can get to the LoggingForm variables and properties that
are public. (No problem there)

I Initially tried to pass in a reference to my Logging class to the
constructor (New()) of the LoggingForm and this worked fine with one
expection...

I have a test project that when btnTest is press it creates and shows one
copy of the LoggingForm. (Ok so far)

But when I have several copies of the form created (same button) and try to
close the copies of the form that were shown only one (the first one) would
raise the event back to my calling application. The other instances of the
form would not raise the event. So I did not like the fact that the
multiple copies did not raise the event each time.

So I now have a Logging Class creating one private withevents LoggingForm
within my Logging Class. This LoggingForm now raises an event during the
close (OK button clicked). This event is raised from the LoggingForm to the
Logging Class which then raises the same event to the calling application.

While I'm controlling only one instance of the LoggingForm now. My event is
being raised properly but if I have several instances of the LoggingForm
spun off of the Test Form (Test Project) I close the first instance of
LoggingForm and it will raise the event properly. However, the other
instances do not raise the event to the calling application.

I'm looking for some good design direction for this type of dll. I'm also
looking for some good feedback on using events within dll projects. Just
seems like there should be a better way to communicate with Forms and
Classes within dlls. What is the standard way to create dlls that use
custom Forms? In this case I only need to raise a few events to Logging
Class. If you had several events that have to be raised this code gets real
ugly quickly.

Design Help from experienced DotNet Designers is greatly appreciated!!!
Thanks for a Help!

JerryM

Re: Class Library Design Problem lukezhan NO[at]SPAM online.microsoft.com
11/29/2006 12:00:00 AM
Hello Jerry,

As I understand, the logging class is designed in Singleton Pattern, and
all Test Form will share one instance of it. How did you implement the
delegate and events between the logging class and test form, can you show
us some sample code on this? Actaully, do you want to share some data
between these layers, or enable communications with delegate and events?

And, why do you need to notify all Test form if I just close one Logging
form? If you have mutilple logging form opening at same time, you may add a
logging form collection in the logging class, instead of just one Logging
variable.

Sincerely,

Luke Zhang

Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.


Re: Class Library Design Problem JerryWEC
11/29/2006 9:17:47 AM
I do have this working somewhat now. I have a singleton for my Logging
Class and I am creating one instance of my LoggingForm in the default
constructor of my Logging Class (Again Singleton designed). I might be able
to move the constructor code to my property...

Public Class Logging

Public Event LogMessageBarClicked()

Public Event LogExitDisplayLoggingWindow()

Public Event LogErrorOccurred(ByVal outEx As Exception) #End Region



Private m_instance As Logging

Private WithEvents m_formInstance As frmLogDisplay

Private m_LogToFile As Boolean



'Default constructor declared to facilitate singleton class model

Public Sub New()

Try

If m_formInstance Is Nothing Then

m_formInstance = New frmLogDisplay()

End If

Catch ex As Exception

'Exception logic here...

End Try

End Sub



Public ReadOnly Property Instance() As Logging

Get

Try

If m_instance Is Nothing Then

SyncLock GetType(Logging)

If m_instance Is Nothing Then

m_instance = New Logging

End If

End SyncLock

End If

Return m_instance

Catch ex As Exception

'EH code here.

End Try

End Get

End Property

..

..

..

'Rest of Class omitted...

End Class



From my LoggingForm I send an event back to my Logging Class with re-raise
it to the calling application. One thing I was trying to eliminate was the
events from the Form to the Logging Class. I have to look at how I was
creating the class objects before. I think I was using one variable for all
three instances so that may have been part of my problem. I'll post if I
have time when I figure out the problem with multiple forms. I don't have
that test code any longer and will have to back track.

Thanks of all your help! JerryM

Re: Class Library Design Problem JerryWEC
12/1/2006 7:45:58 AM
Well what I'd like to see is someone come forward and explain the best way
to design class libraries with Forms. I'd like to see some best practices
from Microsoft as well. Is there any specific web pages or articles that
have covered this topic. I really don't see where having to pass in object
to other object is the best way to send data to internally desgined objects
with a class library and that the having to send back an event between class
objects is the best way to comminucate actions back to objects.

This would be a great book idea if anyone wanted to write it.

Thanks! JerryM

Re: Class Library Design Problem lukezhan NO[at]SPAM online.microsoft.com
12/1/2006 11:04:29 AM
Hello Jerry,

Is there any updates on the issue? If you nned further assistance on this
issue, please feel free to let us know.

Sincerely,

Luke Zhang

Microsoft Online Community Support

This posting is provided "AS IS" with no warranties, and confers no rights.


Re: Class Library Design Problem lukezhan NO[at]SPAM online.microsoft.com
12/4/2006 12:00:00 AM
Hello Jerry,

Events/Delegates is a good way in .NET to communicate between objects and
threads, with them we can invoke methods even in other classes/objects. In
different application, there may be different "best way". But, as I know,
there are lots of .NET applications to use Events and delegate to
communicate between objects.

Sincerely,

Luke Zhang

Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.


AddThis Social Bookmark Button