473,491 Members | 2,552 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

OOP Design

I have a the requirement for a class to alert via an email message when an
error occurs. In this main class, I have wrapped the main logic into a try
catch statement. When an error occurs, inside of the catch statement a call
to an alert class is invoked which in turn sends an email with the error
message. What would be the preferred design approach to solve this
requirement? My original thought is to create an interface for the
AlertAgent which will contain an Alert method. The main class would then
implement this interface, requiring an Alert method. It would then be the
programmers job to implement the logic inside of this method to invoke the
AlertAgent's send method.

Is this the correct approach? Suggestion, please.

Thanks
Jan 13 '06 #1
2 1052
This sounds like the most flexible approach; then in 2008 when the class
fails, somebody can have replaced the email agent that would notify you in
the morning with an SMS agent that can let you know while you are in the
pub!

Bu seriously, this approach provides the most flexibility and is certainly
the approach that I would take.

Martin.

"Chris Fink" <no****@chrisfink.com> wrote in message
news:eN**************@TK2MSFTNGP12.phx.gbl...
I have a the requirement for a class to alert via an email message when an
error occurs. In this main class, I have wrapped the main logic into a try
catch statement. When an error occurs, inside of the catch statement a
call to an alert class is invoked which in turn sends an email with the
error message. What would be the preferred design approach to solve this
requirement? My original thought is to create an interface for the
AlertAgent which will contain an Alert method. The main class would then
implement this interface, requiring an Alert method. It would then be the
programmers job to implement the logic inside of this method to invoke the
AlertAgent's send method.

Is this the correct approach? Suggestion, please.

Thanks

Jan 13 '06 #2
"Chris Fink" <no****@chrisfink.com> wrote in message
news:eN**************@TK2MSFTNGP12.phx.gbl...
I have a the requirement for a class to alert via an email message when an
error occurs. In this main class, I have wrapped the main logic into a try
catch statement. When an error occurs, inside of the catch statement a
call to an alert class is invoked which in turn sends an email with the
error message. What would be the preferred design approach to solve this
requirement?
Factory Method and simple delegation comes to mind.

My original thought is to create an interface for the AlertAgent which
will contain an Alert method.
yep
The main class would then implement this interface, requiring an Alert
method.


I disagree with this part. The main class would not 'implement' this
interface. A concrete 'EmailAlertAgent' class would implement the
interface. The main class would call a factory to return an object that
implements the interface. (at first, this factory method will be really
simple, because it will return an 'EmailAlertAgent' object.) The main class
would then simply call the object's Alert method. In a simple example like
this, I'd place the factory method as a static method in a seperate class in
the same namespace as your interface.

So code looks like this: (Caveat: air code... I use tools a lot, so my air
code is sloppy. I'm trying to illustrate...)

namespace MyCompany.Alert.Agent
{
public interface AlertAgent
{
public bool Alert(Exception excp, OtherAlertData otherdata);
}

public class EmailAlertAgent : AlertAgent
{
public bool Alert(Exception excp, OtherAlertData otherdata)
{
// implement the notification here. Use config settings or
a database to allow thing like the 'TO' line to be readily changed.
}

}
public class AlertFactory
{
public static AlertAgent GetAgent()
{
// for now, this is simple. In the future, you can have this
module check the config file to see if different
// apps would want to use a different alert agent, or if the
user wants to use more than one agent, etc.
return new EmailAlertAgent();
}
}
}

// The point of this exercise is that the code in this main class doesn't
change,
// no matter what changes you need to make to the structure of alerts.

namespace MyCompany.Stuff.Gets.Done
{
public class MainClass
{
public void MainMethod()
{
try
{
// do something hazardous and useful here
}
catch (Exception ex)
{
OtherAlertData ad = new OtherAlertData('useful param
1', 'useful param 2');
AlertAgent agent = AlertFactory.GetAgent();
agent.Alert(ex, ad);
}
}
}
}
--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
Jan 16 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2088
by: adb | last post by:
I came up with a replication configuration that is basically the result of all the restrictions of replication as well as the restrictions of allowable software on work PC's and I was curious if...
3
4109
by: zlst | last post by:
Many technological innovations rely upon User Interface Design to elevate their technical complexity to a usable product. Technology alone may not win user acceptance and subsequent marketability....
0
1884
by: Edward Diener | last post by:
In Borland's VCL it was possible to divide a component into design time and run time DLLs. The design time DLL would only be necessary when the programmer was setting a component's properties or...
7
2971
by: Shimon Sim | last post by:
I have a custom composite control I have following property
2
2356
by: Paul Cheetham | last post by:
Hi, I have moved an application from VS2003 to VS2005, and I am now unable to view most of my forms in the designer. The majority of the forms in my project are derived from class PACForm,...
1
6316
by: Nogusta123 | last post by:
Hi, I have had a lot of problems getting web pages, master pages and content pages to render in VS2005 design view the same as they would in Internet Explorer. I did a lot of looking on the...
0
2491
by: YellowFin Announcements | last post by:
Introduction Usability and relevance have been identified as the major factors preventing mass adoption of Business Intelligence applications. What we have today are traditional BI tools that...
19
3132
by: neelsmail | last post by:
Hi, I have been working on C++ for some time now, and I think I have a flair for design (which just might be only my imagination over- stretched.. :) ). So, I tried to find a design...
10
3612
by: vital | last post by:
Hi, I am designing the middle tier of a project. It has 6 classes and microsoft application data access block. The six classes are DBServices, Logger, ProjectServices ... etc. and all these...
4
2445
by: Ken Fine | last post by:
I've been living with a frustrating issue with VS.NET for some months now and I need to figure out what the problem is. Hopefully someone has run into the same issue and can suggest a fix. I...
0
7154
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7190
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6858
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7360
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5451
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4881
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4578
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
1
633
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
280
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.