Java and C ++ are statically typed, so what you can do with an object depends not so much on its actual dynamic type as on the type with which you are accessing it.
In the above example, you will notice that the server variable is of type ObjectServer . This means that when viewing the server you can only access the ObjectServer methods. Even if the object has a type that has other methods (which is the case in your case and its type is ObjectServerImpl ), you have no way to directly access methods other than ObjectServer .
To access other methods, you need to master the object using a different type. This can be done with a throw or with explicit access, for example, with your ext() . a.ext() returns a , but as a different type ( ExtObjectServer ), giving you access to various a methods.
Your question also asks how server.ext() limited to expert methods when ExtObjectServer extends ObjectServer . The answer is: it is not, but it is correct. This should not be limited to this. The goal is not to provide only expert functions. If so, then client code, which should use both regular and expert functions, would have to take two references to an object that was simply printed differently. There are no benefits to this.
The purpose of progressive disclosure is to hide expert material until it explicitly requests. As soon as you ask for it, you have already seen the basic things, so why hide them from you?
Angew source share