473,753 Members | 8,077 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Accessing parent-parent method.

Hello,

Say I have three classes inheritance A <-- B <-- C

And in A I have the Create method:

class A
{
public override bool Create()
{
// do stuff
return true;
}
}

class B : A
{
public override bool Create()
{
if (!base.Create() )
{
return false;
}

// do stuff.
return true;
}
}

Now in class C

class C : B
{
public override bool Create()
{
// Here I need to access A.Create not B.Create()
}
}
}

Now the problem in C I want to access A.Create() not B.Create() is this
possible? Because calling base.Create() will call B.Create().

I need to do this weird inheritance because C shares a lot of methods, and
logically extends B .. but in creation C is totally different from B.

Thanks for any help.

Hadi
Nov 15 '05 #1
4 1681
in class C you can write base.B() thus it will call Create() method in class
B, which in its turn will call method in class A.
"Hadi" <ha**@hadi.ne t> wrote in message
news:#4******** ******@TK2MSFTN GP11.phx.gbl...
Hello,

Say I have three classes inheritance A <-- B <-- C

And in A I have the Create method:

class A
{
public override bool Create()
{
// do stuff
return true;
}
}

class B : A
{
public override bool Create()
{
if (!base.Create() )
{
return false;
}

// do stuff.
return true;
}
}

Now in class C

class C : B
{
public override bool Create()
{
// Here I need to access A.Create not B.Create()
}
}
}

Now the problem in C I want to access A.Create() not B.Create() is this
possible? Because calling base.Create() will call B.Create().

I need to do this weird inheritance because C shares a lot of methods, and
logically extends B .. but in creation C is totally different from B.

Thanks for any help.

Hadi

Nov 15 '05 #2
If B.Create has to be different, then you might want to think about doing:

class A {} // Note this is non abstract and creatable
abstract class Intermediary : A {}// Note this is an abstract class, put shared
methods here.
class B {} : Intermediary
class C {} : Intermediary

By calling base.Create() in B/C you now call directly down to the class A
implementation as long as you don't override the method in Intermediary. If you
do override the method in Intermediary then all you have to do is call return
base.Create() as implementation in Intermediary.

Adding full source below my sig. Note I used A,B,C,D as names where B was the
Intermediary class and C/D were you B/C classes.
--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers

using System;

public class A {
public virtual bool Create() {
Console.WriteLi ne("Create From A");
return true;
}
}

public abstract class B : A {
public virtual void SharedMethod1() {
}

public virtual void SharedMethod2() {
}
}

public class C : B {
public override bool Create() {
Console.WriteLi ne("Create From C");
return base.Create();
}
}

public class D : B {
public override bool Create() {
Console.WriteLi ne("Create From D");
return base.Create();
}
}

public class Tester {
private static void Main(string[] args) {
C c = new C();
c.Create();

D d = new D();
d.Create();
}
}

"Hadi" <ha**@hadi.ne t> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
Hello,

Say I have three classes inheritance A <-- B <-- C

And in A I have the Create method:

class A
{
public override bool Create()
{
// do stuff
return true;
}
}

class B : A
{
public override bool Create()
{
if (!base.Create() )
{
return false;
}

// do stuff.
return true;
}
}

Now in class C

class C : B
{
public override bool Create()
{
// Here I need to access A.Create not B.Create()
}
}
}

Now the problem in C I want to access A.Create() not B.Create() is this
possible? Because calling base.Create() will call B.Create().

I need to do this weird inheritance because C shares a lot of methods, and
logically extends B .. but in creation C is totally different from B.

Thanks for any help.

Hadi

Nov 15 '05 #3
Right .. ok thanks that's is helpful.

Hadi

"Justin Rogers" <Ju****@games4d otnet.com> wrote in message
news:um******** ******@TK2MSFTN GP12.phx.gbl...
If B.Create has to be different, then you might want to think about doing:

class A {} // Note this is non abstract and creatable
abstract class Intermediary : A {}// Note this is an abstract class, put shared methods here.
class B {} : Intermediary
class C {} : Intermediary

By calling base.Create() in B/C you now call directly down to the class A
implementation as long as you don't override the method in Intermediary. If you do override the method in Intermediary then all you have to do is call return base.Create() as implementation in Intermediary.

Adding full source below my sig. Note I used A,B,C,D as names where B was the Intermediary class and C/D were you B/C classes.
--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers

using System;

public class A {
public virtual bool Create() {
Console.WriteLi ne("Create From A");
return true;
}
}

public abstract class B : A {
public virtual void SharedMethod1() {
}

public virtual void SharedMethod2() {
}
}

public class C : B {
public override bool Create() {
Console.WriteLi ne("Create From C");
return base.Create();
}
}

public class D : B {
public override bool Create() {
Console.WriteLi ne("Create From D");
return base.Create();
}
}

public class Tester {
private static void Main(string[] args) {
C c = new C();
c.Create();

D d = new D();
d.Create();
}
}

"Hadi" <ha**@hadi.ne t> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
Hello,

Say I have three classes inheritance A <-- B <-- C

And in A I have the Create method:

class A
{
public override bool Create()
{
// do stuff
return true;
}
}

class B : A
{
public override bool Create()
{
if (!base.Create() )
{
return false;
}

// do stuff.
return true;
}
}

Now in class C

class C : B
{
public override bool Create()
{
// Here I need to access A.Create not B.Create()
}
}
}

Now the problem in C I want to access A.Create() not B.Create() is this
possible? Because calling base.Create() will call B.Create().

I need to do this weird inheritance because C shares a lot of methods, and logically extends B .. but in creation C is totally different from B.

Thanks for any help.

Hadi


Nov 15 '05 #4
Hadi,

you have several options to do what you need, here you go with two quick
ones:
// Solution #1: adding an intermediate access method

class A
{
public virtual bool Create()
{
return true;
}
}

class B : A
{
public override bool Create()
{
//
}

// This is the intermediate access method which can be called from
// derived classes instead of base.Create which would call B's Create
method
protected bool CreateBase()
{
return base.Create();
}
}

class C : B
{
public override bool Create()
{
// Instead of calling base.Create() you call base.CreateBase ()
return base.CreateBase ();
}
}

// Solution #2: Condition checking
class A
{
public virtual bool Create()
{
return true;
}
}

class B : A
{
public override bool Create()
{
// You check the type of current instance and then do different
processing
if (this is C)
{
return base.Create();
}
else
{
// here you do whatever you need to do if current instance is
not C
}
}
}

class C : B
{
public override bool Create()
{
// You simply call base.Create() and let the base class decide what
to do
return base.Create();
}
}
I am sure you could find as many solutions as you like to this problem, just
play around with it.

Regards,

--
Vjekoslav Babic, MCSA, MCDBA

"Hadi" <ha**@hadi.ne t> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
Hello,

Say I have three classes inheritance A <-- B <-- C

And in A I have the Create method:

class A
{
public override bool Create()
{
// do stuff
return true;
}
}

class B : A
{
public override bool Create()
{
if (!base.Create() )
{
return false;
}

// do stuff.
return true;
}
}

Now in class C

class C : B
{
public override bool Create()
{
// Here I need to access A.Create not B.Create()
}
}
}

Now the problem in C I want to access A.Create() not B.Create() is this
possible? Because calling base.Create() will call B.Create().

I need to do this weird inheritance because C shares a lot of methods, and
logically extends B .. but in creation C is totally different from B.

Thanks for any help.

Hadi

Nov 15 '05 #5

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

Similar topics

1
4241
by: Amy Tseng | last post by:
Hi, I am having a problem accessing SQL Server 2000 via UNIX. I am accessing SQL Server 2000 from Solaris using Sybase Open Client (CT-Lib). Here is the error message: CT-LIBRARY error: ct_connect(): network packet layer: internal net library error: Net-Library operation terminated due to disconnect
6
2746
by: Chris Styles | last post by:
Dear All, I've been using some code to verify form data quite happily, but i've recently changed the way my form is structured, and I can't get it to work now. Originally : The form is called "form1", and I have selects called "PORTA", "PORTB" ... etc...
3
4319
by: prodirect | last post by:
Hi all, I hope someone can help me. I've recently created a database and wanted to put it up on an ftp sight so that multiple people could access the same tables at the same time from different geographical locations. I have been completely unsucessful in acheiving this goal so far however. Things I have tried: Create a shortcut to ftp sight via browser then tried to map local drive to
47
5285
by: fb | last post by:
Hi Everyone. Thanks for the help with the qudratic equation problem...I didn't think about actually doing the math...whoops. Anyway... I'm having some trouble getting the following program to work. I want to output a bit pattern from base 10 input. All I get is a zero after the input...I've looked over the code but can't see the problem...any ideas? /* display the bit pattern corresponding to a signed decimal integer */
3
3345
by: AdamM | last post by:
Hi all, When I run my VbScript, I get the error: "ActiveX component can't create object: 'getobject'. Error 800A01AD". Any ideas what I did wrong? Here's my VBScript: dim o set o=getobject(,"ConsoleApplication2.Program") msgbox o.TestString
1
3134
by: CS Wong | last post by:
Hi, I have a page form where form elements are created dynamically using Javascript instead of programatically at the code-behind level. I have problems accessing the dynamically-created elements and would like to seek a solution for this. I had looked through several articles for accessing programatically-created dynamic elements such as: 1)
3
1350
by: niju | last post by:
Hi there, I have three web pages (A,B,C). I need to prevent users accessing page B and C without accessing A. What would be the best way to achieve this rule? Many Thanks Niju
2
7854
by: Jimmy Reds | last post by:
Hi, I have a blood glucose meter (a Lifescan OneTouch Ultra in case anyone was wondering) which I connect to my PC using a USB cable and I would like to have a go at accessing the data on this device without having to use the software provided by Lifescan. The software is free and is okay but it's not very good at manipulating the data. Although I connect my meter using a USB cable, it can be connected by a serial cable (there is a...
2
4522
by: Vincent | last post by:
I have been trying to find some API routines that will allow me to determine the name of the computer that is accessing a file on a server. I have found the NetFileEnum call (returns the names of the files in use and the names of the users accessing them). I have also found the NetConnectionEnum call (returns the name of the computer that is accessing a share). I do not see any way of correlating the data that these two api calls...
0
918
by: =?Utf-8?B?QmFyZW4=?= | last post by:
Hi! I have created a ASP.NET web application and accessing the same in SharePoint Portal Server using PageViewer Control. My application has a search, wherein I am sending the search string as a XMlDocument to the store Procedure. It works fine when i am directly accessing the website, but its giving exception when i am accessing the same search page through the PageViewer control. Can anyone help me out what might be the problem?
0
9653
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
9451
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
9421
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
9333
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
8328
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
6151
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4771
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...
1
3395
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
3
2284
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.