Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to hide base class members from instantiated objects

Status
Not open for further replies.

BigTeeJay

Technical User
Jun 13, 2001
106
US
Hey,
Say I have the following...

Code:
// Assume I dont have the source for this code/object/class
public parentClass() {
  public doSomething() {
    Console.Writeline("Parent Class: doSomething");
  }

  public doSomethingNew() {
    Console.Writeline("Parent Class: updated doSomething");
  }
}

// This is my code
public childClass() : parentClass() {
  new public doSomethingNew() {
    base.doSomethingNew();
    Console.Writeline("Child Class: doSomethingNew");
  }
}

public void main() {
  childClass c = new childClass;
  c.doSomethingNew();
  c.doSomething(); // dont want this to be available!
}
[code]

...does this illustrate my quesetion?  I want to be able to inherit from a base class (which has various methods and properties), but in some cases I need to "hide" member functions that my child class will probably utilize, but instantiated objects should not have available.

Does anyone know how I could do this?
 
Also, I know I could create a wrapper class, eg...

Code:
public class childClass() {
  private parentClass p = new parentClass();

  public doSomethingNew() {
    p.doSomethingNew();
    Console.Writeline("Wrapper childClass: doSomethingNew");
  }
}

public void main() {
  childClass c = new childClass();
  c.doSomethingNew();
}

...but this wont work, because I do need much of the functionality that the base class provides, without having to (try to) reimplement it.

To give some more background, I am trying to create a logic layer to surround my (provided) data access layer for a .Net application I am working on. I need to ensure that people only call the methods and properties from my logic layer and nothing from the data (base) layer. However, the base layer provides the transaction management (which is one of the primary reasons for not just creating a wrapper class).

PS: I realized after hitting submit on my original post that I was missing the word "class" from the class declarations, but you get the idea ;)
 
Hey,
Thanks for the follow-up! I dont believe it will do what I am wanting. If I remember right, I tried a quick demo in C# with a protected class's method and it didnt work out.

I will certainly give it another look (and let you know how it works out).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top