Type generalization is a technique commonly used in
refactoring
In computer programming and software design, code refactoring is the process of restructuring existing computer code—changing the '' factoring''—without changing its external behavior. Refactoring is intended to improve the design, structu ...
. The idea is to draw on the benefits of
object-orientation {{Broad-concept article
Object-oriented or object-orientation is a software engineering concept, in which concepts are represented as " objects". Object-oriented topics include:
* Object-oriented analysis and design
* Object-oriented design
* Objec ...
and make more-generalized types, thus enabling more code sharing, leading to better maintainability as there is less code to write. Too-general code can, however, become completely useless, leading to
spaghetti code
Spaghetti code is a pejorative phrase for unstructured and difficult-to-maintain source code. Spaghetti code can be caused by several factors, such as volatile project requirements, lack of programming style rules, and software engineers with insuf ...
doing effectively nothing.
Type generalization refers to making more general or more abstract some subset of the traits of a specific
type
Type may refer to:
Science and technology Computing
* Typing, producing text via a keyboard, typewriter, etc.
* Data type, collection of values used for computations.
* File type
* TYPE (DOS command), a command to display contents of a file.
* Ty ...
. A
superclass has wider use than a specific
subclass, and so is more 'general'.
An example of generalizing a type would be moving a
method
Method ( grc, μέθοδος, methodos) literally means a pursuit of knowledge, investigation, mode of prosecuting such inquiry, or system. In recent centuries it more often means a prescribed process for completing a task. It may refer to:
*Scien ...
from a child to a parent
class
Class or The Class may refer to:
Common uses not otherwise categorized
* Class (biology), a taxonomic rank
* Class (knowledge representation), a collection of individuals or objects
* Class (philosophy), an analytical concept used differently ...
for common use by all the parent class' children, not just the original child.
Another example, in the
Java programming language
Java is a high-level, class-based, object-oriented programming language that is designed to have as few implementation dependencies as possible. It is a general-purpose programming language intended to let programmers ''write once, run an ...
, would be access to an
object
Object may refer to:
General meanings
* Object (philosophy), a thing, being, or concept
** Object (abstract), an object which does not exist at any particular time or place
** Physical object, an identifiable collection of matter
* Goal, an ai ...
via an
interface
Interface or interfacing may refer to:
Academic journals
* ''Interface'' (journal), by the Electrochemical Society
* '' Interface, Journal of Applied Linguistics'', now merged with ''ITL International Journal of Applied Linguistics''
* '' Int ...
which isn't tied into a specific implementation of that interface.
References
Code refactoring
{{Software-eng-stub