I am currently writing a solution containing some abstract classes. One of them should only be expanded from a few other classes, as using it from other places than intended could cause a bit of confusion. Therefore, I want to limit which classes can extend this class.
So, if I have a class called ImportantStuff, which is abstract, I want to say that only class A and class B can extend it, and any other class cannot.
You may wonder why I would like to do something like this. Well, the code is written to work, so later there will be many other programmers, so I want to make it clear to those who this class is not intended to be used from any other places than it is. Yes, I know that I can write this in the class description, and I have it, but I want to make it 100% understandable by blocking it, because not all programmers can read comments :) I’m also curious if this can be done in good fashion, because I could not find a good answer on the Internet.
So my question is: what is the best way to do this? I think I can send a key or something that is being processed in the constructor, but is there a cleaner way to do this?
source
share