Answer the question
In order to leave comments, you need to log in
What languages have a built-in ability and syntax to remove certain methods and/or properties of inherited classes when the class is created?
What languages have this functionality?
class A:
var a1
var a2
class B extends A:
remove a1
remove
removes a property a2
from the class B
, class instances B
are already created without a2
remove
type()
Answer the question
In order to leave comments, you need to log in
If a gloomy old woman knocks on your window tonight, it is Barbara Liskov who has a conversation with you.
The whole point of inheritance is that an instance of class B can also be used as an instance of class A (but not vice versa). If some attribute is removed from B, what will happen to inheritance? If you just try to somehow hide it, then this will not help - after all, you can turn an instance of class B into an instance of class A by casting types and get back your access to the desired field.
And in general, here, for example, there is a library that can work with objects of class A. The library was compiled by someone, its source code is not available. We define a child class B and then use the library functions on objects of this class. Everything is fine, but we can no longer prohibit the library from working with this field.
PS: At one time, reading the description of the internal structure of classes in Turborland Pascal helped me understand OOP much better. Classes are arranged (in Pascal they are called objects, but this is not so important) something like this:
1. Link to the virtual method table (VMT)
2. Field 1.
3. Field 2.
...
VMT is structured like this:
1. Link to the method 1
2. Reference to the method 2
... The
inherited class differs from the original one in that it has a longer list of fields (but all the fields of the original are available and located at the same offsets), and the addresses of the overridden methods are different, plus itself the VMT table can be longer due to new methods added (but the same old methods are at the same offsets).
Due to this, even previously compiled code, which knows nothing about inherited classes, works with them as with their own.
There is no such thing and cannot be, because it breaks the whole concept of inheritance.
Most likely, you want to do something wrong, since you have such a desire.
UPD: Looked at the comments. If you really want to take someone else's module and hide something from it, then you don't need to use inheritance.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question