| dbpprop:abstract
|
- In programming language theory, subtyping or subtype polymorphism is a form of type polymorphism in which a subtype is a datatype that is related to another datatype (the supertype) by some notion of substitutability, meaning that program constructs, typically subroutines or functions, written to operate on elements of the supertype can also operate on elements of the subtype. If S is a subtype of T, the subtyping relation is often written S <: T, to mean that any term of type S can be safely used in a context where a term of type T is expected. The precise semantics of subtyping crucially depends on the particulars of what "safely used in a context where" means in a given programming language. The type system of a programming language essentially defines its own subtyping relation, which may well be trivial. Because the subtyping relation allows a term to have (belong to) more than one type, subtyping is a form of type polymorphism, so it is (properly) called subtype polymorphism. In object-oriented programming subtyping is commonly called just polymorphism. Subtyping is practically never called this way in type theory or in functional programming, where the unqualified use of "polymorphism" usually refers to parametric polymorphism, as in polymorphic lambda calculus. (Mechanisms similar in purpose, but not identical with parametric polymorphism are known by other names in object-oriented programming, e.g. generics in Java or templates in C++. ) Functional programming languages often allow the subtyping of records. Consequently, simply typed lambda calculus extended with record types is perhaps the simplest theoretical setting in which a useful notion of subtyping may be defined and studied. Because the resulting calculus allows terms to have more than one type, it is no longer a "simple" type theory. Since functional programming languages, by definition, support function literals, which can also be stored in records, records types with subtyping provide some of the features of object-oriented programming. (Unless references are added to the language, record "objects" are immutable). Typically, functional programming languages also provide some, usually restricted, form of parametric polymorphism. In a theoretical setting, it is desirable to study the interaction of the two features; a common theoretical setting is system F<:. Various calculi that attempt to capture the theoretical properties of object-oriented programming may be derived from system F<:. The concept of subtyping is related to the linguistic notions of hypernymy and holonymy. It is also related to the concept of bounded quantification in mathematical logic. Subtyping should not be confused with the notion of (class or object) inheritance from object-oriented languages; subtyping is a relation between types (interfaces in object-oriented parlance) whereas inheritance is a relation between implementations stemming from a language feature that allows new objects to be created from existing ones. In a number of object-oriented languages, subtyping is called interface inheritance.
- In informatica, e in particolare in programmazione, si definisce sottotipo un tipo di dato legato ad un altro tipo di dato, detto super-tipo, da una relazione di sostituibilità, intesa nel senso che un programma scritto per utilizzare elementi costruiti sul modello del supertipo, può funzionare anche con elementi costruiti sul modello del sottotipo. Più esattamente, spesso si assume che la relazione supertipo-sottotipo sia quella definita dal principio di sostituzione di Liskov; tuttavia ogni linguaggio di programmazione può definire un proprio diverso criterio, o anche non definirlo affatto. Ad esempio, nella maggior parte dei linguaggi orientati agli oggetti, le sottoclassi generano automaticamente sottotipi: se A è una sottoclasse di B, allora un'istanza della classe A può essere usata in qualsiasi contesto in cui il programma si aspetta di trovare un'istanza della classe B; quindi si può affermare che A è un sottotipo di B. Ne consegue che ogni variabile o parametro dichiarato di tipo B può, a run-time, contenere un valore di tipo A. Dal punto di vista della programmazione ad oggetti si dice in tal caso che tale variabile è polimorfica e si distinguono il suo tipo statico (ovvero il tipo indicato nella sua dichiarazione) e il suo tipo dinamico (il tipo effettivo del valore che le viene assegnato, in generale diverso da B, e in questo caso A). Un altro esempio: un certo linguaggio potrebbe ammettere l'uso di valori interi al posto di valori floating point, oppure potrebbe definire un tipo numero in grado di contenere entrambi. Nel primo caso il tipo intero sarebbe un sottotipo di floating point; nel secondo questi due tipi non avrebbero alcuna mutua relazione, ma entrambi sarebbero sottotipi di numero. I programmatori traggono vantaggio dall'uso dei sottotipi, in quanto possono scrivere codice in modo più astratto. Ad esempio: function max (x as numero, y as numero) is if x < y then return y else return x end se intero e floating point sono entrambi sottotipi di numero, allora valori di entrambi questi tipi possono essere indifferentemente passati come parametri a questa funzione. Sotto questo aspetto l'uso dei sottotipi può essere considerato come una particolare forma di polimorfismo. La notazione solitamente usata in teoria dei tipi per indicare la relazione fra tipo e sottotipo è <: sicché A<:B significa che A è un sottotipo di B. Dal punto di vista teorico esiste una fondamentale differenza fra la sottotipizzazione nominale, in cui soltanto i tipi dichiarati secondo determinate regole possono essere uno il sottotipo dell'altro, e la sottotipizzazione strutturale, in cui la struttura stessa di due tipi implica che uno sia il sottotipo dell'altro. La sottotipizzazione sopradescritta si basa sulla nozione di classe, ed è di tipo nominale. Un modo di definire la sottotipizzazione strutturale nel contesto di un linguaggio orientato agli oggetti potrebbe essere affermare che se un oggetto di tipo A è in grado di rispondere a tutti i messaggi a cui è in grado di rispondere un oggetto di tipo B (o, detto in altro modo equivalente, i due oggetti possiedono gli stessi metodi), allora A è un sottotipo di B, indipendentemente dal fatto che i due oggetti siano legati da una relazione di ereditarietà reciproca. L'implementazione di linguaggi di programmazione con sottotipi cade in due classi: implementazioni inclusive. dove ogni valore di tipo A è anche rappresentazione dello stesso valore di tipo B se A<:B, e implementazioni coercitive, dove ogni valore di tipo A può essere automaticamente convertito in uno di tipo B. La sottotipizzazione indotta da una classe (subclassing) in un linguaggio orientato agli oggetti è, solitamente, inclusiva. relazioni di sottitipo tra interi e floating point, che sono rappresentati in modi differenti, sono solitamente coercitive. In quasi tutti i sistemi che definiscono una relazione di sottotipo, questa è riflessiva e transitiva . Viene definito in questo modo un preordinamento sui tipi.
- コンピュータサイエンスにおいて、データ型S が他のデータ型T とis-a関係にあるとき、S をT の派生型(はせいがた、subtype)であるという。またT はS の基本型(きほんがた、supertype)であるという。基本型のデータを処理するように作られたプログラムは、その派生型のデータでも正しく処理することができる。つまり、基本型-派生型関係ではリスコフの置換原則(Liskov Substitution Principle)が成り立つ。とは言っても、実際のプログラミング言語では独自の型の派生(subtyping)の概念を採用していることもあり、またそのような概念を持たないこともある。
- Podtyp to konstrukcja programistyczna umożliwiająca w określonym języku programowania definiowanie ograniczeń na pewnym typie bazowym. Pojęcie podtypu zdefiniowane zostało wprost w języku Ada, w którym istnieje jednoznaczne odróżnienie deklaracji typu i podtypu, identyfikowane odpowiednim słowem kluczowym: subtype – dla podtypów w odróżnieniu od type – dla typów, w tym także typów pochodnych. Podtyp jest więc nałożeniem pewnego ograniczenia na pewien typ (w nomenklaturze języka Ada nazywany typem bazowym). W przypadku podtypów ograniczenia te dotyczą wyłącznie zakresu możliwych wartości należących do podtypu, stanowiących pewien podzbiór wyodrębniony ze zbioru możliwych wartości typu bazowego. Jest to więc różna konstrukcja w porównaniu z typem pochodnym, definiującym jednak nowy typ, mimo że również oparty na pewnym typie macierzystym. Przykład w Adzie: subtype miesiąc is INTEGER range 1..12; Na tak zdefiniowanym podtypie można wykonywać wszystkie te same operacje, które są dopuszczalne dla typu INTEGER, a ograniczony jest jedynie zakres wartości. Istnieją języki, w których występują konstrukcje analogiczne do podtypu, mimo że język nie definiuje wprost takiego pojęcia. Przykładem jest język Pascal, w którym występuje typ okrojony. Jego cechy są jednak takie, iż jest to podtyp pewnego typu bazowego. Typ bazowy w Pascalu musi być typem porządkowym. type miesiąc=1..12; Nie definiuje się tu wprost typu bazowego, wynika on z typu literałów użytych do ograniczenia zakresu wartości. Na wartościach takiego typu oczywiście tak jak w podtypie dopuszczalne są wszystkie operacje typu bazowego. Nowy typ (podtyp) jest zgodny w sensie przypisania z typem bazowym. W języku Modula 2 typ bazowy, w definicji podtypu, może być wyspecyfikowany jawnie lub pominięty: TYPE miesiąc=1..12 TYPE miesiąc:INTEGER=1..12
- 在计算机科学中,子类型(subtype)一般是同另一个数据类型(超类型,supertype)有关系的数据类型,通过了某种可代换性概念,这意味着为在这个超类型的元素上运算而写计算机程序也可以在子类型的元素上运算。更明确的说,超类型-子类型关系经常通过Liskov代换原则来定义;但是任何给定编程语言都可以定义它自己的子类型概念,或根本没有这个概念。
|
| rdfs:comment
|
- In programming language theory, subtyping or subtype polymorphism is a form of type polymorphism in which a subtype is a datatype that is related to another datatype (the supertype) by some notion of substitutability, meaning that program constructs, typically subroutines or functions, written to operate on elements of the supertype can also operate on elements of the subtype.
- In informatica, e in particolare in programmazione, si definisce sottotipo un tipo di dato legato ad un altro tipo di dato, detto super-tipo, da una relazione di sostituibilità, intesa nel senso che un programma scritto per utilizzare elementi costruiti sul modello del supertipo, può funzionare anche con elementi costruiti sul modello del sottotipo.
- Podtyp to konstrukcja programistyczna umożliwiająca w określonym języku programowania definiowanie ograniczeń na pewnym typie bazowym. Pojęcie podtypu zdefiniowane zostało wprost w języku Ada, w którym istnieje jednoznaczne odróżnienie deklaracji typu i podtypu, identyfikowane odpowiednim słowem kluczowym: subtype – dla podtypów w odróżnieniu od type – dla typów, w tym także typów pochodnych.
- 在计算机科学中,子类型(subtype)一般是同另一个数据类型(超类型,supertype)有关系的数据类型,通过了某种可代换性概念,这意味着为在这个超类型的元素上运算而写计算机程序也可以在子类型的元素上运算。更明确的说,超类型-子类型关系经常通过Liskov代换原则来定义;但是任何给定编程语言都可以定义它自己的子类型概念,或根本没有这个概念。
|