473,757 Members | 8,356 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Focuse all derived classes to implement a interface specified by the base class

I have a class which serve as a base class. I want to focuses all the
classes derived from it implement a interface. Make it a abstract
class is not a option since some XML serialization code need to
initialize the class. is it possible?

thanks
Jul 6 '06 #1
2 1457
Jinsong,

Why isn't an abstract class feasible? You can provide a constructor in
the abstract class, and then you can have your derived classes call the
constructor.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Jinsong Liu" <Ji*****@mssolu tion.com.nospam wrote in message
news:io******** *************** *********@4ax.c om...
>I have a class which serve as a base class. I want to focuses all the
classes derived from it implement a interface. Make it a abstract
class is not a option since some XML serialization code need to
initialize the class. is it possible?

thanks

Jul 6 '06 #2
Jinsong Liu wrote:
I have a class which serve as a base class. I want to focuses all the
classes derived from it implement a interface. Make it a abstract
class is not a option since some XML serialization code need to
initialize the class. is it possible?

thanks
Hi Jinsong,

The definition of an abstract class is a class which provides a template for
other classes. It does not contain enough information to instantiate it,
as parts are to be implemented by deriving classes. If you are forcing
classes to implement an interface, then you are saying that where you are
deriving from is not complete, i.e. abstract.

It doesn't make sense to force an implementation i.e. define abstract
methods in a non-abstract class, because an instance of that class would
yield methods that are not implemented.

You can define methods as virtual, which means that they _can_ be overridden
by derived classes, but not necessarily:

public class MyBaseClass
{
public virtual void Foo ()
{
}
}

public class MyDerivedClass : MyBaseClass
{
public override void Foo ()
{
// Overridden Implementation.
}
}

--
Hope this helps,
Tom Spink
Jul 7 '06 #3

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

Similar topics

9
4804
by: justanotherguy63 | last post by:
Hi, I am designing an application where to preserve the hierachy and for code substitability, I need to pass an array of derived class object in place of an array of base class object. Since I am using vector class(STL), the compiler does not allow me to do this. I do realize there is a pitfall in this approach(size of arrays not matching etc), but I wonder how to get around this problem. I have a class hierachy with abstract base...
3
8088
by: Frans Bouma | last post by:
Hi, I have a serious problem with VB.NET and a DataTable derived class and I can't figure out how to solve it. I have implemented it in C# where it works perfectly, but I can't port one statement to VB.NET and this is crucial: re-implementing ISerializable.GetObjectData() in the DataTable derived class so serializing the datatable derived class will call this method and not the DataTable version (which is private, so overriding is also...
6
2944
by: ivan.leben | last post by:
I want to write a Mesh class using half-edges. This class uses three other classes: Vertex, HalfEdge and Face. These classes should be linked properly in the process of building up the mesh by calling Mesh class functions. Let's say they point to each other like this: class Vertex { HalfEdge *edge; }; class HalfEdge { Vertex* vert;
15
3851
by: Bob Johnson | last post by:
I have a base class that must have a member variable populated by, and only by, derived classes. It appears that if I declare the variable as "internal protected" then the base class *can* populate the variable, but the population is not *required* by the derived class (which must be the case). What would meet the requirements is if I create an abstract method in the base class that populates the member variable. In this case the...
0
9298
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10072
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9885
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8737
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7286
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5172
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3399
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2698
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.