472,777 Members | 2,656 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,777 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 2158
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....
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: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.