Reputation: 5226
I use Castle Active Record' ActiveRecordBase class as a base class for my db objects. That allows me to take advantage of the AR pattern goodies, like:
MyClass clas = new MyClass();
clas.Number = 5;
clas.Save();
The problem is, for some objects, I want to hide these methods. How can I do that? I don't use interfaces for these objects.
Edit1: To make it more clear: I want to have 10 classes inheriting from the base one, but 3 of them shouldn't expose some of the methods from the base class. So for example for MyClassB, this:
MyClassB clasB = new MyClassB();
clasB.Number = 5;
clasB.Save();
shouldn't be possible - this object SHOULDN'T be able to Save().
Edit2: I've read c# hide from dervied classes some properties of base class . I agree that this is bad approach, but bear in mind that I have to use ActiveRecordBase, which I cannot simply modify (at least if I want to stick with the original Castle Active Record sources).
Upvotes: 1
Views: 611
Reputation: 55072
You don't do this.
You restructure your design so that the 7 objects inherit from one object that provides the functionality they want, the other 3 inherit from one that doesn't provide this, and they all inherit from the main "core" object. Think of it like a tree. Instead of trying to hide leaves from view, you simple change the location of the branch. I'm not sure this analogy works, but lets pretend it does.
Upvotes: 3
Reputation: 117220
If you want to hide them, the probably do not belong in that base class. I suggest expanding the inheritance hierarchy to achieve this.
Upvotes: 3