473,385 Members | 2,069 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,385 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 2205
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...

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.