Jump to content

Instance (computer science)

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by 89.235.214.24 (talk) at 04:02, 14 April 2013 (grammar). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

object-oriented programming is based on an idea that there are "blueprints" and "things that are manufactured according to the blueprints". The "blueprint" is called a class and the "thing manufactured according to the bluepring" is called an instance.


In computer science the term class has a synonym: type.


The meaning of the term type in computer science is similar to the meaning of the word "type" in every-day language. For example, a barman can ask a client, what type of beverage does he/she want? Coffee, tee, beer? A particular cup of coffee that the client receives is in the role of an instance. Two cups of coffee would form a set of two instances of (the type) coffee.


In computer science the term instance has also a synonym: object.


Just like in every-day life, in computer science the types (classes) can be combined and derived from eachother. For example, the Cappuccino is assembled from milk and coffee.


Sometimes types can be seen as if they formed hierarchies. For example, the Cappuccino and Latte can be viewed as if they were derived from the type "coffee". In computer siceinse lingua: "Coffee is a generalization of the "Cappuccino" and "Latte". A classical Turing tarpit of novice programmers is that in real life a single type can be derived from multiple types. For example, "Cappuccino" is derived from "milk" by adding coffee as an ingredient. This entails that in stead of forming "upside-down trees" the type hierarchies form a more complex, [ordered-graph like] structure.


One of the central ideas of the object-oriented programming is that in stead of describing new types from scrach, programmers can describe ("create", "define") new types by describing the difference between the new type and some existing, already described, type. For example, to describe the content of the Cappuccino, the programmer only needs to write that the Cappuccino consists of coffee and milk and there is no need for writing that the coffee consists of water and roasted coffee beans and that the milk consists of proteins and water.


Types ("classes" in Computer Science lingua) consist of two types of ingredients: data-fields (usually called as "attributes" or "fields", but sometimes also called as "records") and code blocks (usually called as "methods", but sometimes called as "procedures" or "functions"). For example, the type "coffee" might contain a data-field that describes the amount of coffe left in a particular "coffee" (cup) instance. Historically the code blocks were ment to be used for manipulating mostly the data-fields of the instance that contained the code blocks in its type description (class), but in practice the code blocks are used in any way the programmers see fit. The programming techniques, design ideas, are called design patterns.