- Home /
C# Conception - Hide inherited members and functions
Hey everyone,
I have a C# conception question. I have a class that inherit from MonoBehaviour but when you get the object I don't want that the other classes access MonoBehaviour properties.
I don't want to expose the features of the inherited MonoBehaviour class but I want to be able to use them (Update, Start, GetComponent, etc.) inside my inherited class but not from outside.
Is it possible ?
Thanks a lot.
I don't think so. You should think of a design alternative for that.
Try creating and using Interfaces, and keeping pointers to them, ins$$anonymous$$d of $$anonymous$$onoBehaviour classes.
I'm not sure it makes any sense to talk about only using functions like Update() and Start() (and others like Awake, OnDestroy/Enable, etc) inside the class. The whole point of them is that they're called automatically by the engine. One rarely makes explicit calls to them at all (the exception that springs to $$anonymous$$d being when you call a base class's function from the subclass's version of the same function).
Answer by nicolasjr · Apr 22, 2015 at 03:59 PM
Here you can find some interesting references: http://stackoverflow.com/questions/1125746/how-to-hide-remove-a-base-classs-methods-in-c
As I said, the best way would be to use Interfaces, so you can expose only what's from your interest to other classes. This way, instead of having pointers to your MonoBehavior class, you'll have pointers to the interfaces your MonoBehavior class is implementing.