messagebox in class library?

  • Thread starter Thread starter raju
  • Start date Start date
R

raju

Hai,

Is it possible to show the message box with in the class library
( in dll).

If it is not possible means please give the reason.

Regards,
Raj
 
raju said:
Is it possible to show the message box with in the class library
( in dll).
Why don't you try it? The answer should be yes.

However, it's extremely poor design for a number of reasons:

- Your client may be a service or background application, which should not
or even cannot interact with the user. If nobody's sitting behind the
computer, the application will stop running.

- Even if your client does interact with the user, showing a message box may
still block them unexpectedly.

- It violates separation of concerns. Your DLL should not concern itself
with displaying messages to a user, the application is already concerning
itself with that. Your DLL should return status or ask for additional input
in a programmatic fashion, so the client can decide how to best inform the
user. It should not make these decisions on its own.

- Your client may use a different language. You cannot ensure your DLL
supports all the localizations that your client does (and vice versa).

If you really must have this, you should at least provide the client with a
way to turn off these message boxes. That way, clients which really cannot
afford to show them (because they're running non-interactively) can at least
opt out.
 
I agree with Jeroen -- this is not a good design. If you have a problem in
your class in a method being called from the UI (like a Save method), you
should throw an exception and catch it in the UI and do the messaging there.

RobinS.
GoldMail, Inc.
 
Jeroen said:
Why don't you try it? The answer should be yes.

However, it's extremely poor design for a number of reasons:

I think that this is a little harsh, you are making an assumption here
that the class library has little or nothing to do with UI, that may
not necessarily be the case, its (IMO) quite acceptable to have library
UI code as well, common dialogs that may be used across related
applications for example.

Raju, in answer to your question yes its quite possible, you simply
need to add a reference to the system.windows.forms assembly (not
referenced by default in a library project)

Regards Tim J.

--
 
Tim said:
I think that this is a little harsh, you are making an assumption here
that the class library has little or nothing to do with UI, that may
not necessarily be the case, its (IMO) quite acceptable to have library
UI code as well, common dialogs that may be used across related
applications for example.
Sure, that's possible. In fact, I know of one such library myself that has
good reason to show a message box when you call a function -- it's called
user32.dll.

That said, I prefer being "a little harsh" to yet another generation of
programmers propagating this design in inappropriate cases, which are the
majority (and it's *very* harsh on the user when that happens) -- if you
already know when it might be appropriate to do it anyway, you don't need to
listen to my advice in the first place.
 
Jeroen Mostert wrote:

if you already know when it might be appropriate to do it anyway,
you don't need to listen to my advice in the first place.

:-) thats true.



--
 
Back
Top