473,320 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Abstract/Base Class Best Practices - Help

Coming up with a scenario here. For example there is the standard .NET
MailMessage class.

I am creating a project (let's call it CommonBase) that has the following 2
classes

EmailMessage_Base ([Public MustInherit] inherits System.Net.Mail.MailMessage
and provides additional methods and properties)
EmailMessage_Abstract ([Public MustInherit] inherits EmailMessage_Base and
adds some business logic including what default return addresses are and
default SMTP server name is)

We are divided in the organization as to where this "business logic" should
be. I say it makes sense to have it in the abstract class. If it is in the
base class then the abstract class really has no purpose.
This project will be compiled and sent out to all of our offices so the
developers in each office can develop their applications using our
CommonBase. However there will be a second project that references
CommonBase. This project will be modifiable (source code will be available)
and have the following class:

EmailMessage ([Public] inherits CommonBase.EmailMessage_Abstract).

The other offices will have control over the source code in this second
project (called Common) so they can chose to override any of the methods in
CommonBase.EmailMessage_Abstract if they need to do so to suit their
business needs. For example they might want to get the SMTP server name
from a different place in the registry or perhaps pull it from a web service
or resource file.

Is this the best approach? Would an Implemented Interface work better? If
we were to use an implementation we would not be able to inherit
System.Net.Mail.MailMessage as far as I know. Also... I'd like to know if
it is possible to prevent users from Inheriting EmailMessage_Base and only
allow them to Inherit EmailMessage_Abstract. I don't think this is possible
but welcome any suggestions.

Any other comments are welcome, if you wish to comment on naming
conventions, structure, or provide web resources, or anything at all.

Thanks..

D


Mar 27 '06 #1
1 1515
First, don't cross-post. It makes people cross, and cross people don't help
as often as happy people. Since you need help, cross-posting is
cross-purpose.

There are a couple of basic difference between abstract classes and
interfaces, and understanding them is the key to using them effectively.

An interface is used to define a common programming interface which client
applications can use without knowing the specific type of a class. The
interface defines the types and signatures of members, which are known to
any client that wants to use that interface. It contains no code; the code
and logic are determined by the implementation in a class.

An abstract class is similar in that it contains members which are abstract.
These members do not have any code in them, only type and signature. The
business logic for these members must be defined by the derived classes.
However, in addition, an abstract class may have members which are not
abstract, which are defined. These members are common to all derived
classes, and may be treated just like any other members of a base class.

So, you use an abstract base class whenever you will have code that is
intended to be used commonly among the descendants of a class, along with
members that each derived class must provide an implementation for. If there
is no common code, and each descendant must implement the methods and
properties for itself, you use an interface. And if there are no members
that must be defined by derived classes, you use a "regular" class.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Show me your certification without works,
and I'll show my certification
*by* my works.

"D Witherspoon" <dw**********@noway.org> wrote in message
news:uA**************@TK2MSFTNGP10.phx.gbl...
Coming up with a scenario here. For example there is the standard .NET
MailMessage class.

I am creating a project (let's call it CommonBase) that has the following
2 classes

EmailMessage_Base ([Public MustInherit] inherits
System.Net.Mail.MailMessage and provides additional methods and
properties)
EmailMessage_Abstract ([Public MustInherit] inherits EmailMessage_Base and
adds some business logic including what default return addresses are and
default SMTP server name is)

We are divided in the organization as to where this "business logic"
should be. I say it makes sense to have it in the abstract class. If it
is in the base class then the abstract class really has no purpose.
This project will be compiled and sent out to all of our offices so the
developers in each office can develop their applications using our
CommonBase. However there will be a second project that references
CommonBase. This project will be modifiable (source code will be
available) and have the following class:

EmailMessage ([Public] inherits CommonBase.EmailMessage_Abstract).

The other offices will have control over the source code in this second
project (called Common) so they can chose to override any of the methods
in CommonBase.EmailMessage_Abstract if they need to do so to suit their
business needs. For example they might want to get the SMTP server name
from a different place in the registry or perhaps pull it from a web
service or resource file.

Is this the best approach? Would an Implemented Interface work better?
If we were to use an implementation we would not be able to inherit
System.Net.Mail.MailMessage as far as I know. Also... I'd like to know if
it is possible to prevent users from Inheriting EmailMessage_Base and only
allow them to Inherit EmailMessage_Abstract. I don't think this is
possible but welcome any suggestions.

Any other comments are welcome, if you wish to comment on naming
conventions, structure, or provide web resources, or anything at all.

Thanks..

D

Mar 28 '06 #2

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

Similar topics

17
by: Medi Montaseri | last post by:
Hi, Given a collection of similar but not exact entities (or products) Toyota, Ford, Buick, etc; I am contemplating using the Abstraction pattern to provide a common interface to these products....
15
by: Tee | last post by:
Hi, I have a base usercontrol with a method (blank method, no code), I have another few usercontrols that will inherit this base usercontrol, but I want to force all the usercontrol that...
3
by: Jeff | last post by:
I have an abstract class which uses System.Windows.Forms.UserControl as it's base class. It has some custom drawing methods and it also handles a few common events like Paint, PaintBackGround,...
2
by: Polo | last post by:
Hi I have a abstract class and some other than inherite from it I woul like to return a bitmap (defined in resource) from the each subclass (a bitmap that is global (static)) Thank's in...
18
by: Bradley | last post by:
I'm trying to determine if there's a general rule for when an Interface should used vs. an Abstract Class. Is there any design advantage to using one or the other? Brad
1
by: Murray Gill | last post by:
Our current solution has a number of ASP.NET pages with very similar functionality. We would like to move the common functions into a base class that inherits from System.Web.UI.Page, and then force...
1
by: D Witherspoon | last post by:
Coming up with a scenario here. For example there is the standard .NET MailMessage class. I am creating a project (let's call it CommonBase) that has the following 2 classes ...
7
by: jason | last post by:
In the microsoft starter kit Time Tracker application, the data access layer code consist of three cs files. DataAccessHelper.cs DataAcess.cs SQLDataAccessLayer.cs DataAcccessHelper appears...
0
by: emin.shopper | last post by:
I had a need recently to check if my subclasses properly implemented the desired interface and wished that I could use something like an abstract base class in python. After reading up on metaclass...
6
by: Miguel Guedes | last post by:
Hello, I recently read an interview with Bjarne Stroustrup in which he says that pure abstract classes should *not* contain any data. However, I have found that at times situations are when it...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.