I am looking for an good explanation, maybe with some examples. In my understanding, something is ‘generic’ when it can be used for multiple purposes. But I may be wrong…
I am looking for an good explanation, maybe with some examples. In my understanding,
Share
Do you want a ‘generic’ definition, or within a specific context?
In a general sense, ‘generic’ describes a process or structure that does not itself enforce a rigid context within which it must be called. At the same time, it must understand enough about its context to be meaningful. For example, a generic structure for adding numbers would not care whether given floating-point or integer arguments, but would have difficulty adding Q + Pi.
To some extent, this is foundational to object-oriented programming. However, many programming languages use the term ‘generic’ in a much more restrictive sense. Within those languages, a generic class can be strongly typed at run-time to any class that implements a known ‘interface’ (in a general sense…) that the subscriber knows how to interact with. Languages vary widely on how they implement and support this, so concrete examples may not provide much more insight unless you identify the desired language up front.