Suppose you develop an interpreter or file system. There are objects, like variables, procedures and files in some environment. They have a name and content (variable has current value, procedure has the body of code and file has some data in its body). You can request
file3.content to get their "values" and you can also always request the name of the current object by
(vbl|proc|file).name. Suppose that you enable alias objects to given object,
alias(name, target). It says that alias has it own name but somehow shares the "value" with the target. How would you design it?
The alias implementation would be strightforward if I had objects separate from their values. All aliases could share the one body then and primary object could be implemented as alias+body also.
On the other hand, primary objects are in 1-to-1 correspondence with their values and it is not wise to "prefer containtment over overriding" for them. Additionaly, most of the objects won't have the aliases and such design is a waste of memory (2 object is 2x memory wasteful in JVM). But, if do not split our objects into name+body, how do implement the aliases? As proxies? This looks like a duplication of code. You first code variable, proc, ... objects and then expand these classes with approapriate proxies. Even trice, since now objects must be interfaces which admit first-class and proxy implementation. Moreover, such splitting makes values/bodies "headless", you cannot get the name, given a body like proc1.name above. Probably that is right since body under consideretion may be accessed through any of aliases now.
I am hesitating. I admit that there can be a better approach. Which one is advised? The aliases seem to be quite in use and therefore general guidelines must exist, I am sure but cannot find anything.