473,804 Members | 2,119 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

c# overriding class questions

Hello I have base class called DocumentManager .cs
I then have another class which inherits from DocumentManager
which is a TestManager.cs

I want to override the base method and want to pass properties
on TestManager into DocumentManager , and then load the TestManager
properties with values from Document manager....

I am really confused all the examples I can find seem like simple
Animal->Dog type instructions. Basically in DocumentManager
I have a constructor....

public DocumentManager (string sqlConnectionSt ring, string
rootFilePath)
{
sqlconn = sqlConnectionSt ring;
rootFilePath = rootFilePath;
}

and some fields and properties, this plus other like
FileIDReference ,FileName,FileP ath,FullFilePat h;

private string rootFilePath;

public virtual string RootFilePath
{
get
{
return rootFilePath;
}
set
{
rootFilePath = value;
}
}

then a method

public virtual int AddDocument(str ing _filePath)
{
this.FilePath = createDirectory ();
this.FileName = Path.GetFileNam e(_filePath);
DocumentManager DataAccess dmda = new
DocumentManager DataAccess(sqlc onn, rootFilePath);
this.FileIDRefe rence = dmda.AddDocumen tToDMInfo(this. FilePath,
this.FileName);
this.FullFilePa th = this._filepath + this.FileIDRefe rence + "."
+this.FileName;
return this.FileIDRefe rence;
}

Then in my TestManager Class I have similar properties and constuctor
but in
my overrided AddDocument method. I am doing....

public override int AddDocument(str ing _filePath)
{
base.AddDocumen t(_filePath);
}

but somehow my TestManager constructor

public TestManager(str ing sqlConnectionSt ring, string rootFilePath)
{
sqlconn = sqlConnectionSt ring;
rootFilePath = rootFilePath;
}

doesn't pass on the sqlconnect string to the overriden class, also I
need to populate the TestManager properties with those of the
DocumentManager ....

Besides when I do the above I just get this error....
"Declaratio n referenced in a method implementation can not be a final
method"

Can anyone suggest how to go about this in a better way for now I am
just doing the obvious.....

public override int AddDocument(str ing _filePath)
{
DocumentManager dm = new DocumentManager (sqlconn,rootFi lePath);
this.FileIDRefe rence = dm.AddDocument( _filePath);
this.FilePath = dm.FilePath;
this.FileName = dm.FileName;
this.FullFilePa th = dm.FullFilePath ;
set dm = null;
return this.FileIDRefe rence;
}

Thanks,
Mags
Nov 16 '05 #1
2 2996
add this

public TestManager(str ing sqlConnectionSt ring, string rootFilePath) : base
(string sqlConnectionSt ring, string rootFilePath)

to your subclass constructor

JIM

"MattB" <MB*********@ya hoo.co.uk> wrote in message
news:b4******** *************** ***@posting.goo gle.com...
Hello I have base class called DocumentManager .cs
I then have another class which inherits from DocumentManager
which is a TestManager.cs

I want to override the base method and want to pass properties
on TestManager into DocumentManager , and then load the TestManager
properties with values from Document manager....

I am really confused all the examples I can find seem like simple
Animal->Dog type instructions. Basically in DocumentManager
I have a constructor....

public DocumentManager (string sqlConnectionSt ring, string
rootFilePath)
{
sqlconn = sqlConnectionSt ring;
rootFilePath = rootFilePath;
}

and some fields and properties, this plus other like
FileIDReference ,FileName,FileP ath,FullFilePat h;

private string rootFilePath;

public virtual string RootFilePath
{
get
{
return rootFilePath;
}
set
{
rootFilePath = value;
}
}

then a method

public virtual int AddDocument(str ing _filePath)
{
this.FilePath = createDirectory ();
this.FileName = Path.GetFileNam e(_filePath);
DocumentManager DataAccess dmda = new
DocumentManager DataAccess(sqlc onn, rootFilePath);
this.FileIDRefe rence = dmda.AddDocumen tToDMInfo(this. FilePath,
this.FileName);
this.FullFilePa th = this._filepath + this.FileIDRefe rence + "."
+this.FileName;
return this.FileIDRefe rence;
}

Then in my TestManager Class I have similar properties and constuctor
but in
my overrided AddDocument method. I am doing....

public override int AddDocument(str ing _filePath)
{
base.AddDocumen t(_filePath);
}

but somehow my TestManager constructor

public TestManager(str ing sqlConnectionSt ring, string rootFilePath)
{
sqlconn = sqlConnectionSt ring;
rootFilePath = rootFilePath;
}

doesn't pass on the sqlconnect string to the overriden class, also I
need to populate the TestManager properties with those of the
DocumentManager ....

Besides when I do the above I just get this error....
"Declaratio n referenced in a method implementation can not be a final
method"

Can anyone suggest how to go about this in a better way for now I am
just doing the obvious.....

public override int AddDocument(str ing _filePath)
{
DocumentManager dm = new DocumentManager (sqlconn,rootFi lePath);
this.FileIDRefe rence = dm.AddDocument( _filePath);
this.FilePath = dm.FilePath;
this.FileName = dm.FileName;
this.FullFilePa th = dm.FullFilePath ;
set dm = null;
return this.FileIDRefe rence;
}

Thanks,
Mags

Nov 16 '05 #2
You can make your sqlConn string protected, in the base class. That way,
you can access the member from a derived class but not from outside.

-vJ

"MattB" <MB*********@ya hoo.co.uk> wrote in message
news:b4******** *************** ***@posting.goo gle.com...
Hello I have base class called DocumentManager .cs
I then have another class which inherits from DocumentManager
which is a TestManager.cs

I want to override the base method and want to pass properties
on TestManager into DocumentManager , and then load the TestManager
properties with values from Document manager....

I am really confused all the examples I can find seem like simple
Animal->Dog type instructions. Basically in DocumentManager
I have a constructor....

public DocumentManager (string sqlConnectionSt ring, string
rootFilePath)
{
sqlconn = sqlConnectionSt ring;
rootFilePath = rootFilePath;
}

and some fields and properties, this plus other like
FileIDReference ,FileName,FileP ath,FullFilePat h;

private string rootFilePath;

public virtual string RootFilePath
{
get
{
return rootFilePath;
}
set
{
rootFilePath = value;
}
}

then a method

public virtual int AddDocument(str ing _filePath)
{
this.FilePath = createDirectory ();
this.FileName = Path.GetFileNam e(_filePath);
DocumentManager DataAccess dmda = new
DocumentManager DataAccess(sqlc onn, rootFilePath);
this.FileIDRefe rence = dmda.AddDocumen tToDMInfo(this. FilePath,
this.FileName);
this.FullFilePa th = this._filepath + this.FileIDRefe rence + "."
+this.FileName;
return this.FileIDRefe rence;
}

Then in my TestManager Class I have similar properties and constuctor
but in
my overrided AddDocument method. I am doing....

public override int AddDocument(str ing _filePath)
{
base.AddDocumen t(_filePath);
}

but somehow my TestManager constructor

public TestManager(str ing sqlConnectionSt ring, string rootFilePath)
{
sqlconn = sqlConnectionSt ring;
rootFilePath = rootFilePath;
}

doesn't pass on the sqlconnect string to the overriden class, also I
need to populate the TestManager properties with those of the
DocumentManager ....

Besides when I do the above I just get this error....
"Declaratio n referenced in a method implementation can not be a final
method"

Can anyone suggest how to go about this in a better way for now I am
just doing the obvious.....

public override int AddDocument(str ing _filePath)
{
DocumentManager dm = new DocumentManager (sqlconn,rootFi lePath);
this.FileIDRefe rence = dm.AddDocument( _filePath);
this.FilePath = dm.FilePath;
this.FileName = dm.FileName;
this.FullFilePa th = dm.FullFilePath ;
set dm = null;
return this.FileIDRefe rence;
}

Thanks,
Mags

Nov 16 '05 #3

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

Similar topics

3
4202
by: Ali Eghtebas | last post by:
Hi, I have 3 questions regarding the code below: 1) Why can't I trap the KEYDOWN while I can trap KEYUP? 2) Is it correct that I use Return True within the IF-Statement? (I've already read the documentation but it is rather hard to understand so please don't refer to it :) 3) Many examples in the newsgroups use Return MyBase.ProcessKeyPreview(m) as the last code line while I have used Return MyBase.ProcessKeyEventArgs(m)
3
2529
by: Philippe Guglielmetti | last post by:
Look at these few lines of code: class A { public: virtual void f() { cout << "A";}}; class B : public A{public: static void f() { cout << "B"; }}; class C : public B{public: void f() { cout << "C"; }}; // virtual or not ? that's the question... int main(int, char**) { A* x; A a; B b; C c;
8
2267
by: Edward Diener | last post by:
Is it possible for a derived class to override a property and/or event of its base class ?
5
2731
by: Hongzheng Wang | last post by:
Hi, I have a problem about the overriding of private methods of base class. That is, if a method f() of base class is private, can the derived class overriding f() be overriding? For example, class base {
8
6743
by: Massimiliano Alberti | last post by:
Can I specialize a template function in a subclass without overriding it? (the main template function is defined in a base class). Now I'm doing something like that: (in base class) template<class X> void myfunc(X par1) { } (in derived class) template<class X>
15
24015
by: Susan Baker | last post by:
Hello everybody, I'm new to C++ (I have some C background). I've read up on this topic a few times but it just dosen't seem to be sinking in. 1. Whats the difference between overloading and overriding? 2. When is one preferable to use as opposed to the other? 3. How are virtual functions related to this topic (overloading/overriding) - a real world example of using virtual functions would be very much appreciated.
4
2225
by: Rafael Veronezi | last post by:
I have some questions about override in inheritance, and virtual members. I know that you can you override a method by two ways in C#, one, is overriding with the new keyword, like: public new bool Equals(object obj) {} Another is using the override keyword, like: public override bool Equals(object obj) {}
3
1560
by: Amin Sobati | last post by:
Hi, I have two classes. Class2 inhertis Class1: ----------------------------- Public Class Class1 Public Overridable Sub MySub() End Sub End Class Public Class Class2
10
105210
by: r035198x | last post by:
The Object class has five non final methods namely equals, hashCode, toString, clone, and finalize. These were designed to be overridden according to specific general contracts. Other classes that make use of these methods assume that the methods obey these contracts so it is necessary to ensure that if your classes override these methods, they do so correctly. In this article I'll take a look at the equals and hashCode methods. ...
17
1694
by: Donn Ingle | last post by:
Hi, Here's a framework for the questions: --- In a module, part of an API --- class Basis ( object ): def foo ( self, arg ): pass --- In user's own code --- class Child ( Basis ):
0
9715
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10600
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...
0
10352
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10354
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
10097
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9175
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...
0
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4313
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3835
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.