Generic Packages


Generic packages are packages with some kind of formal parameter, e.g. a replaceable type. They are really a special case of Parametrized Generic Classes. Another way of regarding generic classes is as parameterized Abstract Data Types, e.g. package GeneralStack below, which is parameterized in terms of the type of the elements in the stack - the type parameter Element.




By "instantiating" the package GeneralStack with different values of the type parameter Element we can create specialized stack packages containing elements of a specified type. In this case instantiation means the creation of a more specialized package. For example, we have instantiated GeneralStack below, with a type argument Integer creating the specialized stack called IntegerStack, and with Real giving the stack RealStack.





Finally the stack IntegerStack is used in the class IntStackUser into which it is imported.