Wrapper Function - Multiple Inheritance

Multiple Inheritance

In a programming language that does not support multiple inheritance of base classes, wrapper functions can be used to simulate it. Below is an example of part of a Java class that "inherits" from LinkedList and HashSet.

public class StackSet implements Stack, Set { private LinkedList stack; private HashSet set; public boolean push(Object o) { if (set.add(o)) return stack.push(o); else return false; } public Object pop { Object o = stack.pop; set.remove(o); return o; } public boolean contains(Object o) { return set.contains(o); } }

Read more about this topic:  Wrapper Function

Famous quotes containing the words multiple and/or inheritance:

    Creativity seems to emerge from multiple experiences, coupled with a well-supported development of personal resources, including a sense of freedom to venture beyond the known.
    Loris Malaguzzi (20th century)

    It is very difficult to be wholly joyous or wholly sad on this earth. The comic, when it is human, soon takes upon itself a face of pain; and some of our griefs ... have their source in weaknesses which must be recognized with smiling compassion as the common inheritance of us all.
    Joseph Conrad (1857–1924)